Most digital timers require a set of dip switches or rotary BCD encoders to preset their interval. But those techniques consume eight or more inputs from a microcontroller's (MCU's) I/O lines. To alleviate the problem, this circuit forms a digital timer that only requires one input pin of the PIC16F872 MCU to adjust its interval (see the figure). The MCU performs all of the functions, a-d converting, timing, and decoding to drive the displays.
The timing interval range for this circuit is from 1 to 199 seconds with a resolution of 1 second. It can be adjusted with potentiometer R1, which generates an analog voltage to the PIC's AN0 input. This voltage is read by the analog-to-digital converter (ADC), which in turn generates the respective binary reading. Using lookup tables in the software routine, such binary readings are converted to BCD code and translated to a seven-segment code. This is the code required to drive the 2.5-digit LED digital display. The digital reading displayed now represents the timing interval in seconds.
Once the trigger is actuated by a negative-edge pulse generated by the pushbutton connected to RA1, output RA3 goes to a logic one, and the digital reading starts decrementing each second. When the digital reading reaches zero seconds, RA3 goes low and the display presents the original preset number. This way, the timer can be triggered again with the same interval if desired.
A trigger pulse on RA1 typically has a 50-ms duration, and the MCU reads this input every 73 µs, which is sufficient to catch such a pulse. Also, that means the MCU updates the display every 73 µs. Debouncing the pushbutton is performed through software because only the first high-to-low transition is read to start the timing routine.
A new timing interval can be obtained by adjusting R1 before pulsing the trigger input. Once the cycle starts, the interval can't be changed. The MCU is constantly reading the AN0 voltage. When this voltage is changed by the user, the reading is increased or decreased.
The software routine for the PIC16F872 MCU, PIC16F872 Routine.asm.doc, can be found in the online version of this article. By changing the constants in the subroutine "DELAY," the MCU can be adjusted to supply pulses from 1 to 199 milliseconds, minutes, or even hours.
When the input voltage is changed, it's first compared against the ADC reference voltages VREF+ and VREF2 , which are connected to VDD and VSS, respectively. Register ADCON0 configures these reference voltages. Once the a-d conversion is processed in 20 µs, the result is stored in register ADRESH. Then the BCD to Binary conversion routine "BCDBIN" is executed, and finally, this result is converted to a seven-segment format to drive the displays. The table shows nine typical cases. If the user tries to set a timing interval that's out of range, the display will present the message "Err" to indicate an error.
The output LED connected to RA3 can be substituted by an optocoupler or a transistor to drive a relay. For battery-powered circuits, the output pulse from RA3 can be replaced by a 1-kHz frequency with a duty cycle of 50% to drive a coil's relay and save energy. Also, the C.C. LED displays can be substituted by an alphanumeric LCD readout, but an additional subroutine is required to handle such a device. Finally, for industrial applications, it's recommended to use a 4.00-MHz crystal with an extended temperature range.
The timing interval on this MCU-based programmable timer is set by adjusting the analog voltage at the AN0 pin.
respected sir, I need the two digit countdown timer with eprom backup i will request you to give the schematic source code and circuit diagram. thanking you!
Anonymous -June 19, 2007
how to become timer interval input from analog voltage into digital numbers counting,use the same one pin?thank you in advance steve
Anonymous -May 07, 2007
i don`t understood anything, but sounds great vicky!!
Alberto B. -December 21, 2005 (Article Rating: )
why don't you multiplex the leds ? you would save 6 outputs
jacques -June 21, 2005
It's a good design. Simple and useful. Congratulations Vicky.
Anonymous -March 21, 2005 (Article Rating: )
I think that this is a good article that can be used for many students. Congratulations and keep it going.
Jazeck -March 10, 2005 (Article Rating: )
Congratulations Mario!
Highbran -March 09, 2005
I think it's a very good design ´cause it has many applications and it is a simple but very useful design. Congratulations guys!!!!
Armando Felix -March 09, 2005
Good for you guys.
Anonymous -February 13, 2005 (Article Rating: )
It is a good design.
Anonymous -February 07, 2005 (Article Rating: )
I believe that it is a good and very interesting design with simple applications.
Anonymous -February 07, 2005 (Article Rating: )
Your Comments:
Enter the text from the image below
Please refresh the page if you have trouble reading this text.
Search Electronic Design
Web Seminar
Sponsored By:
Title: Read Pacing: A Performance Enhancing Feature of PCI Express Gen 2 Switch Devices