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.

Timers limitation counts

Status
Not open for further replies.

ateeq12

Newbie level 3
Joined
Feb 11, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,299
hey! i m beginer and feeling that the timers in pic mcus are not sufficient for my project ,
i m requride 35 timers ! how to fix problem?
why r the timers r limited in mcus ?:sad:
 

why do need 35 timers? what are you going to do with those?
 
Depending on the purpose of the 35 timers you might be able to use just one hardware time in the MCU and extend it to 35 software timers.
 
Depending on the purpose of the 35 timers you might be able to use just one hardware time in the MCU and extend it to 35 software timers.

software timers? plz enplain more8-O
 

1. generate a timer tick in hardware using a polling or preferably an interrupt routine.
2. call a routine with the tick, an ISR will do this for you.
3. count 35 variables up or down in software, these are the timers you need.

Easy, and if you are writing in assembly language you can increment or decrement a timer variable in just one instruction.

Brian.
 
you can do something like this,

int variable_1_flag = 0;
int variable_2_flag = 0;

timer_interrupt() // interrupt to occur for every 1ms
{
if (TMR0IF)
TMR0IF = 0;
// timer values
increment a variable
if(variable==1000) // for 1 sec
{
variable_1_flag = 1;
}
if(variable==2000) // for 2 sec
{
variable_2_flag = 1;
}
// do as many like this

}

main()
{
if(variable_1_flag==1)
{
// do something
variable_2_flag = 0; // to reset the flag
}

if(variable_2_flag==1)
{
// do something
variable_2_flag = 0;
}
}
 
Or another method is like this:

timer_interruot()
{
TMR0IF = 0; // use other timer if more appropriate
TMR0 = 0xNN; // reload the timer again if needed
if(myTimer1 != 0) myTimer1--; // count the timer down to zero then stop
if(myTimer2 != 0) myTimer2--;
.
.
if(myTimer35 != 0) myTimer35--;
}

Now each time the interrupt occurs, all the counter values reduce by 1 until they reach zero. So if your interrupt was say 100mS, and you loaded the values 10, 20, 30 and 70 into your timer variables, they would reach zero in 1 second, 2 seconds, 3 seconds and 7 seconds. You can reload the timers anywhere in your program with new values at any time and you can test to see if they are still running (not timed out) by using "if(myTimerN)". All the timers run independently of each other.

Brian.
 
:p Thanks Bro -it helped me alot;
*** bless u with more and more knowledge!!!!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top