RF Module Qualifier, CRC?
Hello to all,
I am using the Linx RXM & TXM LR (long range) modules. I was sending my data successfully until I change my qualifier to anything but 254. It operated very reliably with only an occasional hiccup (probably due to multipath around the metal buildings) at several hundred feet. I am sending an address (word) broken up into four pieces which is in bytes because I am using Manchester Encoding, then reconstructing and comparing the address in the receiver (constant) and also doing the same with the actual button pressed on the transmitter (key). I am not using USART because I still don't understand it after reading countless post on this forum and reading the datasheet.
So I am doing this on the transmitter:
serout2 serpin,16468,[$AA,$AA,$AA,$AA,$AA,synch,addA,addB,addC,addD,addA ,_
addB,addC,addD,key,key,key,key,key]
And this of course on the receiver:
SERIN2 serpin,16468,500,loop1,[wait(254),address1,address2,address3,address4,_
address5,address6,address7,address8,mydata1,mydata 2,mydata3,mydata4,mydata5]
Then I am decoding the address (manchester) then summing those up, ADD1=ADDA+ADDB<<4+ADDC<<8+ADDD<<12
comparing my address (constant) in the receiver to ADD1
then I check:
IF (address = add1) && (mydata1 == mydata2) && (mydata1 == mydata3) &&_
(mydata1 == mydata4) && (mydata1 == mydata5) && _
(MYDATA1 > 0) && (MYDATA2 > 0) && (MYDATA3 > 0) && (MYDATA4 > 0)&& _
(MYDATA5 > 0) THEN
Index2 = 1
For Index = 0 to 3
mydata.0[Index] = mydata1.0[Index2]
Index2 = Index2 + 2
Next Index
chksum2 = chksum2 + 1
chksum3 = 0
high rf
else
chksum2 = 0
chksum3 = chksum3 + 1
low rf
endif
if chksum2 >=3 then start
until chksum3 >= 1
ADD1=0
chksum2 = 0
chksum3 = 0
mydata = 0
I decode the mydata
then i repeat this three times by going back up to the SERIN2
using that if statement ,if chksum2 >=3 then start
then I assume all of mydata and the address match is good so I continue on to the output I want on.
Life seems good because each output is actually staying on as long as I am pressing the button on the transmitter and the output immediately goes off as soon as I release the button.
BUT:
It does not work if I change the qualifier to anything else, maybe this should not alarm me but I have been trying to figure out why.. call me a perfectionist,...after all I am sending a preamble to balance the data slicer,...right? And I have tried sending more $AA's and even $55's and a combination of those. I am aware of the rx module "noise" read many post on this forum,watched it on my scope and squelch is useless because of range limitations but mainly to stop the noise completey, squelch turn up full, no data is then received:(
ok, other than changing the qualifier this remote control works almost perfect, that may be an over statement . I have learned a lot from all of you out there, especially breaking down my code and understanding how it ticks.
After doing a search on checksums, found many articles about CRC and a dead link PDF about CRC but as I mentioned, it is a dead link. So any suggestions, preferably in lamen's terms how I can use CRC?
Many Thanks
ASM??? This is why I bought PicBasic Pro
Thanks for all the help but I was looking at Bruce's remote example,
http://www.picbasic.co.uk/forum/showthread.php?t=12554
I thought I could also use the timer portion that could be helpful to jump out of the SERIN2 if no data is received, But ASM??? This is why I bought PicBasic Pro...
From what I understand, very little, I need to add this to my code:
DEFINE NO_CLRWDT 1 ' Watchdog timer is disabled, so we don't need to reset it
DEFINE INTHAND RESET_VT ' Interrrupt on Timer1 overflow to reset outputs in 65.5mS
' if no serial data received in this time period
SYMBOL TMR1IF = PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
SYMBOL TMR1IE = PIE1.0 ' Timer1 interrupt enable bit
' Setup Timer1 for resets after ~65.5mS
T1CON = %00000000 ' Internal clock, 1:1 prescale, Timer1 off for now
TMR1L = 0
TMR1H = 0 ' Timer1 low & high bytes cleared
TMR1IF = 0 ' Clear Timer1 overflow flag before enabling interrupt
TMR1IE = 1 ' Enable Timer1 overflow interrupt
INTCON = %11000000 ' Global & peripheral ints enabled
chksum2 = 0 ' Clear match count
GOTO initialize ' Jump over int handler
ASM
RESET_VT
; Do interrupt stuff here
bcf T1CON,TMR1ON ; Stop Timer1
clrf TMR1L ; Clear low byte
clrf TMR1H ; Clear high byte
bcf PIR1,TMR1IF ; Clear Timer1 interrupt flag bit
DON'T KNOW ABOUT THE NEXT TWO LINES, SO I COMMENTED THOSE OUT. I BEEN READY THE DATASHEET FOR THE 16F628A, AND AT BEST GUESS TO CLEAR A SINGLE BIT ON PORTA, WHAT I SEEN IN THE DATASHEET REFERENCING WOULD BE PORTA, 1 OR PORT??1. DOESN'T COMPILE, HOW COULD I CLEAR PARTICULAR BITS HERE FOR PORTA AND PORTB?
;clrf portb ; Clear outputs on button release (or timeout)
;clrf porta ; Clear outputs on button release (or timeout)
bsf T1CON,TMR1ON ; Re-enable Timer1 before exiting interrupt handler
retfie ; Return from the interrupt
ENDASM
And then here is my serial in:
' Fire up Timer1 before entry to serial input routine
T1CON.0 = 1
' at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS) if no Synch byte
' and serial data arrive on time. SERIN2 timeout & label options
' are useless with a noisy RF receiver output - as noise continually
' resets the timeout period causing it to hang forever.
' Wait for Synch byte, then get new inbound data & checksum
SERIN2 serpin,16468,[wait(254),address1,address2,address3,address4,_
mydata1,mydata2,mydata3,mydata4,mydata5,mydata6]
T1CON.0 = 0 ' Stop Timer1 once we've received data
TMR1L = 0 ' Clear low byte
TMR1H = 0 ' Clear high byte
I compiled this with the rest of my code and it seems to be working fine, but am waiting for the gremlins to pop out.
Thanks a million for all the recommendations already.
I'm just the curious type...
I've been following this to see where it ended up... If you don't mind me asking; what kind of data are you transmitting? What speed?
I'm using the same modules for RF control of hardware.