Commit 3394fa63 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Change to fast PWM

parent 114a55bb
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
/* /*
* Serial I/O assignments: * Serial I/O assignments:
* *
* DI 0 -- Motor Overtemp * DI 0 -- Ball On Beam
* DI 1 -- Motor Overtemp
* *
* DO 0 -- Motor Brake * DO 0 -- Motor Brake
* DO 1 -- Accelerometer Self-Test * DO 1 -- Accelerometer Self-Test
...@@ -124,18 +125,18 @@ SIGNAL(USART_RXC_vect) ...@@ -124,18 +125,18 @@ SIGNAL(USART_RXC_vect)
switch (serialio_RXC(ch)) { switch (serialio_RXC(ch)) {
case serialio_clearbit: { case serialio_clearbit: {
switch (serialio_channel) { switch (serialio_channel) {
case 0: { PORTB &= ~0x08; } break; case 0: { PORTB &= ~0x08; } break; // motorBrake
case 1: { PORTC &= ~0x80; } break; case 1: { PORTC &= ~0x80; } break; // accelerometerSelfTest
} }
} break; } break;
case serialio_setbit: { case serialio_setbit: {
switch (serialio_channel) { switch (serialio_channel) {
case 0: { PORTB |= 0x08; } break; case 0: { PORTB |= 0x08; } break; // motorBrake
case 1: { PORTC |= 0x80; } break; case 1: { PORTC |= 0x80; } break; // accelerometerSelfTest
} }
} break; } break;
case serialio_pollbit: { case serialio_pollbit: {
if (serialio_channel < 1) { if (serialio_channel < 2) {
serial_readbits |= (1<<serialio_channel); serial_readbits |= (1<<serialio_channel);
} }
} break; } break;
...@@ -176,15 +177,15 @@ int main() ...@@ -176,15 +177,15 @@ int main()
serial_readconfig = 0; serial_readconfig = 0;
PORTA = 0x00; // PortA, pull-ups PORTA = 0x00; // PortA, pull-ups
DDRA = 0x00; // PortA, all inputs DDRA = 0x00; // PortA, all inputs
PORTB = 0x00; // PortB, pull-ups / initial values PORTB = 0x10; // PortB, pull-ups / initial values
DDRB = 0x0a; // PortB, bits 1 & 3 outputs DDRB = 0x0a; // PortB, bits 1 & 3 outputs
PORTC = 0x00; // PortC, pull-ups / initial values PORTC = 0x00; // PortC, pull-ups / initial values
DDRC = 0x80; // PortC, bit 7 output DDRC = 0x80; // PortC, bit 7 output
PORTD = 0x00; // PortD, pull-ups / initial values PORTD = 0x00; // PortD, pull-ups / initial values
DDRD = 0x20; // PortD, bit 5 output DDRD = 0x20; // PortD, bit 5 output
TCCR0 = 0x05; // Timer0, Clock / 1024 TCCR0 = 0x05; // Timer0, Clock / 1024
TCCR1A = 0x83; // OC1A 10 bit PWM (Phase Correct), clear A on match TCCR1A = 0x83; // OC1A 10 bit PWM (fast), active high
TCCR1B = 0x01; // Clock / 1 TCCR1B = 0x09; // Clock / 1
OCR1A = 0 & 0x3ff; OCR1A = 0 & 0x3ff;
UCSRA = 0x00; // USART: UCSRA = 0x00; // USART:
UCSRB = 0x98; // USART: RxIntEnable|RxEnable|TxEnable UCSRB = 0x98; // USART: RxIntEnable|RxEnable|TxEnable
...@@ -215,9 +216,17 @@ int main() ...@@ -215,9 +216,17 @@ int main()
if (channels & 0x08) { serialio_putchannel(3, local.accelerometerY); } if (channels & 0x08) { serialio_putchannel(3, local.accelerometerY); }
if (channels & 0x10) { serialio_putchannel(4, local.accelerometerZ); } if (channels & 0x10) { serialio_putchannel(4, local.accelerometerZ); }
if (channels & 0x20) { serialio_putchannel(5, local.motorEncoder); } if (channels & 0x20) { serialio_putchannel(5, local.motorEncoder); }
if (bits & 0x01) { serialio_putbit(0, PORTB & 0x10); } // thermalFlag if (bits & 0x01) {
// ballOnBeam
serialio_putbit(0, PINB & 0x01);
}
if (bits & 0x02) {
// thermalFlag
serialio_putbit(1, !(PINB & 0x10));
}
if (config) { if (config) {
CONF_DIGITAL_IN(0, CONF_RESOLUTION(1)); // motorTemp CONF_DIGITAL_IN(0, CONF_RESOLUTION(1)); // ballOnBeam
CONF_DIGITAL_IN(1, CONF_RESOLUTION(1)); // motorTemp
CONF_DIGITAL_OUT(0, CONF_RESOLUTION(1)); // motorBrake CONF_DIGITAL_OUT(0, CONF_RESOLUTION(1)); // motorBrake
CONF_DIGITAL_OUT(1, CONF_RESOLUTION(1)); // accelerometerSelfTest CONF_DIGITAL_OUT(1, CONF_RESOLUTION(1)); // accelerometerSelfTest
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment