Permalink
Browse files

fixed transmission interrupts to send more consistently. Also changed…

… last packet byte to 0xFF for less noticible flicker
  • Loading branch information...
1 parent fb3c4e8 commit 2c489b7334efb620737d81f77c7895e9ec4ef03e @Unchapped committed Aug 12, 2011
View
@@ -18,8 +18,8 @@
/* Global Variables */
//TODO: move this to EEPROM for separation of code and data!
-//Packet Format 0xAA sync byte |4 byte secret code | 0x00 clear byte
-unsigned char code[6] = {0xAA, 0xDE, 0xAD, 0xBE, 0xEF, 0x00};
+//Packet Format 0xAA sync byte |4 byte secret code | 0xFF clear byte
+unsigned char code[6] = {0xAA, 0xDE, 0xAD, 0xBE, 0xEF, 0xFF};
/* Custom interrupt flags */
#define TRANSMIT 0x01
@@ -35,41 +35,44 @@ volatile unsigned char flags;
// current transmitted bit index
unsigned char index;
-unsigned char bit;
+volatile unsigned char nextbit;
//timer 0 match interrupt
ISR(TIM0_COMPA_vect){
+ //update transmit bit in constant time
+ PORTB = (PORTB & ~_BV(PB4)) | nextbit;
+
+ //set the flag to take care of the logic
flags |= TRANSMIT;
}
int main(){
/* INIT CODE */
- cli();
+ cli(); //disable interrupts
+
+ flags = 0x00; //clear custom interrupt flag
+
+ //TODO: load custom pen codes from EEPROM
+ //need to add init while loop to handle EEPROM interrupts
/*Timer 0 init
- * output should change every 3 ms
- * that's 112.5 timer cycles at clk/256
+ * output should change every 10 ms
+ * that's 150 timer cycles at clk/64
*/
TCCR0A = _BV(WGM01); //Timer 0 set to CTC mode
TCCR0B = _BV(CS01) | _BV(CS00); //Timer on, 64 prescaler
//TCCR0B = _BV(CS02) | _BV(CS00); //Timer on, 1024 prescaler FOR TESTING
- OCR0A = TRANSMIT_TIME; //Match 3ms cycle
+ OCR0A = TRANSMIT_TIME; //Match 10ms cycle
TIMSK0 = _BV(OCIE0A); //Enable Match A interrupt
-
+
+ /* bit transmission setup */
DDRB = _BV(PB4); // enable output on port B, pin 4
-
- //TODO: load custom pen codes from EEPROM
-
- //clear custom interrupt flag
- flags = 0x00;
-
- //start transmission at address 0
- index = 0;
- bit = 0x00;
+ index = 0; //start transmission at address 0
+ nextbit = 0x00; //clear the next bit variable
sei(); //enable interrupts
- /* LOOP */
+ /*MAIN LOOP */
while(1){
//let ints do their thing...
@@ -78,11 +81,10 @@ int main(){
//increment index
index = (index + 1) % 48;
+ nextbit = 0x00;
if((code[index / 8] << (index % 8)) & 0x80)
- PORTB |= _BV(PB4);
- else
- PORTB &= ~_BV(PB4);
+ nextbit = _BV(PB4);
//clear the interrupt flag...
flags &= ~TRANSMIT;
Binary file not shown.
@@ -1,21 +1,22 @@
:1000000009C021C020C01FC01EC01DC01DC01BC014
:100010001AC019C011241FBECFE9CDBF10E0A0E661
-:10002000B0E0EAE2F1E002C005900D92A636B10719
+:10002000B0E0EEE3F1E002C005900D92A636B10714
:10003000D9F710E0A6E6B0E001C01D92A936B107DD
-:10004000E1F713D070C0DCCF1F920F920FB60F9262
-:1000500011248F93809168008160809368008F9154
-:100060000F900FBE0F901F901895F89482E08FBDEF
-:1000700083E083BF86E986BF84E089BF80E187BBD8
-:10008000109268001092670010926600789420E049
-:100090008091680080FFFCCF822F90E0019660E3A2
-:1000A00070E01AD0282FE82FE695E695E695F0E067
-:1000B000E05AFF4F8081922F977001C0880F9A9568
-:1000C000EAF787FF02C0C49A01C0C4988091680013
-:1000D0008E7F80936800DCCF97FB092E07260AD01D
-:1000E00077FD04D00CD006D000201AF470956195ED
-:1000F0007F4F0895F6F7909581959F4F0895AA1B1D
-:10010000BB1B51E107C0AA1FBB1FA617B70710F002
-:10011000A61BB70B881F991F5A95A9F78095909534
-:0A012000BC01CD010895F894FFCF53
-:06012A00AADEADBEEF00ED
+:10004000E1F71BD07AC0DCCF1F920F920FB60F9250
+:1000500011248F939F9388B3909166008F7E892B94
+:1000600088BB809168008160809368009F918F9128
+:100070000F900FBE0F901F901895F8941092680083
+:1000800082E08FBD83E083BF86E986BF84E089BFBD
+:1000900080E187BB1092670010926600789420E0A0
+:1000A00030E18091680080FFFCCF822F90E00196C4
+:1000B00060E370E01BD0282F10926600E82FE695D1
+:1000C000E695E695F0E0E05AFF4F8081922F977019
+:1000D00001C0880F9A95EAF787FF02C03093660047
+:1000E000809168008E7F80936800DBCF97FB092E9C
+:1000F00007260AD077FD04D00CD006D000201AF4D1
+:10010000709561957F4F0895F6F7909581959F4F73
+:100110000895AA1BBB1B51E107C0AA1FBB1FA6174E
+:10012000B70710F0A61BB70B881F991F5A95A9F7A0
+:0E01300080959095BC01CD010895F894FFCF05
+:06013E00AADEADBEEFFFDA
:00000001FF
Oops, something went wrong.

0 comments on commit 2c489b7

Please sign in to comment.