A simple IR Tx Rx system - Packet Errors
hello.
i have tried make own little ir transmitter attiny85 16mhz external crystal.
i using nano tsop rx.
i have various tsop packages...i lost may what. have following ones available (labels on of package):225 ,386,233,148,322 , have 41 in breadboard.
they have green band (i assume 38khz) except 233 has brown/orange band.
i using code here send bytes 0-255 in loop 10ms delay.
my code uses high low period denote "1" , low low denote "0".
this give rx "rest" not on saturate (as per data sheet).
tsop41
i have burst 600us long @ 38khz giving ~23 cycles per burst.
each burst followed @ least 600us low period.
the datasheet says:
"minimum burst length 6 cycles/burst"
"after each burst of length gap time required of 6 70 cycles ≥ 10 cycles"
"for bursts greater minimum gap time in data stream needed of 70 cycles > 1.2 x burst length"
"maximum number of continuous short bursts/second 2000"
i thought had satisfied above having @ least 23 cycle gap after every 23 cycles.
i.e.
when run code shown, works. noticed packets causing issues, not expected +1 on last value. started log them , collected ~50,000 bytes occurred ~900 errors.
i plotted frequency table , can see ones seem "wrong" not random , there seems sway toward ones had previous numbers lot of 1s had higher failure rate.
how can eliminate issue?
code tx:
code rx:
thank help!
i have tried make own little ir transmitter attiny85 16mhz external crystal.
i using nano tsop rx.
i have various tsop packages...i lost may what. have following ones available (labels on of package):225 ,386,233,148,322 , have 41 in breadboard.
they have green band (i assume 38khz) except 233 has brown/orange band.
i using code here send bytes 0-255 in loop 10ms delay.
my code uses high low period denote "1" , low low denote "0".
this give rx "rest" not on saturate (as per data sheet).
tsop41
i have burst 600us long @ 38khz giving ~23 cycles per burst.
each burst followed @ least 600us low period.
the datasheet says:
"minimum burst length 6 cycles/burst"
"after each burst of length gap time required of 6 70 cycles ≥ 10 cycles"
"for bursts greater minimum gap time in data stream needed of 70 cycles > 1.2 x burst length"
"maximum number of continuous short bursts/second 2000"
i thought had satisfied above having @ least 23 cycle gap after every 23 cycles.
i.e.
when run code shown, works. noticed packets causing issues, not expected +1 on last value. started log them , collected ~50,000 bytes occurred ~900 errors.
i plotted frequency table , can see ones seem "wrong" not random , there seems sway toward ones had previous numbers lot of 1s had higher failure rate.
how can eliminate issue?
code tx:
code: [select]
int baud = 600;
byte packsize = 8;
void setup() {
clkpr = 0 // clock pre-scale register = 0. clock division factor = 1
;
ddrb = 0
| (1 << pb1); //set pin pb1 output
ocr1c = 12; // counter max...clock cycles before pin toggled.
pllcsr = 0;
}
void loop() {
// send numbers 0 256.
(byte = 0; < 16000; i++) {
senddata(i);
delay(10);
}
}
void senddata(int x) {
int compare_bits = 0b10000000;
highbit(); // startbit.
(byte = 0; < packsize; i++) {
if (compare_bits & x) { // if last bit in x == 1...
highbit(); // send highbit.
}
else {
lowbit();
}
compare_bits = compare_bits >> 1; //shift compare along next bit...
}
}
void highbit() {
//turn 38-40khz pin on, delay (baud) , turn off.
// high bit 1 adn 0.
tccr1 = 0
| (1 << ctc1)
| (1 << com1a0) //bits 5 , 4 of tccr1 (com1a0 , com1a1) indicate when comparator == counter
| (0 << com1a1) // when a0 1 , a1 0, pin toggled on compare.
| (0 << cs13)
| (1 << cs12) // table 12-5. timer/counter1 prescale select. divides clock amount.
| (0 << cs11)
| (1 << cs10);
delaymicroseconds(baud);
tccr1 = 0;
delaymicroseconds(baud);
}
void lowbit() {
// low bit 00;
delaymicroseconds(baud);
delaymicroseconds(baud);
}
code rx:
code: [select]
int baud = 600;
int doublebaud = baud * 2;
unsigned int rxd = 0;
byte state;
byte packsize = 8;
long errors = 0;
int last_num = 0;
long total_bytes = 0;
void setup() {
// put setup code here, run once:
pinmode(8, input);
serial.begin(115200);
}
void loop() {
// put main code here, run repeatedly:
if (!digitalread(8)) { // hit start bit...
delaymicroseconds(1400);
(int = packsize; > 0; i--) {
state = !digitalread(8);
serial.print(state);
rxd = rxd << 1;
rxd += state;
delaymicroseconds(doublebaud);
}
if (rxd != last_num + 1 && rxd > 0) {
errors++;
serial.print(",e");
}
else {
serial.print(",o");
}
last_num = rxd;
total_bytes++;
serial.print(",");
serial.print(rxd);
serial.print(",");
serial.print(total_bytes);
serial.print(",");
serial.println(errors);
rxd = 0;
}
}
thank help!
oh , before forget, tsop has 0.1uf cap across vs , gnd , 100ohm resistor between supply voltage , tsop rx voltage supply pin.
Arduino Forum > Using Arduino > Project Guidance > A simple IR Tx Rx system - Packet Errors
arduino
Comments
Post a Comment