PDA

View Full Version : Control NEXA 230V RF Switch



Fredrick
- 30th December 2008, 16:48
A PIC program for control NEXA 230V Switch with a PIC and the parallax RF transmitter
Bruce from www.rentron.com helpt me write this code, actually he wrote the hole code to me :)

http://www.nexa.se/res/produktbilder_stora/143021.jpg
http://www.parallax.com/Portals/0/Images/Prod/2/279/27980-M.jpg
Pictures are from
www.nexa.se and www.parallax.com



<html>
<head></head>
<body><!--StartFragment--><pre><code><font color="#000080"><i>'************************************************* ***************
'* Name : NEXA RemoteControl *
'* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 2008-12-30 *
'* Version : 1.0 *
'* Notes : PIC 16F872 @ 20 Mhz *
'* : *
'************************************************* ***************

</i></font><font color="#008000"><b>DEFINE </b></font>OSC 20

T <font color="#008000"><b>CON </b></font>350 <font color="#000080"><i>' T = 350uS
</i></font>T3 <font color="#008000"><b>CON </b></font>1050 <font color="#000080"><i>' 3T
</i></font>T32 <font color="#008000"><b>CON </b></font>11200 <font color="#000080"><i>' 32T (Stop/Synch)

' Note we're using 1 VS X as shown in text
</i></font>A1_ON <font color="#008000"><b>CON </b></font>%111000000000 <font color="#000080"><i>' 12-bit code for House/Unit A1 ON
</i></font>A1_OFF <font color="#008000"><b>CON </b></font>%011000000000 <font color="#000080"><i>' 12-bit code for House/Unit A1 OFF
' ||||||||||||____ 4-bit House code
' ||||||||________ 4-bit Unit code
' ||||____________ 3-bit Unknown code
' |_______________ 1-bit Activation code 1=ON 0=OFF
'
' House code Unit Code
' ------------------------
' | 0000 - A | 0000 - 1 |
' | X000 - B | X000 - 2 |
' | 0X00 - C | 0X00 - 3 |
' | XX00 - D | XX00 - 4 |
' | 00X0 - E | 00X0 - 5 |
' | X0X0 - F | X0X0 - 6 |
' | 0XX0 - G | 0XX0 - 7 |
' | XXX0 - H | XXX0 - 8 |
' | 000X - I | 000X - 9 |
' | X00X - J | X00X - 10 |
' | 0X0X - K | 0X0X - 11 |
' | XX0X - L | XX0X - 12 |
' | 00XX - M | 00XX - 13 |
' | X0XX - N | X0XX - 14 |
' | 0XXX - O | 0XXX - 15 |
' | XXXX - P | XXXX - 16 |
' ------------------------

</i></font>D_PACKET <font color="#008000"><b>VAR WORD </b></font><font color="#000080"><i>' Holds 12-bit data packet to send
</i></font>INDEX <font color="#008000"><b>VAR BYTE </b></font><font color="#000080"><i>' Data packet bit index pointer
</i></font>LOOPS <font color="#008000"><b>VAR BYTE </b></font><font color="#000080"><i>' Loop counter

</i></font>TX <font color="#008000"><b>VAR </b></font>PORTB.0 <font color="#000080"><i>' Connects to RF transmitter data in

</i></font><font color="#008000"><b>LOW </b></font>TX <font color="#000080"><i>' TX output idles low for RF carrier OFF

</i></font>Main:
D_PACKET = A1_ON
<font color="#008000"><b>GOSUB </b></font>Send
<font color="#008000"><b>PAUSE </b></font>5000
D_PACKET = A1_OFF
<font color="#008000"><b>GOSUB </b></font>Send
<font color="#008000"><b>PAUSE </b></font>5000
<font color="#008000"><b>GOTO </b></font>Main

Send:
<font color="#008000"><b>FOR </b></font>LOOPS = 1 <font color="#008000"><b>TO </b></font>4 <font color="#000080"><i>' send each packet 4 times
</i></font><font color="#008000"><b>FOR </b></font>INDEX = 0 <font color="#008000"><b>TO </b></font>11 <font color="#000080"><i>' sends 12 bits per pass LSB 1st

</i></font><font color="#008000"><b>HIGH </b></font>TX <font color="#000080"><i>' The 1st half of a 0 or X bit period is the
</i></font><font color="#008000"><b>PAUSEUS </b></font>T <font color="#000080"><i>' same so no need to repeat this sequence inside
</i></font><font color="#008000"><b>LOW </b></font>TX <font color="#000080"><i>' the IF block
</i></font><font color="#008000"><b>PAUSEUS </b></font>T3

