Go Down

Topic: Timing microsecond pulses  (Read 730 times) previous topic - next topic

WPD64

Dec 13, 2018, 08:50 pm Last Edit: Dec 13, 2018, 09:11 pm by WPD64
Dear Arduino community

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

Code: [Select]

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
//
//


AWOL

Why analogRead? it is very slow.

MarkT

#2
Dec 13, 2018, 10:27 pm Last Edit: Dec 13, 2018, 10:28 pm by MarkT
You need digitalRead for any digital encoding.

Is your signal not digital?

Or put another way please provide full details of all the hardware involved, so we don't have
to keep guessing and asking questions...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

WPD64

#3
Dec 13, 2018, 10:36 pm Last Edit: Dec 13, 2018, 10:52 pm by WPD64
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.

MarkT

Full details of all the hardware - that means links to datasheets/product pages, etc.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

WPD64

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.



AWOL

The details of the external hardware really are of no relevance here.
analogRead takes around 100 microseconds.
It's hard, in that case, to understand this thread's title.

WPD64

#7
Dec 13, 2018, 11:02 pm Last Edit: Dec 13, 2018, 11:14 pm by WPD64
If I was beeing unclear I am very sorry.
Maybe I should start a new thread along the lines of...

I took the quite inefficient way of analyzing a stream of noisy manchester encoded data in a tight loop using analogRead()

I than detected rising and falling edges manually and was able to decode the signal.
However, is there any more elegant way of implementing this.

The incoming signal is ~0 for LOW and ~3.3V for HIGH

WPD64

#8
Dec 13, 2018, 11:09 pm Last Edit: Dec 13, 2018, 11:14 pm by WPD64
analogRead takes around 100 microseconds.
It's hard, in that case, to understand this thread's title.
mmh, I am recording pulse widths of 500 +/- 30 us reliably.
title should maybe have been 'some 10 microseconds'

EDIT: or rather 'timing 500 us pulses'

Wawa

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.
Hash is normal on the data-slicer output of a 433Mhz receiver.

Everybody else is using a library for that.
I have used rs-switch, but there are others.
Leo..

WPD64

Hash is normal on the data-slicer output of a 433Mhz receiver.

'Hash' beeing noise ?
Sorry - I am not a native speaker

Wawa

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..

WPD64


WPD64

Alas rc-switch uses micros() as well. So no use to me.


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.

Go Up