The good old PIC16F84A does not have an analogue to digital converter (ADC) on board. A good solution to this problem is offered by the TLC549 serial ADC made by Texas Instruments. The TLC549 uses only 3 of the I/O pins of the controller, is very compact and is also readily available.
The TLC549 control lines CS and l/O-Clock are controlled from the PIC. The result of the conversion is available via the serial output of the ADC (Data Out), one bit at a time, and is stored into a byte of RAM in
the PIC. You can find a detailed description of how this works in the Texas Instruments data sheet: http://focus.ti.com/lit/ds/symlink/tlc549.pdf. The program shows how the 8 bits in the RESULT byte are fetched in (lines 10 to 25).
For the sake of clarity it was decided to show each and every step in full. The clock signal for the ADC is generated by the subroutine IOCLOCK (lines 34 to 38). The chip select input of the ADC is controlled by program lines 09 and 26. The operating sequence diagram (datasheet page 3) clearly shows how the CS has to be
controlled. The TLC549 will not operate correctly when the CS is permanently connected to ground.
The routine SHIFTIN takes care of assembling the RESULT byte. RAO (Data Out) is first copied to the carry bit (31). The carry is subsequently left shifted into the RESULT byte (32). Since the order of the data bits from the conversion result is MSB first and LSB last (see datasheet), this ensures that the conversion result ends up the correct way around in the RESULT byte, after going through a complete cycle.
In the schematic you can see that PORTB is used to visualise the result of the conversion using LEDs. If you have another use for PORTB then you may omit program lines 27 and 28. An analogue signal for the input of the ADC is simulated with potentiometer P1. The value is not critical; use a higher value to avoid unnecessary loading of the power supply.
When flash programming the PIC client, the reset circuit (R1, C3 and
RST) needs to be disconnected from pin 4 (MCLR).


Похожие статьи
Нет отзывов к этой записи