Use OCR3 instead of OCR1 for servo
This commit is contained in:
parent
235f368340
commit
41163406c2
1 changed files with 42 additions and 41 deletions
|
@ -62,47 +62,48 @@ unsigned int servob=SERVO_INIT;
|
||||||
void
|
void
|
||||||
servo_init(void)
|
servo_init(void)
|
||||||
{
|
{
|
||||||
// Port B initialization
|
// Port E initialization
|
||||||
// Func7=Out Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
|
// Set Pin 3 and 4 to output mode for OCR1A and OCR2A
|
||||||
// State7=0 State6=0 State5=0 State4=T State3=T State2=T State1=T State0=T
|
DDRE |= 1<<3 | 1<<4;
|
||||||
PORTB=0x00;
|
|
||||||
DDRB=0xE0;
|
// Timer/Counter 3 initialization
|
||||||
// Timer/Counter 1 initialization
|
|
||||||
// Clock source: System Clock
|
// Clock source: System Clock
|
||||||
// Clock value: 2000.000 kHz
|
// Clock value: 2000.000 kHz
|
||||||
// Mode: Ph. & fr. cor. PWM top=ICR1
|
// Mode: Ph. & fr. cor. PWM top=ICR1
|
||||||
// OC1A output: Connected
|
// OC3A output: Connected
|
||||||
// OC1B output: Connected
|
// OC3B output: Connected
|
||||||
// OC1C output: Connected
|
// OC3C output: Connected
|
||||||
// Noise Canceler: Off
|
// Noise Canceler: Off
|
||||||
// Input Capture on Falling Edge
|
// Input Capture on Falling Edge
|
||||||
// Timer1 Overflow Interrupt: Off
|
// Timer3 Overflow Interrupt: Off
|
||||||
// Input Capture Interrupt: Off
|
// Input Capture Interrupt: Off
|
||||||
// Compare A Match Interrupt: Off
|
// Compare A Match Interrupt: Off
|
||||||
// Compare B Match Interrupt: Off
|
// Compare B Match Interrupt: Off
|
||||||
// Compare C Match Interrupt: Off
|
// Compare C Match Interrupt: Off
|
||||||
TCCR1A=0xA8;
|
|
||||||
TCCR1B=0x12;
|
/* TCCR3A = [COM3A1|COM3A0|COM3B1|COM3B0||FOC3A|FOC3B|WGM31|WGM30] */
|
||||||
TCNT1H=0x00;
|
/* 1 0 1 0 1 0 0 0 */
|
||||||
TCNT1L=0x00;
|
TCCR3A=0xA8;
|
||||||
// ICR1 has a computed value of 20,000 - see the ESawdust.com/blog article for how this
|
/* TCCR3B = [ ICNC3| ICES3| -| WGM33||WGM32| CS32| CS31| CS30] */
|
||||||
|
/* 0 0 0 1 0 0 1 0 */
|
||||||
|
TCCR3B=0x12;
|
||||||
|
TCNT3H=0x00;
|
||||||
|
TCNT3L=0x00;
|
||||||
|
// ICR3 has a computed value of 20,000 - see the chip manual for how this
|
||||||
// value was derived.
|
// value was derived.
|
||||||
// 20000 == 0x4e20 so that's what goes into the high and low byte of the ICR1 register
|
// 20000 == 0x4e20 so that's what goes into the high and low byte of the ICR3 register
|
||||||
// alternatively, Codevision would let you just do ICR1 = 20000;
|
// alternatively, Codevision would let you just do ICR3 = 20000;
|
||||||
ICR1H=0x4E;
|
ICR3H=0x4E;
|
||||||
ICR1L=0x20;
|
ICR3L=0x20;
|
||||||
|
|
||||||
/* OCR1AH=0x00;
|
// OCR3A will govern the steering servo, OCR3B will govern throttle
|
||||||
OCR1AL=0x00;
|
OCR3A = 1500; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
||||||
*/
|
|
||||||
// OCR1A will govern the steering servo, OCR1B will govern throttle
|
|
||||||
OCR1A = 1500; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
|
||||||
|
|
||||||
// OCR1A will govern the steering servo, OCR1B will govern throttle
|
// OCR3A will govern the steering servo, OCR3B will govern throttle
|
||||||
OCR1B = 1500; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
OCR3B = 1500; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
||||||
// start with motor off - no duty cycle at all
|
// start with motor off - no duty cycle at all
|
||||||
OCR1CH=0x00;
|
OCR3CH=0x00;
|
||||||
OCR1CL=0x00;
|
OCR3CL=0x00;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
|
@ -139,13 +140,13 @@ servo_set(unsigned i,unsigned int j)
|
||||||
if(i==0)
|
if(i==0)
|
||||||
{
|
{
|
||||||
servoa=j;
|
servoa=j;
|
||||||
OCR1A = SERVO_OFFSET + servoa;
|
OCR3A = SERVO_OFFSET + servoa;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(i==1)
|
if(i==1)
|
||||||
{
|
{
|
||||||
servob=j;
|
servob=j;
|
||||||
OCR1A = SERVO_OFFSET + servob;
|
OCR3A = SERVO_OFFSET + servob;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue