NEX Robotics
5.3.3 Timer 5 configuration in 8 bit fast PWM mode
Function Timer5_init() function initializes the function in 8 bit fast PWM generation mode.
// Timer 5 initialized in PWM mode for velocity control
// Prescale: 256
// PWM 8bit fast, TOP=0x00FF
// Timer Frequency:225.000Hz
void
timer5_init()
{
TCCR5B = 0x00;
TCNT5H = 0xFF;
TCNT5L = 0x01;
OCR5AH = 0x00;
OCR5AL = 0xFF;
OCR5BH = 0x00;
OCR5BL = 0xFF;
OCR5CH = 0x00;
OCR5CL = 0xFF;
TCCR5A = 0xA9;
//For Overriding normal port functionality to OCRnA outputs. WGM51=0, WGM50=1 Along With GM52 //in
TCCR5B for Selecting FAST PWM 8-bit Mode
TCCR5B = 0x0B;
}
PWM frequency calculation:
PWM frequency = System Clock / N (1 + TOP)
= 14.7456 MHz / 256 (1 + 255)
= 225.000 Hz
Where
System clock = Crystal frequency = 14.7456MHz
Prescale = N = 256
TOP = 255 (8 bit resolution)
System Clock / Prescale
System Clock
System Clock / 8
System Clock / 64
System Clock / 256
System Clock / 1024
Table 5.2: 8 bit PWM fast frequency for different prescale options
5.3.4 Function for timer 5 initialization
void
init_devices (void)
{
cli();
//disable all interrupts
timer5_init();
sei();
//re-enable interrupts
}
cli(); disables all the interrupts and sei(); enables all the interrupts.
www.nex-robotics.com
//Stop
//Counter higher 8-bit value to which OCR5xH value is compared with
//Counter lower 8-bit value to which OCR5xH value is compared with
//Output compare register high value for Left Motor
//Output compare register low value for Left Motor
//Output compare register high value for Right Motor
//Output compare register low value for Right Motor
//Output compare register high value for Motor C1
//Output compare register low value for Motor C1
//COM5A1=1, COM5A0=0; COM5B1=1, COM5B0=0; COM5C1=1
// COM5C0=0
//WGM12=1; CS12=0, CS11=1, CS10=1 (Prescaler=64)
F
F
F
F
F
//use this function to initialize all devices
8-bit (TOP = 255)
= 57.600 KHz
pwm
= 7.200 KHz
pwm
= 900.000Hz
pwm
= 225.000 Hz
pwm
= 56.250 Hz
pwm
Fire Bird V Software Manual
83
Need help?
Do you have a question about the Fire Bird V ATMEGA2560 and is the answer not in the manual?