<font color="#008000"><b>IF </b></font>D_PACKET.0[INDEX]=1 <font color="#008000"><b>THEN
HIGH </b></font>TX <font color="#000080"><i>' send a 1 bit (1=X here)
</i></font><font color="#008000"><b>PAUSEUS </b></font>T3
<font color="#008000"><b>LOW </b></font>TX
<font color="#008000"><b>PAUSEUS </b></font>T
<font color="#008000"><b>ELSE
HIGH </b></font>TX <font color="#000080"><i>' send a 0 bit
</i></font><font color="#008000"><b>PAUSEUS </b></font>T
<font color="#008000"><b>LOW </b></font>TX
<font color="#008000"><b>PAUSEUS </b></font>T3
<font color="#008000"><b>ENDIF
NEXT </b></font>INDEX <font color="#000080"><i>' loop until all 12-bits sent

' Start of Stop/Synch period after each 12-bit packet
</i></font><font color="#008000"><b>HIGH </b></font>TX
<font color="#008000"><b>PAUSEUS </b></font>T
<font color="#008000"><b>LOW </b></font>TX
<font color="#008000"><b>PAUSEUS </b></font>T32
<font color="#000080"><i>' End of Stop/Synch period

</i></font><font color="#008000"><b>NEXT </b></font>LOOPS <font color="#000080"><i>' send 4 packets per pass
</i></font><font color="#008000"><b>RETURN

END
</b></font></code></pre><!--EndFragment--></body>
</html>

Dennis
- 5th December 2009, 22:41
Hi all

Could somebody please help the code on the receiver side , in other words to decode this ?
the reaosn I am sasking is because I have the very same system at home and would like to add my little PIC project as a receiver to it.

Here's what I thought would work so far ....



'************************************************* ***************

DEFINE OSC 20

T CON 350 ' T = 350uS
T3 CON 1050 ' 3T
T32 CON 11200 ' 32T (Stop/Synch)

D_PACKET VAR WORD ' Holds 12-bit data packet to send
INDEX VAR BYTE ' Data packet bit index pointer
LOOPS VAR BYTE ' Loop counter

RX VAR word ' Connects to TX receiver data in
RXPORT VAR portb.0
RFCOUNT VAR byte[2] 'possibly be needing this
BITCOUNT var byte ' count number of bits received
MARKER var byte 'check pauses or spaces of incoming pulse

receive:
LOW RX ' RX output idles low for RF carrier OFF

DEFINE PULSIN_MAX 11200 '>11200 RETURNS 0
PulsIn RXPORT,1,RX 'receive pulse on portb.0 and hold in RX
If (RX<11200) Then receive 'pulse is too short or > pulsin max try again
While RXPORT=0:Wend 'wait pulse



And that's where I'm stuck :-(
What is the next thing to look for ? T or T3 and how would the code look ?
Do I use a WHILE loop ?
Should I be adding a REPEAT UNTIL ?
I imagine a counter condition needed as well until we reach 12 bits
Should I even be using pulsin or not ?


Any help would be greatly appreciated.

Kind regards

Dennis

dhouston
- 6th December 2009, 00:34
DEFINE PULSIN_MAX 11200 '>11200 RETURNS 0You need to change this. I suggest you make it 120% of the greatest expected pulse. Battery operated transmitters can vary ±10-15%.

Also, there is no 1:1 correspondence between uS and the units used by PulsIn. You need to study and understand the manual. At 20MHz, PulsIn units are 2uS.

Dennis
- 7th December 2009, 00:19
Hi again Dave

Hope all is well with you :-)

Thanks for the reply.

As always it has sent me hurtling off to get more info about pulsin and pulsout

So regarding your reply ...

Assuming the reciver side is also @ 20 MHz and T =350uS and 32T as per the above code is 11200 would that mean a figure of 13440 would be acceptable


DEFINE PULSIN_MAX 13440 >13440 returns a 0

or have I done the wrong by taking 120% of 11200
Should it be less ?
The reason I am asking is what happens if the pulse is less than 13440 , let's say it is the actual max without variance and is spot on as 11200 that arrives...do we just discard it ?
If I take max as 11200 and then take off 15% that leaves me with a figure of
9520.
This seems to be the one I should use because if the pulse is anything less than this then we should discard it right ?
Now i have a MIN and a MAX for the received initial pulse and something to test against right.
So...
IF pulsein < 9520 or > 13440 then discard it

Is that correct ?

Kind regards
Dennis

Do i have it correct so far ?