I have written a sketch to parse real-time manchester encoded data.
This type of encoding requires the timing of consecutive HIGH and LOW states.
I saw no way to use pulseIn() because it consumes the trailing edge which would be needed to time the following state.
So I implented my own timing function using analogRead() and micros().
In my recent efforts to port the code to the z-uno I stumbled over the fact that z-uno does not offer micros().
Does anybody see any way to solve my problem?
EDIT: platform is the UNO.
Thanks so much
Sebastian
For reference here's my timing algorithm
unsigned long t0 = micros();
unsigned long t1 = t0;
int a = analogRead(pin);
while ((a >= sig_min) && (a <= sig_max) && ( t1-t0 < timeout)) {
a = analogRead(pin);
t1 = micros();
}
return (t1-t0);
// sig_min and sig_max are margins to bracket noisy HIGH or LOW
// e.g. for LOW: sig_min=0; sig_max=400
// for HIGH: sig_min=400; sig_max=32767
//
//
I had trouble using digitalRead() because the signal from the RF module is quit noisy.
The thing is, my programm is working flawlessly in processing RF data from a bunch of 433Mhz thermometers.
However, after browsing the forum about manchester decoding I am beginning to think I took a very unelegant approach and should be looking into interupts.
As to the setup:
I have started out with commercially available set of 8 thermometers and a display unit communicating at 433Mhz.
I took the receiver board from the display unit and connected it to a UNO input pin and began analyzing the incoming signals.
The details of the external hardware really are of no relevance here.
I have a manchester encoded signal on a UNO input pin [0...3.3V] which is somewhat noisy.
At the time of implemenation I considered the signal to not really be digital, so I chose to use analogRead() and do the digitization myself.
Yes, simple 433Mhz OOK receivers output a full digital signal (noise) when nothing is received.
It's up to the software to detect if it contains a valid remote signal.
rc-switch uses pin2 of an Uno (interrupt#0).
The library comes with examples.
Leo..
I noticed that your actual platform is a UNO, however if you can't get what you want, an Arduino DUE has an USART peripheral with the Manchester encoding/decoding option in hardware, easy to use.
ard_newbie:
I noticed that your actual platform is a UNO, however if you can't get what you want, an Arduino DUE has an USART peripheral with the Manchester encoding/decoding option in hardware, easy to use.
Thanks for that information. I'll keep that in mind for my next hardware purchase.
To those of you wondering why I am not using a digital input and interrupts:
The signal is actually only 2.5V for HIGH.
Because I orgininally implemented the code several years ago I had forgotten all about that.
Anyway, I solved the original problem of porting from Arduino to z-uno by implementing serial communication bewtween the two and leaving the RF/manchester part on the Arduino.
Just for your information:
The z-uno environment and compiler are really not fit to implement any complex stuff.
There are many shortcomings particularly in c++, e.g.
no static members
no class inheritance
limited functionality in initialization lists, hence no member variables by reference
Plus, compiler errors hardly ever point you the the correct line of code which makes debugging a pain.