|
Re: Controlling Jaguar with c code
This is the PWM code we are currently running
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
// Mode: Fast PWM top=0x00FF
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xA1;
TCCR1B=0x0D;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0xFF;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
while (1)
{
//XBEE Transmit & Receive
//delay_ms(10);
//PORTB = 0x1C;
USART_Receive();
//delay_ms(1000);
//PWM Drive Code
if(rxData == 0x31)
{
OCR1AL = 0x00; //set 0% duty cycle
//OCR1BL = 0x00; //set 0% duty cycle
}
else if(rxData == 0x33)
{
OCR1AL = 0x9E; //set 62% duty cycle
//OCR1BL = 0x66; //set 40% duty cycle
}
else if(rxData == 0x44)
{
OCR1AL = 0xB2; //set 70% duty cycle
//OCR1BL = 0x80; //set 50% duty cycle
}
else if(rxData == 0x55)
{
OCR1AL = 0xCC; //set 80% duty cycle
//OCR1BL = 0x9E; //set 62% duty cycle
}
else if(rxData == 0x66)
{
OCR1AL = 0xE6; //set 90% duty cycle
}
else if(rxData == 0x77)
{
OCR1AL = 0xFF; //set 100% duty cycle
}
//Reverse drive
else if(rxData == 0x35)
{
OCR1AL = 0x9E; //set 62% duty cycle
}
else if(rxData == 0x36)
{
OCR1AL = 0xB2; //set 70% duty cycle
}
else if(rxData == 0x37)
{
OCR1AL = 0xCC; //set 80% duty cycle
}
else if(rxData == 0x38)
{
OCR1AL = 0xE6; //set 90% duty cycle
}
else if(rxData == 0x39)
{
OCR1AL = 0xFF; //set 100% duty cycle
}
else
{
//OCR1AL = 0x00; //set 0% duty cycle
}
}
}
|