Skip to content
Snippets Groups Projects
Commit 3394fa63 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Change to fast PWM

parent 114a55bb
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment