NEX Robotics
5.4.1 Timer 1 configuration in 10 bit fast PWM mode
Function Timer1_init() function initializes the function in 10 bit fast PWM generation mode.
//TIMER1 initialization in 10 bit fast PWM mode
//prescale:256
// WGM: 7) PWM 10bit fast, TOP=0x03FF
// actual value: 52.25Hz
void
timer1_init(void)
{
TCCR1B = 0x00;
TCNT1H = 0xFC;
TCNT1L = 0x01;
OCR1AH = 0x03;
OCR1AL = 0xFF;
OCR1BH = 0x03;
OCR1BL = 0xFF;
OCR1CH = 0x03;
OCR1CL = 0xFF;
ICR1H = 0x03;
ICR1L = 0xFF;
TCCR1A = 0xAB;
//COM1A1=1, COM1A0=0; COM1B1=1, COM1B0=0; COM1C1=1 COM1C0=0
//For Overriding normal port functionality to OCRnA outputs. WGM11=1, WGM10=1. Along With //WGM12 in
TCCR1B for Selecting FAST PWM Mode TCCR1C = 0x00;
TCCR1B = 0x0C;
//WGM12=1; CS12=1, CS11=0, CS10=0 (Prescaler=256)
}
5.4.2 Timer 1 initialization
//Function to initialize all the peripherals
void
init_devices(void)
{
cli();
//disable all interrupts
port_init();
timer1_init();
sei();
//re-enable interrupts
}
5.4.3 Functions to rotate servo motor by specified angle in the multiple of 1.86 degrees
//Function to rotate Servo 1 by a specified angle in the multiples of 1.86 degrees
void servo_1(unsigned char
{
float
PositionPanServo = 0;
PositionPanServo = ((float)degrees / 1.86) + 35.0;
OCR1AH = 0x00;
OCR1AL =
(unsigned
char) PositionPanServo;
}
//Function to rotate Servo 2 by a specified angle in the multiples of 1.86 degrees
void servo_2(unsigned char
{
float
PositionTiltServo = 0;
www.nex-robotics.com
//stop
//Counter high value to which OCR1xH value is to be compared with
//Counter low value to which OCR1xH value is to be compared with
//Output compare Register high value for servo 1
//Output Compare Register low Value For servo 1
//Output compare Register high value for servo 2
//Output Compare Register low Value For servo 2
//Output compare Register high value for servo 3
//Output Compare Register low Value For servo 3
degrees)
degrees)
Fire Bird V Software Manual
86
Need help?
Do you have a question about the Fire Bird V ATMEGA2560 and is the answer not in the manual?