View Single Post
  #1   Spotlight this post!  
Unread 09-03-2006, 22:30
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,673
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Timer0 stubbornly not working

Hey all,

I'm embarrassed to have to ask, but we're using Timer0 in our code to give us a 60Hz cycle on a PID loop. And the darned thing refuses to work. After an hour or troubleshooting and fiddling with code and looking at a frequency counter, we were stuck at about 38.somethingHz. I finally realized that this was a full count from 0 to 65535 at a prescale of 1:4. So our pre-load values aren't pre-loading properly. Here's a code snippet of the initializing and the interrupt handler:

Code:
//Initialize
  T0CON= 0b00000001;    ////1:4 Prescale
  TMR0H= 0X5D;   //Pre-load TMR0 to overflow at 60 Hz
  TMR0L= 0X3D;
  T0CONbits.TMR0ON= 1; //Turn timer on

  T1CON= 0b10000110;  //Set Timer 3 in async counter mode, 16-bit read
  TMR1H=0x00;
  TMR1L=0x00;
  T1CONbits.TMR1ON = 1;  //Turn Timer on


//Interrupt handler
    else if (INTCONbits.TMR0IF && INTCONbits.TMR0IE) // timer 1 interrupt?
    {

		INTCONbits.TMR0IF = 0; // clear the timer 0 interrupt flag
		TMR0H = 0X5D;   //Pre-load TMR0 to overflow at 60Hz
		TMR0L = 0X3D;
		Timer1L = TMR1L;
		Timer1H = TMR1H;
		TMR1H = 0x00;
		TMR1L = 0x00;
		fMainTimer = 1;
    }
We've got a similar problem with Timer1. We're using it as an asyncronous counter in 16-bit read/write mode. Unfortunately, the high byte just isn't getting read. Timer1H is always equal to zero, even when it shouldn't be. We've tried using it not in 16-bit read/write mode, and it works fine. But then we have to worry about getting incorrect readings if the low byte overflows as we're reading.

I'll note that the commonality here is the Timer0 exclusively uses 16-bit read/write mode, and Timer1 wasn't working in 16-bit read/write mode. So. Does anyone know if there's some extra step I need to take to get things to work in 16-bit read/write mode? Is it just broken? Is there PIC errata about this too? Will I ever stop ending my sentences in question marks?
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter