diff --git a/ball_and_beam-2018/avr/ball_and_beam-2018.c b/ball_and_beam-2018/avr/ball_and_beam-2018.c index 4e7ac39d1918d4950cbd76d6679ad93d1e456dc7..3c64cdd6a304ef72dca37a60edb3dfa8e6cddae9 100644 --- a/ball_and_beam-2018/avr/ball_and_beam-2018.c +++ b/ball_and_beam-2018/avr/ball_and_beam-2018.c @@ -7,7 +7,8 @@ /* * Serial I/O assignments: * - * DI 0 -- Motor Overtemp + * DI 0 -- Ball On Beam + * DI 1 -- Motor Overtemp * * DO 0 -- Motor Brake * DO 1 -- Accelerometer Self-Test @@ -124,18 +125,18 @@ SIGNAL(USART_RXC_vect) switch (serialio_RXC(ch)) { case serialio_clearbit: { switch (serialio_channel) { - case 0: { PORTB &= ~0x08; } break; - case 1: { PORTC &= ~0x80; } break; + case 0: { PORTB &= ~0x08; } break; // motorBrake + case 1: { PORTC &= ~0x80; } break; // accelerometerSelfTest } } break; case serialio_setbit: { switch (serialio_channel) { - case 0: { PORTB |= 0x08; } break; - case 1: { PORTC |= 0x80; } break; + case 0: { PORTB |= 0x08; } break; // motorBrake + case 1: { PORTC |= 0x80; } break; // accelerometerSelfTest } } break; case serialio_pollbit: { - if (serialio_channel < 1) { + if (serialio_channel < 2) { serial_readbits |= (1<<serialio_channel); } } break; @@ -176,15 +177,15 @@ int main() serial_readconfig = 0; PORTA = 0x00; // PortA, pull-ups 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 PORTC = 0x00; // PortC, pull-ups / initial values DDRC = 0x80; // PortC, bit 7 output PORTD = 0x00; // PortD, pull-ups / initial values DDRD = 0x20; // PortD, bit 5 output TCCR0 = 0x05; // Timer0, Clock / 1024 - TCCR1A = 0x83; // OC1A 10 bit PWM (Phase Correct), clear A on match - TCCR1B = 0x01; // Clock / 1 + TCCR1A = 0x83; // OC1A 10 bit PWM (fast), active high + TCCR1B = 0x09; // Clock / 1 OCR1A = 0 & 0x3ff; UCSRA = 0x00; // USART: UCSRB = 0x98; // USART: RxIntEnable|RxEnable|TxEnable @@ -215,9 +216,17 @@ int main() if (channels & 0x08) { serialio_putchannel(3, local.accelerometerY); } if (channels & 0x10) { serialio_putchannel(4, local.accelerometerZ); } 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) { - 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(1, CONF_RESOLUTION(1)); // accelerometerSelfTest