carrerashark minor changes

Sat, 03 Dec 2011 11:10:36 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Sat, 03 Dec 2011 11:10:36 +0100
changeset 31
a8f082503782
parent 30
10c78c097d18
child 32
b83d239fe719

carrerashark minor changes

carrerashark/README file | annotate | diff | comparison | revisions
carrerashark/main.c file | annotate | diff | comparison | revisions
--- a/carrerashark/README	Thu Dec 01 15:31:19 2011 +0100
+++ b/carrerashark/README	Sat Dec 03 11:10:36 2011 +0100
@@ -5,7 +5,7 @@
     PD2 = Controller Input
     |>o = Inv Schmitt Trigger for signal buffering (74hc14)
 
-    [RAIL+] ------[33kohm]------+-----|>o--|>0----[PD2]
+    [RAIL+] ------[33kohm]------+-----|>o--|>o----[PD2]
                                 |
                                 --[10kohm]---
                                             |
--- a/carrerashark/main.c	Thu Dec 01 15:31:19 2011 +0100
+++ b/carrerashark/main.c	Sat Dec 03 11:10:36 2011 +0100
@@ -57,16 +57,27 @@
 volatile uint8_t bitbuf_len = 0;
 volatile uint16_t bitbuf = 0;
 
+volatile uint16_t sysclock = 0;
+ISR ( TIMER0_OVF_vect ) {
+    PORTD ^= _BV(PD6);
+    if (sysclock != 0xffff) sysclock++;
+}
+
 ISR ( INT0_vect ) {
     PORTD ^= _BV(PD3);
+    if (sysclock<10) {
+        // this is the answer slot start bit??
+        PORTD ^= _BV(PD7);
+    } else {
     GICR &= ~_BV(INT0) ; // Disable INT0
-    // Startsignal erkannt, ab hier den Timer2 starten,
-    // der liest dann alle 50µs den Zustand ein und schreibt das
-    // empfangene Bit in den Puffer
-    bitbuf = 0; // init
-    bitbuf_len = 0b10000000; // init 1 pulse received
-    TCNT2 = 0;
-    TIMSK |= _BV(OCIE2); //enable timer2 interrupt
+        // Startsignal erkannt, ab hier den Timer2 starten,
+        // der liest dann alle 50µs den Zustand ein und schreibt das
+        // empfangene Bit in den Puffer
+        bitbuf = 0; // init
+        bitbuf_len = 0b10000000; // init 1 pulse received
+        TCNT2 = 0;
+        TIMSK |= _BV(OCIE2); //enable timer2 interrupt
+    }
 }
 
 
@@ -87,8 +98,10 @@
             data_len = (bitbuf_len & 0b00111111);
             if (data_len == 13) PORTD ^= _BV(6); // debug sync output on program packets
             TIMSK &= ~_BV(OCIE2); //disable timer2 interrupt
-            GICR |= _BV(INT0) ; // Enable INT0
+            GICR |= _BV(INT0); // Enable INT0
+            GIFR &= ~_BV(INTF0); // clear int0 irq flag
             data = bitbuf; // output data
+            sysclock = 0; // reset system clock counter
         } else {
             bitbuf_len++; // increment bit counter
             bitbuf = bitbuf << 1; // shift bits
@@ -119,13 +132,20 @@
     OCR2 = TIMER2_50US;
     TIMSK |= 1<<OCIE2; //enable timer2 interrupt
 
+    // setup system timer
+    TCCR0 = (1<<CS21); //divide by 8
+    TIMSK |= 1<<TOIE0; //enable timer0 interrupt
+
+
     MCUCR = _BV(ISC00); // falling edge
+//    MCUCR = _BV(ISC00) | _BV(ISC01); // rising edge
     GICR = _BV(INT0) ; // Enable INT0
 
-    DDRD |= _BV(PD3) | _BV(PD4) | _BV(PD5);
+    DDRD |= _BV(PD3) | _BV(PD4) | _BV(PD5) | _BV(PD6) | _BV(PD7);
+    PORTD |= _BV(PD7);
 
     RS232_init(); // initialize RS232 interface
-    RS232_puts_p(PSTR("CarreraShark 1.1\n"));
+    RS232_puts_p(PSTR("CarreraShark 1.2\n"));
 
     sei();
     i = 0;

mercurial