Control NEXA 230V RF Switch


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187

    Default Control NEXA 230V RF Switch

    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



    Pictures are from
    www.nexa.se and www.parallax.com

    Code:
    <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>

  2. #2


    Did you find this post helpful? Yes | No

    Default decode ?

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

    Code:
    '****************************************************************
    
    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
    Last edited by Dennis; - 5th December 2009 at 21:45.

  3. #3
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    Code:
    DEFINE PULSIN_MAX 11200				'>11200 RETURNS 0
    You 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.

  4. #4


    Did you find this post helpful? Yes | No

    Default pulsin max

    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
    Code:
    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 ?

Similar Threads

  1. Simple RF remote control code
    By Bruce in forum Code Examples
    Replies: 13
    Last Post: - 22nd January 2014, 10:45
  2. Need help - Just want to make a simple switch using RF Modules
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 25th October 2009, 10:38
  3. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  4. PIC to control NEXA remoteswitch
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 8th January 2009, 11:29
  5. RF Remote control
    By eralp in forum General
    Replies: 3
    Last Post: - 10th January 2007, 23:15

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts