Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Efficient way to make a timer circuit

Status
Not open for further replies.

poxkix

Member level 5
Member level 5
Joined
Aug 20, 2011
Messages
87
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,948
I constructed 4 timer circuits which will countdown from 60 minutes to 0.
They are controlled individually by a single PIC18F4620. The timers will time/function at different times depending which timer would I want to start to countdown. The timers default time is 0.

I was thinking, is their another way to make the 4 timers to just 1? Still with the same functionality.

code:
Code:
unsigned short cnt = 0;
unsigned short minute = 0;
unsigned short second = 0;
unsigned short count = 0;

unsigned short cnt_pressed = 0;
unsigned short holder = 10;
unsigned short temp = 0;

void increment();
void decrement();
void interrupt () {
     if (INTCON.INTF == 1) {
        INTCON.INTF = 0;
        increment();
        INTCON.T0IE = 1;
        temp = 1;
     }
     if (INTCON.T0IF == 1) {
        TMR0 = 0;
        INTCON.T0IF = 0;
        cnt++;
        portb.f3 = 1;
        temp = 1;
        if (cnt == 0x0F) {      //  15 time trigger for 1 second
           second++;
           cnt = 0;
           temp = 0;
           if (second == 0x3C) {    // seconds
             decrement();
             second = 0;
             if (minute == 0x00) {  // minutes
                INTCON.T0IE = 0;

                if(second == 0 && minute == 0) {
                portb.f3 = 0;
                }
             }
           }
        }
     }
}

void initMain() {
     TRISA = 0x00;
     TRISB = 0x03;
     porta = 0;
     portb = 0;
}

void initInterrupt() {
     TMR0 = 0;
     INTCON.GIE = 1;
     INTCON.T0IF = 0;
     INTCON.INTE = 1;
     //INTCON.RBIE = 0;
     INTCON.T0IE = 0;
     //1 = Interrupt on rising edge of RB0/INT pin
     //0 = Interrupt on falling edge of RB0/INT pin
     OPTION_REG = 0x47; // option_reg 111 = 1 : 256
}

void subMain() {
     while (1) {
           if (temp == 0) {
           portb.f2 = 0;
           } else {
           portb.f2 = 1;
           }
     }
}

void main () {
     initMain();
     initInterrupt();
     subMain();
     
     while(1) {
     }
}

void increment() {
     short x = 1;
       for (;x <= 60; x ++) {
           cnt_pressed = cnt_pressed  + 1;
           if (cnt_pressed == holder) {
           minute+= 6;
           cnt_pressed = 0;
           porta = minute;
           portb = minute;
           }
           portb.f2 = 1;
       }
       minute = minute + 60;
       porta = minute;
       portb = minute;
       portb.f2 = 1;
}
void decrement() {
     switch (minute) {
            case 0x00: minute = 0xA0;
            case 0x10:
            case 0x20:
            case 0x30:
            case 0x40:
            case 0x50:
            case 0x60:
            case 0x70:
            case 0x80:
            case 0x90: minute = minute - 7;
                       cnt_pressed = 9;
                       porta = minute;
                       portb = minute;
                       portb.f2 = 1; break;
            default: minute = minute - 1;
                     cnt_pressed -= 1;
                     porta = minute;
                     portb = minute;
                     portb.f3 = 1;
                     portb.f2 = 1; break;
     }
}

Untitled.pngasd.png
 

Hi,
if u mean using one micro instead of 4 , I've got to say it is a better choice to use timers in the microcontrollers.
For example imagine that : atmega16 has three timers . so u can use three counters at the same time.
 
use one max7219 to control your 8 displays
or connect the 8 displays directly to the pic using multiplexing
example here : http://extremeelectronics.co.in/microchip-pic-tutorials/using-multiplexed-7-segment-displays-%E2%80%93-pic-microcontroller-tutorial/

Saw the image, the problem is the segments are 4 pair of 7 segments are separated. They are not placed side by side the same with the link you gave me.

Hi,
if u mean using one micro instead of 4 , I've got to say it is a better choice to use timers in the microcontrollers.
For example imagine that : atmega16 has three timers . so u can use three counters at the same time.

Yes, 1 micro instead of 4. The problem is, the most easy to get microcontroller available in my area is just the PIC16F877A.


Another thing, the PIC18F4620 is also controlling the reset of those 4 timers individually. The timers has a PIC16F84A and 2 7448. The controlling of the timer from the PIC18F4620 is done by interrupt at the RB0/INT of the PIC16F84A.
 

You could use the 16F877A for maintaining the time and controlling all 8 7-segment displays. Multiplex the displays and you'll require 16 pins to control the 7-segments displays including the decimal point.

If you use the 16F877A, you can control the reset of the timers in the 16F877A.

However, 16F877A doesn't have 4 timers. If you can code to utilize the 3 timers and make 4 required timings from them, then you can use 16F877A.

Hope this helps.
Tahmid.
 

You could use the 16F877A for maintaining the time and controlling all 8 7-segment displays. Multiplex the displays and you'll require 16 pins to control the 7-segments displays including the decimal point.
If you use the 16F877A, you can control the reset of the timers in the 16F877A.
However, 16F877A doesn't have 4 timers. If you can code to utilize the 3 timers and make 4 required timings from them, then you can use 16F877A.
Hope this helps.
Tahmid.

Yes, that is my main problem. It has only three. And another, 16F877A has only 1 RB0/INT. how would that be done? The 4 timers should work at any given time. I tried it once using one 16F877A but I can't/don't know how it should be done
 

you can use only one timer to generate a second delay (or whaever minimum delay you need to watch)
and then make 4 counters that are based on that delay, even if they dont count the same way
one counter can count from one to one, the other one count each 4 delay, so on...
and you get almost any timer you want based only on one timer, the one with the minimum delay of all your counters
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top