Topics Topics Edit Profile Profile Help/Instructions Help Member List Member List  
Search Last 1|3|7 Days Search Search Tree View Tree View  

PIC timer advice

:: EPE Chat Zone ­:: ­Radio Bygones Message Board :: » EPE Forum Archives 2007-2009 » Archive through 18 June, 2007 » PIC timer advice « Previous Next »

  Thread Last Poster Posts Pages Last Post
  ClosedClosed: New threads not accepted on this page        

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

tuurbo46
Valued Member
Username: tuurbo46

Post Number: 13
Registered: 09-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 16 June, 2007 - 10:00 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Hi all,

Thanks for all the help with my previous relay wiring problems. The problem was found to be a wire had fallen off the ICD2 connection to the vero board. This was the reason i could not get any logic high on my I/O pins to feed the gate on the FET. Anyway, with your help my relay is running sweet!

Back to timers, am i correct in understanding timers can only be called via the ISR, or can they be called via a funtion call? I have included an example below.

***** ISR Version *********

timer0_isr(void)
{
LATB=0x01;

}

main()
{

for(;;)
continue;
}



***** Function call version *********




void turn_on_led(void)
{
LATB=0x01;

}

main()
{
while (1)
{
if(RA1)
{
turn_on_led();
}
}

}

Cheers Tuurbo6
Top of pagePrevious messageNext messageBottom of page Link to this message

tuurbo46
Valued Member
Username: tuurbo46

Post Number: 14
Registered: 09-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 16 June, 2007 - 11:27 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Opps, sorry that does not read correct. The below code is just a rought example and does not work. I will change a little so it makes more sense.

***** ISR Version *********

timer0_isr(void)
{

LATB ^=0x01; // toggle led
// clear TMR0 overflow flag

}

main()
{
while(1)
{
if(RA1)// interrupt fired
}
}



***** Function call version *********




void turn_on_led(void)
{
LATB ^=0x01; // toggle led
// clear TMR0 overflow flag
}

main()
{
while (1)
{
if(RA1) // a button is pressed (not interrupt)
{
turn_on_led();
}
}

}

Cheers Tuurbo6
Top of pagePrevious messageNext messageBottom of page Link to this message

epithumia
Frequent Contributor
Username: epithumia

Post Number: 434
Registered: 06-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 16 June, 2007 - 12:15 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

No, you don't need to use interrupts. Just leave the interrupt masked and do:

while(1)
{
.......if(TMR0 overflow flag){
..........turn_on_led();
..........clear TMR0 overflow flag
.......}
}
If you need me, Neil and me will be hanging out with the Dream King. - Tori Amos
Top of pagePrevious messageNext messageBottom of page Link to this message

tuurbo46
Valued Member
Username: tuurbo46

Post Number: 15
Registered: 09-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 16 June, 2007 - 12:28 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Hi

Thanks for your example. This has cleared up my dustier areas of timers.

Cheers.

Tuurbo46

Administration Administration Log Out Log Out   Previous Page Previous Page Next Page Next Page