Skip to content

Commit e35bfde

Browse files
committed
Corrected and error where the data bit is captured
to stop overun errors at th eend of bytes causing the whole packet to be dumped. It shoudl read the last bit of the last byte without, what happens after that wrecking it.
1 parent abfac77 commit e35bfde

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

DebugManchester.ino

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
/*
22
Manchester Decoding, reading by delay rather than interrupt
3-
Rob Ward July 2014
3+
Rob Ward August 2014
44
This example code is in the public domain.
55
Use at your own risk, I will take no responsibility for any loss whatsoever its deployment.
66
Visit https://github.com/robwlakes/ArduinoWeatherOS for the latest version and
7-
documentation. Filename: DebugManchester.ino ReadMe: DebugMan.md
8-
9-
NB: Choosing the wrong polarity will still provide "data", but will be incorrect
10-
even thought the two delays are working properly!!!
11-
Remember to check both Polarity settings for sensible data.
7+
documentation. Filename: DebugManchester.ino
128
13-
DebugVersion_09, 28tyh July 2014
9+
DebugVersion_10, 1stAugust 2014
1410
1511
*/
1612

@@ -19,11 +15,10 @@ int RxPin = 8; //The number of signal from the Rx
1915
int ledPin = 13; //The number of the onboard LED pin
2016

2117
// Variables for Manchester Receiver Logic:
22-
word sDelay = 240; //Small Delay about 1/4 of bit duration try like 220 to 480
23-
word lDelay = 480; //Long Delay about 1/2 of bit duration try like 440 to 880, 1/4 + 1/2 = 3/4
18+
word sDelay = 250; //Small Delay about 1/4 of bit duration try like 250 to 500
19+
word lDelay = 500; //Long Delay about 1/2 of bit duration try like 500 to 1000, 1/4 + 1/2 = 3/4
2420
byte polarity = 1; //0 for lo->hi==1 or 1 for hi->lo==1 for Polarity, sets tempBit at start
25-
byte tempBit ; //Reflects the required transition polarity
26-
byte bitState ; //State of the RxPin 3/4 way through Bit Waveform
21+
byte tempBit = 1; //Reflects the required transition polarity
2722
byte discards = 0; //how many leading "bits" need to be dumped, usually just a zero if anything eg discards=1
2823
boolean firstZero = false;//has it processed the first zero yet? This a "sync" bit.
2924
boolean noErrors = true; //flags if signal does not follow Manchester conventions
@@ -33,7 +28,7 @@ byte headerHits = 0; //Counts the number of "1"s to determine a header
3328
//Variables for Byte storage
3429
byte dataByte = 0; //Accumulates the bit information
3530
byte nosBits = 0; //Counts to 8 bits within a dataByte
36-
byte maxBytes = 6; //Set the bytes collected after each header. NB if set too high, any end noise will cause an error
31+
byte maxBytes = 5; //Set the bytes collected after each header. NB if set too high, any end noise will cause an error
3732
byte nosBytes = 0; //Counter stays within 0 -> maxBytes
3833
//Variables for multiple packets
3934
byte bank = 0; //Points to the array of 0 to 3 banks of results from up to 4 last data downloads
@@ -61,7 +56,7 @@ void setup() {
6156
Serial.begin(115200);//make it fast so it dumps quick!
6257
pinMode(RxPin, INPUT);
6358
pinMode(ledPin, OUTPUT);
64-
Serial.println("Debug Manchester Version GIT-Hub V01");
59+
Serial.println("Debug Manchester Version 09");
6560
lDelay=2*sDelay;//just to make sure the 1:2 ratio is established. They can have some other ratio if required
6661
Serial.print("Using a delay of 1/4 bitWaveform ");// +-15% and they still seem to work ok, pretty tolerant!
6762
Serial.print(sDelay,DEC);
@@ -91,7 +86,7 @@ void setup() {
9186

9287
// Main routines, find header, then sync in with it, get a packet, and decode data in it, plus report any errors.
9388
void loop(){
94-
tempBit=polarity^1; //these begin as opposites for each packet
89+
tempBit=polarity^1; //these begin the opposites for a packet
9590
noErrors=true;
9691
firstZero=false;
9792
headerHits=0;
@@ -108,18 +103,16 @@ void loop(){
108103
noErrors=false;//something has gone wrong, polarity has changed too early, ie always an error
109104
}//exit and retry
110105
else{
111-
//now grab the bitState before setting up for next bit & correct for polarity
112-
bitState = tempBit ^ polarity;//Polarity=1, invert OR Polarity=0, ignore
113-
//Now work on what the next bit waveform is going to be
106+
byte bitState = tempBit ^ polarity;//if polarity=1, invert the tempBit or if polarity=0, leave it alone.
114107
delayMicroseconds(lDelay);
115108
//now 1 quarter into the next bit pattern,
116-
if(digitalRead(RxPin)==tempBit){ //if RxPin has NOT swapped, then next data bit value IS swapping
109+
if(digitalRead(RxPin)==tempBit){ //if RxPin has not swapped, then bitWaveform is swapping
117110
//If the header is done, then it means data change is occuring ie 1->0, or 0->1
118-
//data transition detection must swap, so it loops for the opposite transition in the next bit waveform
111+
//data transition detection must swap, so it loops for the opposite transitions
119112
tempBit = tempBit^1;
120-
}//end of detecting no transition at end of bit waveform
113+
}//end of detecting no transition at end of bit waveform, ie end of previous bit waveform same as start of next bitwaveform
121114

122-
//Now process the tempBit state and interept data as definite 0 or 1's, (Polarity corrected by now)
115+
//Now process the tempBit state and make data definite 0 or 1's, allow possibility of Pos or Neg Polarity
123116
if(bitState==1){ //1 data could be header or packet
124117
if(!firstZero){
125118
headerHits++;
@@ -142,7 +135,6 @@ void loop(){
142135
//we have our header, chewed up any excess and here is a zero
143136
if ((!firstZero)&&(headerHits>=headerBits)){ //if first zero, it has not been found previously
144137
firstZero=true;
145-
//Serial.print("!");
146138
}//end of finding first zero
147139
add(bitState);
148140
}//end of dealing with a zero
@@ -170,7 +162,7 @@ void add(byte bitData){
170162
//Serial.print("B");
171163
}
172164
if(nosBytes==maxBytes){
173-
hexBinDump();//for debug purposes dump out in hex and bainary
165+
hexBinDump();//for debug purposes dump out in hex and binary
174166
//analyseData();//later on develop your own analysis routines
175167
}
176168
}
@@ -212,3 +204,18 @@ void eraseManchester(){
212204

213205

214206

207+
208+
209+
210+
211+
212+
213+
214+
215+
216+
217+
218+
219+
220+
221+

0 commit comments

Comments
 (0)