PDA

View Full Version : PIC to control NEXA remoteswitch



Fredrick
- 26th December 2008, 18:08
I have this RF transmitter http://www.parallax.com/Store/Accessories/Communication/tabid/161/CategoryID/36/List/0/Level/a/ProductID/113/Default.aspx?SortField=ProductName%2cProductName
And want to wite a program in PBP that controls NEXA remote switches http://www.elbutik.se/product.html?product_id=219031
i have found the protocol that NEXA use but i canīt understand how to write a program that sendīs the RF code.

I have tryed to play whit SEROUT, SERUOT2, and PULSOUT for some hours now but nothing works.

Can anyone here give me some tips on how to write the program?

NEXA protocol
http://svn.telldus.com/svn/rf_ctrl/nexa_2_6_driver/trunk/NexaProtocol.txt


I use PicBasicPro 2.50b.

Fredrick
- 28th December 2008, 19:34
Maybe itīs not posible whit PBP to write that code?

Archangel
- 28th December 2008, 21:04
I have this RF transmitter http://www.parallax.com/Store/Accessories/Communication/tabid/161/CategoryID/36/List/0/Level/a/ProductID/113/Default.aspx?SortField=ProductName%2cProductName
And want to wite a program in PBP that controls NEXA remote switches http://www.elbutik.se/product.html?product_id=219031
i have found the protocol that NEXA use but i canīt understand how to write a program that sendīs the RF code.

I have tryed to play whit SEROUT, SERUOT2, and PULSOUT for some hours now but nothing works.

Can anyone here give me some tips on how to write the program?

NEXA protocol
http://svn.telldus.com/svn/rf_ctrl/nexa_2_6_driver/trunk/NexaProtocol.txt


I use PicBasicPro 2.50b.

Hello Fredrick,
Your posts have made 1 thing very clear to me, and that is: You have not even bothered to look at the data sheet you linked to. Why did I say that ? No not to be mean spirited, but because THEY GIVE YOU the source code you are requesting here. Yes it is in pdf format which means you have to retype it. ( 9 lines of code each for xmit and receive ) to paraphrase sunday school; "The forum helps those, who help themselves".
So, get the transmitter and receiver talking to one another , sending data, and then worry about how to format it, you can manipulate the data on the receiver end if it turns out you cannot send it just the way you want it sent, the main thing is get the data there.

Fredrick
- 28th December 2008, 21:08
And were do you find the source code in PBP for control a NEXA swich from a Parallax transmitter?

I canīt find it.

EDIT
The code you are talking about is for transmitt to the Parallax RF reciver not the NEXA 230Volt remoteswitch.....!!!

Archangel
- 28th December 2008, 22:27
Do you have the transmit / receive link up and working? Can you control the nexa without the wireless? Seems like 3 separate problems, control nexa, control wireless, control both together.

Fredrick
- 28th December 2008, 22:39
Yes, the Parallax transmitter and reciver works fine, no problem...
I can read data sheets!!!

But how do i send the same RF code that the NEXA remote controls sends to the NEXA remote swich.

I have seen other projects that sends NEXA RF code whit a PIC and a RF transmitter but thats in ASM code.



extern IntRet
; extern ReceiveB,RT1Ini,IntRet,TxCharB
extern STRTUP
; extern STRTUP,TBuffCB

global RFNIni,RFNTrns
; global RTTrnsB
global CCP1Int,CCP2Int

include SYSTEM.INC ;System definitions
include P16C74A.INC ;Definitions for PIC16C74A

;************************************************* ***********************
;* *
;* CONSTANTS *
;* *
;* Constant definitions for this program module. *
;* *
;************************************************* ***********************

;
; Bittime definitions for NEXA RF transmitter
;
BITTIM1 equ 295 ;1/4 bittime
BITTIM2 equ 590 ;2/4 bittime
BITTIM3 equ 885 ;3/4 bittime
BITTIM4 equ 1180 ;4/4 bittime
BITTIMP equ 10240 ;Bittime for preamble
;BITTIME equ 590 ;Bittime for NEXA RF transmitter
BITTIME equ 295 ;Bittime for NEXA RF transmitter

;************************************************* ***********************
;* *
;* VARIABLES *
;* *
;* Variable definitions for this program module. *
;* *
;************************************************* ***********************

RAM0 UDATA

TXCount res 1 ;Transmission counts
BCount res 1 ;Transmit bit counter
XmtHldH res 1 ;Transmit/receive holding register high
XmtHldL res 1 ;Transmit/receive holding register low
XmtRegH res 1 ;Transmit/receive shift register high
XmtRegL res 1 ;Transmit/receive shift register low
BCountR res 1 ;Receive bit counter

