Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/18/11 04:15
Modified:
  02/18/11 07:07

Read: times


 
#181170 - C8051F350 target board C program
Hi, I'm using C8051F350 target board from Silicon Laboratories. I am using timer2 and timer3 for timer process. The target board is connected to the HB-25 motor controller and a 12vdc motor. Can anyone help me?


When I put this code in my program, the motor is able to run and there is waveform generated on the oscilloscope. But unable to increase speed.
Toggle = ~Toggle;			
while(TF2L==0);      
TF2L=0; 

This is my revised code. Motor is not running and there is no PWM signal generated on the oscilloscope.
while (1)
{                    
        if (SW2 == 0) // if P1.0 is pressed
  	{
   	       TMR2RL--; // increase Timer2 interval
			
   	       if (TMR2RL <= TMR3RL) // if Timer2 interval longer than Timer3
   		      TMR2RL++; // do not increase Timer2 interval
  	}	
}

TMR2RL and TMR3RL values in the program code are different from the watch window.  
void Timer2_Init (void)
{
 	TMR2CN = 0x00; // Timer2 configured for 16-bit auto-reload 
 	CKCON |= 0x30; // Timer2 uses SYSCLK/12
 	TMR2RL = 0xffff; // Init reload value to 0 - Value shown in the watch window is 57249. It supposed to be 65535.
 	TMR2 = 0xffff; // set to reload immediately
 	ET2 = 1;  // Enable Timer2 interrupt
 	TR2 = 1;  // start Timer2
}
void Timer2_ISR (void) interrupt 5
{
	if (TF2H == 1)
 	{  		
  		TF2H = 0; // reset high byte overflow flag
  		TF2L = 0; // reset low byte overflow flag
  		TR2 = 0; // disable Timer2
   	}
 	else
 	{
  		TF2L = 0;          // reset low byte overflow flag
 	}
	
}
void Timer3_Init (void)
{
 	TMR3CN = 0x00; // Timer3 configured for 16-bit auto-reload 
 	CKCON |= 0xc0; // Timer3 uses SYSCLK/12
 	TMR3RL = 0xff00; // Init reload values for 1 ms interval - Value shown in watch window is 50397. It supposed to be 65280	
 	TMR3 = 0xffff; // set to reload immediately
 	EIP1 |= 0x80; // Timer3 interrupts set to high priority level
 	EIE1 |= 0x80; // Enable Timer3 interrupt
 	TMR3CN |= 0x04; // start Timer3
}
void Timer3_ISR (void) interrupt 14
{
 	if ((TMR3CN & 0x80) != 0)	// if TF3H=1
 	{   
  		TMR3CN &= 0x3f; // reset high and low byte overflow flag
  		TMR2RL = 0xffff; // set Timer2 to reload immediately
  		TMR3RL = 0xffff; // set Timer3 to reload immediately
  		TR2 = 1;  // enable Timer2
   	}  
 	else 
 	{
  		TMR3CN &= 0xbf; // reset low byte overflow flag
 	}
}

 



No replies in thread

Back to Subject List