EDN Access -- 05.11.95 single IC adds analog inputs to digital PL

-May 11, 1995

EDN logo
Design Ideas:May 11, 1995

Single IC adds analog inputs to digital PLC


Many low-cost programmable logic controllers (PLCs) are digital only and have relay outputs, debounced digital inputs, and one or more counter inputs. The circuit in Fig 1 adds four 8-bit analog inputs to even the most basic PLC. The design requires a PLC with just two digital outputs and one high-speed (>5 kHz) counter input. The circuit is based on Microchip Technology's (Chandler, AZ) PIC 16C71 RISC µC. This µC has a four-channel, 8-bit ADC and an 8-bit digital I/O port. The digital I/O port has built-in pullup resistors, so direct interface to relays is possible.

The PIC operates by sensing a low-to-high change on the RB0 input. This change causes a wake-up interrupt in the PIC. After some suitable debounce interval (50 msec), the PIC selects A/D channel 0, 1, 2, or 3, depending on the address at RB0 and RB1. The PIC sets the channel, waits for the input multiplexer to settle, and reads the ADC's result. The PIC has converted the analog input to a 0-to-255 digital byte.

The PLC's counter input now helps transfer this digital value into the PLC. The PIC shifts out the digital code as a string of pulses at 5 kHz. The pulse train is 0 to 255 counts long, depending on the value of the sampled A/D channel. The following equation translates the digital count to a voltage:



At a 5-kHz transfer rate, it may take up to 51 msec to completely transfer all 255 counts to the PLC's counter. After a complete transfer, the PIC waits for a low-to-high transition on the RB0 input pin to restart the process. Fig 2 is a flow diagram of the PLC's program.

If a convenient 5V source isn't available for powering the PIC µC, you can drive the circuit using the optional power supply in the Fig 2. A 9V alkaline battery can continuously power the circuit for over 250 hours. Longer life is possible if you use a PLC-relay output to switch the power on and off. For long term, unattended operation, you can substitute a 9V wall-cube transformer from Radio Shack for the 9V battery.

The PIC was programmed in C, using a low-cost C compiler. Even using a high-level language such as C, this interface program consumes only about one-quarter of the PIC's 1-kbyte available program space. The ZIPfile attached to EDN BBS /DI_SIG #1701 contains the HEX object file to program your own PIC, along with the C source code. (DI #1701)

| EDN Access | feedback | subscribe to EDN! |
| design features | design ideas | columnist |

Copyright c 1995 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.

Loading comments...

Write a Comment

To comment please Log In