Wed, 16 Nov 2011 12:29:09 +0100
fixes, bound lap counter reset to race start button
blackbox/driver/adc.c | file | annotate | diff | comparison | revisions | |
blackbox/lowlevel.c | file | annotate | diff | comparison | revisions | |
blackbox/main.c | file | annotate | diff | comparison | revisions | |
blackbox/main.h | file | annotate | diff | comparison | revisions |
--- a/blackbox/driver/adc.c Tue Nov 15 12:51:04 2011 +0100 +++ b/blackbox/driver/adc.c Wed Nov 16 12:29:09 2011 +0100 @@ -12,11 +12,11 @@ // get a sample from ADC chip. // chanell must be in range 0-7. uint16_t getADC(int channel) { - if (channel == 0) +// if (channel == 0) adcReference = ((1<<REFS1) | (1<<REFS0)); // switch to 2.56V (~2x //adcReference = (1<<REFS1); // switch to 1.1v (~4.5x) - not on ATMEGA16 - else - adcReference = (1<<REFS0); // switch to 5v (1x) +// else +// adcReference = (1<<REFS0); // switch to 5v (1x) ADMUX = adcReference + channel; // start one sample ADCSRA |= (1<<ADSC);
--- a/blackbox/lowlevel.c Tue Nov 15 12:51:04 2011 +0100 +++ b/blackbox/lowlevel.c Wed Nov 16 12:29:09 2011 +0100 @@ -42,10 +42,18 @@ } void init_hardware(void) { + // reset all ports to input, no pullup + DDRA = 0; PORTA = 0; + DDRB = 0; PORTB = 0; + DDRC = 0; PORTC = 0; + DDRD = 0; PORTD = 0; + + RS232_init(); // initialize RS485 interface RS232_puts_p(PSTR("CARRERA beta loading\n")); initADC(); + SFIOR = 0; // set LED output DDR(LED1_PORT) |= _BV(LED1); @@ -59,11 +67,17 @@ // switch pull-ups SW_FUEL_PORT |= _BV(SW_FUEL); + SW_START_PORT |= _BV(SW_START); + SW_PACECAR_PORT |= _BV(SW_PACECAR); + // control outputs + DDR(LAP_COUNTER_PORT) |= _BV(LAP_COUNTER); + + // setup rail control //RAIL_DETECT_PORT |= _BV(RAIL_DETECT); // enable internal pull-up DDR(RAIL_POWER_PORT) |= _BV(RAIL_POWER); - + // display init sequence on LEDs LED(1, 1); _delay_ms(50); LED(2, 1); _delay_ms(50); LED(3, 1); _delay_ms(50); @@ -82,15 +96,13 @@ // setup data bit timer - TCCR2 = (1<<CS21); //divide by 8 - TCCR2 |= (1<<WGM21); // set compare match + TCCR2 = (1<<CS21) | (1<<WGM21); //divide by 8, set compare match OCR2 = TIMER2_50US; TIMSK |= 1<<OCIE2; //enable timer2 interrupt // setup data packet timer //TCCR1A = (1<<COM1A1); - TCCR1B = (1<<CS11); //divide by 8 - TCCR1B |= (1<<WGM12); // set compare match + TCCR1B = (1<<CS11) | (1<<WGM12); //divide by 8, set compare match //TCCR1B = (1<<CS11) | (1<<CS10); //divide by 64 //TCNT1 = TIMER_7500NS; OCR1A = TIMER1_7500NS;
--- a/blackbox/main.c Tue Nov 15 12:51:04 2011 +0100 +++ b/blackbox/main.c Wed Nov 16 12:29:09 2011 +0100 @@ -90,19 +90,19 @@ uint16_t tmp; switch (controller) { case 0: - tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1; + tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) tmp |= (1<<5); break; case 1: - tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1; + tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) tmp |= (1<<5); break; case 2: - tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1; + tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) tmp |= (1<<5); break; case 3: - tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1; + tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) tmp |= (1<<5); break; case 4: tmp = (1<<5); break; // todo regler 5 @@ -230,6 +230,11 @@ } else timer0_delay--; // 2.3 ms delay not reached yet } +ISR (INT2_vect) { + // Lap counter Interrupt + LED(5,2); +} + int main(void) { @@ -248,6 +253,12 @@ // check for short circuit on the rails check_rails_shortcut(); + // read in button presses + if ( (PIN(SW_START_PORT) & _BV(SW_START)) == 0 ) { + // start button press active + LAP_COUNTER_PORT |= _BV(LAP_COUNTER); + } else LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER); + switch (packet_index) { case 1: if (program_count > 0) {
--- a/blackbox/main.h Tue Nov 15 12:51:04 2011 +0100 +++ b/blackbox/main.h Wed Nov 16 12:29:09 2011 +0100 @@ -13,8 +13,8 @@ #define MODUL_ST6 PD6 #define I2C_PORT PORTC -#define I2C_SDA PC0 -#define I2C_SCL PC1 +#define I2C_SCL PC0 +#define I2C_SDA PC1 #define LED1_PORT PORTA #define LED2_PORT PORTA @@ -45,10 +45,10 @@ #define CONTROLLER_PORT PORTB #define CONTROLLER_MAX 360 // full throttle ADC value #define CONTROLLER_DIVISOR (uint8_t)(CONTROLLER_MAX/15) -#define CONTROLLER1_SW 4 -#define CONTROLLER2_SW 5 -#define CONTROLLER3_SW 6 -#define CONTROLLER4_SW 7 +#define CONTROLLER1_SW PB4 +#define CONTROLLER2_SW PB5 +#define CONTROLLER3_SW PB6 +#define CONTROLLER4_SW PB7 #define CONTROLLER1_SPEED 0 // ADC channel # #define CONTROLLER2_SPEED 1 // ADC channel # #define CONTROLLER3_SPEED 2 // ADC channel #