XFlag res 1

;************************************************* ***********************
;* *
;* FUNCTIONS *
;* *
;* Functions for this program module. *
;* *
;************************************************* ***********************

PROM CODE

;
; Initalize device driver.
;
RFNIni movlw B'00000001' ;Enable timer 1
movwf T1CON

movlw B'00001000' ;CCP2 as output compare (pin RC1)
movwf CCP2CON

; movlw B'00000100' ;CCP1 as input capture (pin RC2)
; movwf CCP1CON

errorlevel -302
bsf STATUS,RP0 ;Bank 1
; bsf PIE1,CCP1IE ;Enable capture/compare 1 interrupt
bsf PIE2,CCP2IE ;Enable capture/compare 2 interrupt
bcf STATUS,RP0 ;Bank 0
errorlevel +302
return

;
; Transmitt data.
;
; IN: W = Data
; FSR = Address
; OUT: W,FSR destroyed
;
RFNTrns movwf XmtHldH ;Data
movfw FSR
movwf XmtHldL ;Address
swapf XmtHldL,f
movlw 4
movwf TXCount ;Number of transmissions
bsf XFlag,0
return

;
; Capture/compare 1 interrupt service routine.
;
CCP1Int bcf STATUS,RP0 ;Bank 0
bcf PIR1,CCP1IF ;Clear interrupt flag
tstf BCountR
bnz BitRead
; movlw low ( BITT15 ) ;Low byte of timer value (1.5 bittime)
addwf CCPR1L,w ;Update low byte of compare register
movwf FSR ;Use FSR for temp storage
; movlw high ( BITT15 ) ;High byte of timer value (1.5 bittime)
btfsc STATUS,C ;Update high byte of compare register
addlw 1 ;Add one for carry
addwf CCPR1H,f
movfw FSR
movwf CCPR1L
btfbs PORTC,2,IntRet ;Verify startbit twice
btfbs PORTC,2,IntRet
movlw 9
movwf BCountR
movlw B'00001010' ;CCP1 as interrupt only
movwf CCP1CON
goto IntRet

BitRead movlw low ( BITTIME ) ;Low byte of timer value
addwf CCPR1L,w ;Update low byte of compare register
movwf FSR ;Use FSR for temp storage
movlw high ( BITTIME );High byte of timer value
btfsc STATUS,C ;Update high byte of compare register
addlw 1 ;Add one for carry
addwf CCPR1H,f
movfw FSR
movwf CCPR1L

clrc
btfsc PORTC,2 ;Test receive bit (RC2)
setc
; rrf XmtReg,f ;Shift bit into receive register
decfsz BCountR,f ;Increment bitcount
goto IntRet
movlw B'00000100' ;CCP1 as input capture (pin RC2)
movwf CCP1CON
; rlf XmtReg,f ;Stopbit -> carry
bnc FErr ;Framing error if no stopbit

; movfw XmtReg ;Read received character
clrc
; call ReceiveB ;Decode message. Complete ?
goto IntRet

FErr setc
; call ReceiveB ;Decode message. Complete ?
goto IntRet

;
; Capture/compare 2 interrupt service routine.
;
CCP2Int bcf PIR2,CCP2IF ;Clear interrupt flag
bcf STATUS,RP0 ;Bank 0

btfbc XFlag,0,C2Norm0 ;Exit if transmission disabled
movfw BCount
bz C2z1
decfsz BCount,f
goto C2z2
decfsz TXCount,f
goto C2z1
bcf XFlag,0
goto C2Norm0

C2z1 movfw XmtHldH
movwf XmtRegH
movfw XmtHldL
movwf XmtRegL

rlf XmtRegL,f
rlf XmtRegH,f
movlw 50
movwf BCount
bsf CCP2CON,CCP2M0 ;Send bit = 1

movlw low (BITTIMP) ;Low byte of timer value (1/4 duty cycle)
addwf CCPR2L,w ;Update low byte of compare register
movwf FSR ;Use FSR for temp storage
movlw high (BITTIMP) ;High byte of timer value
goto C2SetL

; goto C2Norm

C2z2 btfsc BCount,0
bcf CCP2CON,CCP2M0 ;Send bit = 0
btfss BCount,0
bsf CCP2CON,CCP2M0 ;Send bit = 1

