Electronic Design

  
Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


[Ideas For Design]
Just One Microcontroller Pin Sets Programmable Timer's Interval

Ricardo Jimenez, Mario Maciel, Virgilia Moreno  |   ED Online ID #9582  |   February 3, 2005


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 VREF 2 , 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.


Reprints   Printer-Friendly  Email this Article  RSS    Font Size   What's This?


  • In EDA, A Year Of Mergers, Failed And Otherwise
  • 2008 BEST Electronic Design Winners
  • Engineers Rely On Internet For Product Info
  • Rochester Electronics Establishes New Design and Technology Group
  • November 17, 2008
  • Custom Sources Light Way To 22-nm IC Lithography
  • Software Turns Scopes Into Vector RF Signal Analyzers
  • Couple’s $15 Million Gift Advances Rice Engineering Education
    1) Behind The Bright Lights, LED Drivers Evolve To Meet New Requirements
    (1174 views today)
    2) Ten Top Design Skills For Tough Times
    (294 views today)
    3) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (285 views today)
    4) Wi-Fi Chips Stand Out In A Sea Of Wireless Products
    (207 views today)
    5) Easily Convert Decimal Numbers To Their Binary And BCD Formats
    (200 views today)
    ALL TOP 20



    Reader Comments

    Rating Only

    Rating Only -June 19, 2007   (Article Rating: )

    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: )

    POST YOUR COMMENTS HERE
    Name:

    Email:
    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
    Speakers: 
    Date: 07/01/08
    Register: 

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF
    Mobile Dev & Design Schematics Find Power Products Military Electronics EE Events Related Resources