Reading wireless RF data

Discussion specific to the 24-pin ZX microcontrollers, e.g. ZX-24r, ZX-24s and ZX-24t.
Post Reply
hakha4
Posts: 47
Joined: 01 June 2009, 21:23 PM
Location: Moholm Sweden

Reading wireless RF data

Post by hakha4 »

Hi!
I'm working on a project controlling wireless RF switches (Nexa) from zbasic using simple Rf sender/reciever TWS 434/RWS 434. I've got the sending code part to work using information from the net and I can control the 230V switches nearly to 100%. In short pulses are send as shown below :


12-bit code for House/Unit A1 ON 000000000111
12-bit code for House/Unit A1 OFF 000000000110



xxxx____ 4-bit House code
||||xxxx________ 4-bit Unit code
||||||||xxx_____ 3-bit Unknown code = '011'
|||||||||||x____ 1-bit Activation code 1=ON 0=OFF




a logic '0' is: 360 us high, 1070 us low, 360 us high, 1070 us low

a logic '1' is :360 us high, 1070 us low,1070 us high,360 us low

STOP/SYNC is : 360 us high, 1250 us low after each 12-bit packet

I know this issue have been discussed earlier to some extent but I'm unsure what method to use reading data from reciever. My approach sofar is to use the linear output on the reciever to trig an interrupt and this seems to work ok. I then use InputCapture to read data on the data out pin on the reciever. Data read in looks like 'garbage'
and is inconsistent between readings

Incoming data 'ON'
3531
20682
7964
7051
6490
26950
1333
8470
12389
27606
1733
65535
Incoming data 'OFF'
6035
1589
10689
10995
2125
7565
2979
9999
3690
28251
1135
65535

Can someone give me a hint what approach to use . Below is essential part of code for reading data

Code: Select all


Public RWS_434_TaskStack (1 To 30) As Byte

RWS_434_Ready = False

CallTask RWS_434_checkdata,RWS_434_TaskStack
'

Sub Main
Do


If RWS_434_Ready Then 'data avaliable
Debug.print "Incoming data"
Call Read_RWS_434
'Call Test
End If
     Call Delay(2.0)
   Loop
End Sub

Public RWS_434_Ready as Boolean 

Public Sub RWS_434_checkdata() 
  Do 
    RWS_434_Ready = True 
    Call WaitForInterrupt(zxPinRisingEdge, 0) 'pin 6 on zx24p  Pin 14, int 6 on ZX 1281e 
  Loop 
End Sub

Public Sub Read_RWS_434()

Dim pd(1 to 12) as UnsignedInteger
Dim x As Integer

'useInputCapture uses pin 12 on zx24p
' Port C Bit 1 must be an input 

Call PutPin(12, zxInputTriState)

Call InputCapture(pd, UBound(pd), 1)
For X = 1 To 12
Debug.print pd(x)
Next
RWS_434_Ready = False


End Sub



Regards Håkan
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Reading wireless RF data

Post by dkinzer »

hakha4 wrote:Data read in looks like 'garbage' and is inconsistent between readings
I could be that variable latency between the interrupt occurring and getting InputCapture set up is causing inconsistent results. An alternate approach that might work is to write a specialized variant of InputCapture that ignores timer overflow until the first transition. You could either store the raw data (high/low counts) or build in recognition of the start/stop and 0/1 patterns.
- Don Kinzer
hakha4
Posts: 47
Joined: 01 June 2009, 21:23 PM
Location: Moholm Sweden

Post by hakha4 »

Thanks Don for reply
I've tried to send same commands several times to see if there is a pattern to regocnize but don't seems to be. Shouldn't occasionly some pulse be read with correct value? . I tried with Pulsin command just to verify that data arrives correct and it reads the very last pulse correct but I can't figure out how to read pulses in from a loop.

I don't have the knowledge to write a special form of InputCapture you recommended

Code: Select all

Do While pulseWidth <> 0