bcf STATUS,C ;Bit = 0
btfbc BCount,1,???1
btfbc BCount,0,???3
rrf XmtRegH,f
rrf XmtRegL,f
bcf STATUS,C ;Bit = 0
???3 btfsc XmtRegL,0
bsf STATUS,C ;Bit = 1
???1 btfbc BCount,0,???2
btfbs STATUS,C,???4
???5 movlw low (BITTIM1) ;Low byte of timer value (1/4 duty cycle)
addwf CCPR2L,w ;Update low byte of compare register
movwf FSR ;Use FSR for temp storage
movlw high (BITTIM1) ;High byte of timer value
goto C2SetL

???2 btfbs STATUS,C,???5
???4 movlw low (BITTIM3) ;Low byte of timer value (1/4 duty cycle)
addwf CCPR2L,w ;Update low byte of compare register
movwf FSR ;Use FSR for temp storage
movlw high (BITTIM3) ;High byte of timer value
goto C2SetL

C2Norm0 bcf CCP2CON,CCP2M0 ;Send bit = 0
C2Norm movlw low (BITTIM2) ;Low byte of timer value (1/4 duty cycle)
addwf CCPR2L,w ;Update low byte of compare register
movwf FSR ;Use FSR for temp storage
movlw high (BITTIM2) ;High byte of timer value
C2SetL btfsc STATUS,C ;Update high byte of compare register
addlw 1 ;Add one for carry
addwf CCPR2H,f
movfw FSR
movwf CCPR2L
goto IntRet

Archangel
- 28th December 2008, 22:50
Yes, the Parallax transmitter and reciver works fine, no problem...
I can read data sheets!!!

OK, sorry, I thought that was what you were having trouble with. From fishing the internet this thing looks a lot like X10 controls, and I am guessing you want to control it without interfacing to a nexa transmitter, yes?

Fredrick
- 28th December 2008, 22:57
Yes i want to control it from the Parallax transmitter.

And yes the protocol seems to look like the X10 but there are some diffrents becouse the X10 funtion in PBP doesīt work.

Archangel
- 29th December 2008, 00:37
And the assembly code posted above . . where did it come from, and do you have the include file system.inc? the other one I think comes from MPASM.
The web pages I visited list these for sale in Swedish speaking countries only. I think these are over my head, sorry.

ardhuru
- 29th December 2008, 05:18
Seeing the actual original signal would make it much easier, right?

Use the original transmitter, and a compatible RF receiver; feed the output to the soundcard and capture this signal, and study it using any sound editor (Audacity / Goldwave) (more details on this technique at Dave Houston's site).

It would then be much easier to replicate this signal.

Regards,

Anand

dhouston
- 29th December 2008, 16:52
Here's the URL that Anand referred to...http://davehouston.org/learn.htmOnce you capture the codes you merely need to duplicate the timing with your transmitter.

Bruce
- 29th December 2008, 17:40
Try something like this.


DEFINE OSC 4

' Timing as described in NexaProtocol.txt
T CON 350 ' T = 350uS
T3 CON 1050 ' 3T
T32 CON 11200 ' 32T (Stop/Synch)

' Note we're using 1 VS X as shown in text
A1_ON CON %101100000000 ' 12-bit code for House/Unit A1 ON
A1_OFF CON %001100000000 ' 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

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

TX VAR PORTB.0 ' Connects to RF transmitter data in

LOW TX ' TX output idles low for RF carrier OFF

Main:
D_PACKET = A1_ON
GOSUB Send
PAUSE 5000
D_PACKET = A1_OFF
GOSUB Send
PAUSE 5000
GOTO Main

Send:
FOR LOOPS = 1 TO 4 ' send each packet 4 times
FOR INDEX = 0 TO 11 ' sends 12 bits per pass LSB 1st

HIGH TX ' The 1st half of a 0 or X bit period is the
PAUSEUS T ' same so no need to repeat this sequence inside
LOW TX ' the IF block
PAUSEUS T3

IF D_PACKET.0[INDEX]=1 THEN
HIGH TX ' send a 1 bit (1=X here)
PAUSEUS T3
LOW TX
PAUSEUS T
ELSE
HIGH TX ' send a 0 bit
PAUSEUS T
LOW TX
PAUSEUS T3
ENDIF
NEXT INDEX ' loop until all 12-bits sent

' Start of Stop/Synch period after each 12-bit packet
HIGH TX
PAUSEUS T
LOW TX
PAUSEUS T32
' End of Stop/Synch period

NEXT LOOPS ' send 4 packets per pass
RETURN

END
Can't say if this works or not since I don't have the receiver to play with, but it looks close
to what's shown in the NexaProtocol.txt timing diagram.

Fredrick
- 29th December 2008, 19:08
Hi Bruce

Thanx for the code, but it doesīt work so good but we are close now. :)

