PDA

View Full Version : SERIN Timeout



George
- 19th March 2007, 04:06
I'm trying to write some code for a receiver which really was just going to be a timing loop - the sender unit sends time and an on or off, the receiver then should start counting down the time if the sender has told it to run - so I was going to do a timeout and a small timing loop outside of the SERIN command - however it seems the timeout isn't working - prolly due to the fact the input from the RF module is constantly sending noise down the line.

I think my only other way is to interupt out using a timer - but not realy sure how to do it and I have a bit of a phobia about interupts - have done quite a bit of searching on here but still find it a bit of a struggle to understand what everything means -

Does anyone know a simple way I can do what I'm trying to achieve?

Thanks

@ DEVICE PIC16F676, INTRC_OSC_NOCLKOUT, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF


Define OSCCAL_1K 1
DEFINE OSC 4

TRISA = %001000
TRISC = %000000


ANSEL = 0 'disable analog
T1CON = %00000100
VRCON = 0 ' A/D Voltage reference disabled
CMCON = 7 'Disable comparitor

timesw var PortA.5
gosw var PortA.3
stopsw var PortA.4
timeset var byte
display var byte
'time var word
b0 var byte
b1 var bit
b2 var byte

clear
timeset = 1
PortA = 0
PortC = 0

Begin: 'start sequence

display = (1 << b0) - 1
PORTC = display
pause 100
if b0 < 7 then
b0 = b0 + 1
goto begin
Else
Pause 1000
b0 = 0
portC = b0
Endif

Start:

serin PORTA.3,0,100,time,["READY"],timeset,b1 'Read receiver
gosub disply

time:
b2 = b2 + 1
if b2 > 200 and timeset > 0 and b1 = 1 then
timeset = timeset - 1
b2 = 0
endif
if timeset = 0 then b1 = 0
goto start




disply:

display = (1 << timeset) 'Set display to be bar type
PORTC = display 'output LEDs
PORTA.0 = b1

return

mpardinho
- 19th March 2007, 15:33
Start:

serin PORTA.3,0,100,time,["READY"],timeset,b1 'Read receiver
gosub disply

time:
b2 = b2 + 1
if b2 > 200 and timeset > 0 and b1 = 1 then
timeset = timeset - 1
b2 = 0
endif
if timeset = 0 then b1 = 0
goto start




try

Start:

'serin PORTA.3,0,100,time,["READY"],timeset,b1 'Read receiver
serin PORTA.3, 0, 100, time, next, ["READY"], timeset, b1 'Read receiver
gosub disply

time:
b2 = b2 + 1
if b2 > 200 and timeset > 0 and b1 = 1 then
timeset = timeset - 1
b2 = 0
endif
if timeset = 0 then b1 = 0

next:
goto start

George
- 19th March 2007, 20:10
Thanks - but even with the next renamed (cos next is a reserved word) it comes up with compilation errors cos there are 3 things on the timeout label where there should only be 2. The issue is, because it's a radio connection there is static whenever there is not a radio transmission, PBP sees this as potential data, and if not met by the qualifier then it just loops to the beginning of the command again - so long as it's seeing these pin fluctuations and doing this loop, it will not timeout.

I also figure that I can't use the ON INTERUPT command - because that only works when a PBP statement is complete and the SERIN command will never complete if it doesn't get a qualifier and gets RF staic noise through all the time.

BTW I forgot to mention the PIC I'm using is a PIC16F676

George
- 21st March 2007, 22:22
I've now tried DT's interupt files - however I get a million errors - ie. not being able to fit variables - sigh
ERROR: Variable wsave3 position request 416 beyond RAM_END 95.
ERROR: Variable wsave2 position request 288 beyond RAM_END 95.
ERROR: Variable wsave1 position request 160 beyond RAM_END 95.
that sort of thing

Any advice on how to do this would be greatly appreciated - I've just about pulled all my hair out!

How do you do an interrupt in ASM for this simply so that it will come out of the serin command - increment a timing incrementation and go back to the serial loop it's stuck in?

Thanks in advance

skimask
- 21st March 2007, 23:35
I also figure that I can't use the ON INTERUPT command - because that only works when a PBP statement is complete and the SERIN command will never complete if it doesn't get a qualifier and gets RF staic noise through all the time.

BTW I forgot to mention the PIC I'm using is a PIC16F676

Use a timeout just a bit longer than the length of the start bit at your baud rate and put it in a loop. If you get a SOLID start bit, then all should be well...if the start bit is flakely, it should timeout. That should let you use ON INTERRUPT alright, should is the key word :)