pulseWidth = CUInt&#40;CSng&#40;PulseIn&#40;myPin, polarity&#41;&#41; / pwUnits / 2.0&#41;
width&#40;y&#41;= pulseWidth
Loop

gives output :

0 ?
2550 ( us ,correct)

Should I try get data in via a serial port instead? I read on Dave Houston's site that this is not the best way

Any help appreciated
Regards Håkan
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

hakha4 wrote:Should I try get data in via a serial port instead?
I'm not familiar with this transmitter/receiver pair but I doubt that PulseIn() is the way to go. Do you have example code (in any language) showing how to receive data from the RWS 434? If so, post a link to it or send it to me by email and I'll take a look to get some ideas on how to proceed.
Last edited by dkinzer on 11 July 2012, 12:42 PM, edited 1 time in total.
- Don Kinzer
DocJC
Posts: 112
Joined: 16 March 2006, 6:23 AM
Location: Cleveland, OH
Contact:

Post by DocJC »

Are you feeding the "Linear Output" through a BPF and cleaning up the signal before feeding it to the uC?

I think the Linear Output is provided for those who wish to clean up the signal and attemp to improve the signal to noise ratio of the receiver.

I've use a similar receiver before, and I used the digital output. The linear output is a constant stream of noise in the abscence of a signal, and detecting the signal reliably was not trivial.

As the receiver module also provides a "digital output", I would be inclined to use that output to feed the uC.

How you decode the data stream is actually a complex question, with many options available.

One approach is to sample the input and watch for a level change, then use this to sample the bit value in the middle of its bit time window, (or sample the bit time window several times to help reduce noise induced errors).

One can use a software PLL to synch on the bit transitions to help lock in on the signal.

It would probably be much easier to use another micro to generate an output signal that matches the ideal signal from the receiver to feed into your decoder micro while working on your code.

When the program works, then switch to the real, RF receiver generated signal, as it will have more noise and be significantly harder to reliably decode.

Having an O'scope to actually see the signal generated by the receiver is helpful. The low cost modules expect your micro to do a bit of work in decoding the signal. The output is typically generated from an RF receiver and some analog circuitry, without any intelligence provided by a micro to help decode the signal.

This is very different from a Bluetooth module, or XBee module, where there is an on board micro that is decoding the RF output, processing the signal, cleaning it up significantly, possibly providing error detecting or error correcting measures, and output what is, by and large, a clean signal.

JC
hakha4
Posts: 47
Joined: 01 June 2009, 21:23 PM
Location: Moholm Sweden

Post by hakha4 »

Don ! I've send you an email.
Jc,thank's for your comments. I'm using the linear output just for detecting incoming data trough an interrupt and this part seems to be ok. I then try to read the pulsetrain via the data output pin and this is the tricky part. I know it has been done by others reading the Nexa protocol but it is hard to get specific information on how it's done. Found a code snippet at http://arduino.cc/playground/Code/HomeEasy
and Don is kind to take a look at this to see how to port to zbasic
Regards Håkan
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

hakha4 wrote:I'm using the linear output just for detecting incoming data trough an interrupt and this part seems to be ok.
I've attached some code that correctly decodes a signal sent by another ZX using the "custom input capture" approach that I mentioned. You won't need the linear output with this code, it just puts received data in a queue and you can read it out at your leisure.

The code implements the timing that you described in a private email which is slightly different than what you described above. In any event, it should be fairly easy for you to adjust the nominal timing values (OnTime0, OnTime1 and BitTime, expressed in microseconds) as well as the allowed deviation from the nominal timing (plus or minus BitDelta).
Attachments
CustomInCapt.zip
Custom Input Capture for a NEXA signal (simple protocol only).
(3.02 KiB) Downloaded 625 times
- Don Kinzer
hakha4
Posts: 47
Joined: 01 June 2009, 21:23 PM
Location: Moholm Sweden

Post by hakha4 »

Got my zx328n in the mail and have tested code provided by Don . Works perfect,thank's
Håkan :D
Post Reply