If i have the NEXA switch ON and let the PIC program running for 1 - 5 minutes the PIC turns the NEXA off, but never on again.

Here is more information for the NEXA and source code in some other language..
http://svn.telldus.com/svn/rf_ctrl/tellstick_2_6_driver/trunk/examples/
http://svn.telldus.com/svn/rf_ctrl/

I have read on a swedish forum that the original NEXA remote control sendīs 25 bits but there is only every second bit that contains the data, it sends a "zero" between every bit

http://elektronikforumet.com/forum/viewtopic.php?t=15147&highlight=nexa+proto*

Bruce
- 29th December 2008, 20:10
Hi Fredrick,

I think I goofed on the 3-bit unknown bits. Try changing to this;

A1_ON CON %111000000000 ' 12-bit code for House/Unit A1 ON
A1_OFF CON %011000000000 ' 12-bit code for House/Unit A1 OFF

dhouston
- 29th December 2008, 20:15
If you capture the codes as Anand suggested, I think you will find they are substantially different from what is described in NexaProtocol.txt. The Elro AB600 and Intertechno are among those that use the Arc Technology hardware. Those protocols agree with NexaProtocol.txt as far as A=0000, 1=0000, etc. but the wave shapes differ significantly from the shapes in NexaProtocol.txt. As I recall, the codes I have for Elro AB600 and Intertechno tested OK using a European Pronto (433.92MHz) to send the RF codes.

Fredrick
- 29th December 2008, 21:25
Hi Bruce
Iīm inprest of your programing skills, the code now works fine, better than the original NEXA remote control.

I have tryed diffrent housecodes and unit numbers and all works whit no problems.

The PIC can now control the NEXA switch from mutch longer rance then the original remote control.


Many thanx to you Bruce.

Bruce
- 30th December 2008, 00:01
Hi Fredrick,

Excellent. I'm glad you got it working, and happy to help.

We lucked-out having someone else do the dirty work for us...;o}

Dave & Anand both make good points above. If you have access to an O-Scope or can
build the sound card version, it makes the whole process a lot easier. And then you'll be
relatively sure your timing is correct.

I suspect this is what someone did when they wrote NexaProtocol.txt. You can probably
tweak the timing down to near perfect if you scope the data output pin on the NEXA
encoder IC in your transmitter.

At least now you have something to work with, and you can see how the timing from
NexaProtocol.txt was converted to a few simple PBP routines.

Cloning most encoders is relatively simple. The decoding part is a LOT more work.

Maybe you could post what you have now in the code examples section to share with
others?

Fredrick
- 30th December 2008, 15:59
I tryed to do the sound card version today byt no one of my 2 computers have a "Line in" or "Audio in" input, only a input with a microphone symbol on and that doesīt work.

I have now posted the code in the code exampel area now.

Fredrick
- 8th January 2009, 02:15
Is it posible to capture the RF signal with the PICkit2 tool "PICkit 2 Programmer Logic Tool Analyzer"?

If so i will buy the PICkit2 programmer (i need a new programmer with USB support.)

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805

ardhuru
- 8th January 2009, 05:44
I tryed to do the sound card version today byt no one of my 2 computers have a "Line in" or "Audio in" input, only a input with a microphone symbol on and that doesīt work.



You still might be able to use the mic input, if you attenuate the signal 1:1000 (a 100K and a 100ohm resistor divider, perhaps?). The waveform might not look picture perfect, but will surely be good enough for your purpose.

Alternately, if you have a serial port, you might want to look at Dante's infrax utility at http://www.geocities.com/tdanro/irman/irman.html

This would require you to build a small capture circuit, and be informed this does not work reliably with USB-to-serial interfaces. On a native serial port (or a PCI based additional one) it works quite brilliantly.

Regards,

Anand

Fredrick
- 8th January 2009, 10:09
Ok, i will try.

But i still need a new programmer so i hope that i can use the "Logic Tool" in Pickit2, or doesīt that work?

http://www.microchip.com/stellent/groups/devtools_sg/documents/devtools/~export/en023805~90~en006096~PressReleaseLayout/94839-4.png

dhouston
- 8th January 2009, 11:29
The mic input is tricky. Usually, it has +5V on one conductor to power electret microphones. Some are stereo.http://www.hobby-hour.com/electronics/computer_microphone.phpA logic analyzer might work but I've never tried one. The signals typically are between 1000Hz & 2000Hz.