Also, can you rewrite the code a bit on the sending unit? I'm thinking maybe some qualifying bytes sent before the actual data is sent might come in handy in a case like this. The qualifying bytes get a short timeout, the data gets a longer timeout, in seperate SERIN statements.

George
- 21st March 2007, 23:52
Hey skimask, Took me a while to understand what you are saying (am a bit slow this far into the week). I think what you are saying would work, tho I'm concerned tho that it would be a bit intermittant as far as timing goes - as your timing may be dependant on what's coming through the airwaves at the time.

Currently I'm thinking about building a squelch circuit which will no doubt limit my range but should enable the serin timeout to work - tho i do think the ideal would be an assembly interupt.

skimask
- 21st March 2007, 23:58
Hey skimask, Took me a while to understand what you are saying (am a bit slow this far into the week). I think what you are saying would work, tho I'm concerned tho that it would be a bit intermittant as far as timing goes - as your timing may be dependant on what's coming through the airwaves at the time.

Currently I'm thinking about building a squelch circuit which will no doubt limit my range but should enable the serin timeout to work - tho i do think the ideal would be an assembly interupt.

Again, do you have access to the data sending unit? Can you change the code in that? I'll thinking you could eliminate the squelch circuit by just adding a load of preamble bytes before the data...
Otherwise...a squelch circuit probably wouldn't work either since you have to break squelch, which takes time, which takes bytes, and so on...
I'm still thinking on this one...

George
- 22nd March 2007, 00:56
Yeah, have written the code for the sender so can change that to whatever, I've got "READY" as my qualifier. I'm going to try your idea about using a very short timeout to see how it works 1-2ms I'm thinking at the moment - will be interesting if nothing else to see what effect it has on the time keeping. Thanks for all yr input so far

skimask
- 22nd March 2007, 01:00
Yeah, have written the code for the sender so can change that to whatever, I've got "READY" as my qualifier. I'm going to try your idea about using a very short timeout to see how it works 1-2ms I'm thinking at the moment - will be interesting if nothing else to see what effect it has on the time keeping. Thanks for all yr input so far

I just saw that your baud rate is 2400. That's .416 us per bit, a start bit is generally 1.5 bit lengths, which gives you .625us for a start bit. Timeout is limited to 1 ms minimum, it might work, it might not. You might end up waiting for READY, but only able to receive "EADY". I would think if you sent a string of qualifiers (bunch of $AA55's or the like), say 10 of them, wait until you have a solid 5 received, then you should be able to dispense with any timeouts because you signal is strong enough to get the qual's.

George
- 22nd March 2007, 02:57
I've got a string of 5 $AA preceeeding the READY, and haven't seemed to have much of a problem getting the data to the receiver - i send the data 5 times on a transmission to make fairly sure it gets through. I've got the timeout at 1ms toggling an LED to indicate to me when it's exiting out of the serin command - it's way random tho can tripout every half second or every 10 minutes. The issue I have is not so much transmitting the data - it's when no data is being transmitted

George
- 22nd March 2007, 03:24
Oh the other thing I forgot to mention is that the RF modules r AM so there is alot of static when there is no carrier

skimask
- 22nd March 2007, 04:06
Oh the other thing I forgot to mention is that the RF modules r AM so there is alot of static when there is no carrier

ooofff...AM...that hurts :)
Still, send the data multiple times, add a checksum to the data, receive the data successfully X number of times, blah blah blah... Should be too much of a problem even with all that random AM static noise.
But you're still on the problem of sitting in a SERIN loop waiting for solid data while you still need to do other stuff, correct? How about a 2nd PIC (say a 16F688) that just sits there and waits for data, and when it gets good data, it fires it out a different serial port to the 'real' PIC, which doesn't have to worry about garbage data... Heck, might even be a good spot for a 10F202 to handle that job!!!

George
- 22nd March 2007, 20:19
Yah - I wanted to avoid something like that due to complexity - plus haven't had any luck with PBP and 10F202 (PBP uses up too many variables - tho for a simple job like that I'm sure it would work) electronically it's prolly simpler for me to build a squelch. I might do a new post with a title more reflecting ASM interupts - thanks for all yr input

mister_e
- 22nd March 2007, 22:39
unless your module have a RSS output, send it to the trash can.

Archangel
- 23rd March 2007, 05:27
Oh the other thing I forgot to mention is that the RF modules r AM so there is alot of static when there is no carrier
Can you not install a squelch circuit on the receiver?

mister_e
- 23rd March 2007, 15:06
Or feed it to a PIC comparator input

Sorry if this sounds like a PMS reply ;) but we still don't know which RF module you're using.