Serin, really basic question

JPB33

Senior Member
I am getting confused using serin, but pleased I'm making progress with something new to me. From the basic commands it says "All processing stops until the new serial data byte is received" which I assume means that nothing happens (blocking?) until the new data is received, and a 0 doesn't count ?

When I view using sertxd the program only runs when a 1 is received from the tx which confirms that?

I was hoping to run the program continuously as I want to switch c.2 high by using another input although it is not receiving anything from the tx

Peter

Code:
 'RX below for high output on C.2 when b0 = 1 from RX (or pinc.3 high for setting??)  WORKING 11-5-18
;
	do 
	serin c.4, T2400, ("PETER:"), b0	  'Qualifier PETER added upper case important
	if b0 >= 1 then high C.2 		  'Checking b0 number, LED on and relay switched by C.2
	pause 300  low C.2  
	endif 					 
	sertxd("The value of b0 is ",#b0,13,10)
	loop
 

oracacle

Senior Member
a few things, what chip/chips?
what is sending the qualifier?
what happen when you use a less complex qualifier? I single letter for example. don't forget that you have a colon on the end of your qualifier which would have to be sent as well. also ensure that everything is running at the same clock speed and serial data rate/polarity.
 

AllyCat

Senior Member
Hi,

You haven't said which PICaxe you're using nor where the serial data is coming from (and I'm not clear about the exact problem) but personally when debugging/learning, I wouldn't use the qualifier facility of SERIN. Also maybe use only "printable" characters, e.g. b0 = "1" (ASCII 49) so it might be more obvious what is (or isn't) happening.

If you need the program to do other things whilst receiving the serial data, then you will probably need to use a timeout and/or HSERIN (hence the need to know if it's an X2 or M2). In either case it might be necessary to write a separate section of the program (subroutine) to identify the qualifier sequence of characters individually (depending on their speed of transmission, etc.), rather than rely on a qualifier within SERIN.

Cheers, Alan.
 

JPB33

Senior Member
Thanks for the replies. The idea is to operate a slave clock from a pendulum master clock using an HC-12 link. A pulse is generated every 30 secs from the master clock by monitoring the clock current which is about 350ma. After filtering its fed to the first 8M2 by an opto isolator, serial data out to an HC-12, received by another HC-12 and serial data into another 8M2 which drives the slave clock with a 300ms pulse every 30 secs. The good news is its working fine on the bench at present.

I added the qualifier as I thought it made the rf link less susceptible to any interference which would affect the time keeping but have no real knowledge of using one before. Perhaps its over the top/not needed?

Learning what was happening over sertxd I hoping to see the rx program looping as per the tx, so when it wasnt I then started seriously reading and concluded that it only loops when a 1 is received hence the original question.

I need to advance the slave clock only to set it to time at a rate of about 1hz but I'm not sure which way to go about at present as I've only just got the link working.

The complete program is attached this time, hope this answers the questions. Thanks Peter

'TX Master clock version


do
let b0 = pinc.4 'Pulse from master clock or press c.4 switch to operate
if b0 = 1 then
serout C.1, T2400, ("PETER:", b0) 'Qualifier PETER added upper case important
high c.2 'Checking b0 to put C.2 high to confirm b0 is 1
else
low c.2
endif
'sertxd("The value of b0 is ",#b0,13,10)
loop
;
;
;
;
; 'RX below for high output on C.2 when b0 = 1 from RX (or pinc.3 high for setting??) WORKING 11-5-18
;
do
serin c.4, T2400, ("PETER:"), b0 'Qualifier PETER added upper case important
if b0 >= 1 then
high C.2 'Checking b0 number, LED on and relay switched by C.2
pause 300
low C.2
endif
'sertxd("The value of b0 is ",#b0,13,10)
loop
 

geoff07

Senior Member
One way to use serin which avoids the blocking problem at the expense of another 08M2 is to have a dedicated chip receiving the input This chip then interrupts the main chip when there is something to say. The interrupt signal is a short serial output string preceded by a high or low on the same pin, to suit the chosen polarity. The interrupt service routine is triggered by the high/low and then reads the serial input on the same pin, setting any variables or flags as necessary. The code in the dedicated chip is very simple, and the main chip can do what it pleases without being blocked. It works well for IR input as sell as serial data.
 

JPB33

Senior Member
That's a good idea, thanks. I have a number of 8M2 smd boards I had made still in stock so quite feasible.

I'm not sure of the overall timing using an HC-12 link but the input pulse lasts for 95ms and wondered if there was a way to record/check how many 1's had made it over the link in that time?

In my inexperience I was trying to keep the code simple in case the 8M2 was off doing something else when the pulse was arriving due to the half duplex timing.


IMG_2503.JPG
 

AllyCat

Senior Member
Hi,

... another 8M2 which drives the slave clock with a 300ms pulse every 30 secs.
You can't assume that every pulse will be reliably received over a 434 MHz radio link, so the receiving program will need some form of "flywheel" operation. For example it might wait for 29 seconds and then "listen" for two seconds. If a pulse is detected, it (re)times the clock accordingly, but if not it generates a pulse anyway. That should also solve the blocking issue and highlights that an overly strong qualifier may itself produce "errors" (missing pulses).

The program would also need to count the number of (consecutive) missing pulses and if there are too many then gradually increase the "search window" until a pulse is found. But again wait for at least two pulses to have the correct spacing before re-synchronising the slave clock.

Cheers, Alan.
 

JPB33

Senior Member
Thanks Alan,

Good ideas which would overcome a lot of the doubts of "is it showing the right time"

Cannot think of a way to get round serin, is there a better way to receive serial data without the blocking effect so it could be " live" only for a few seconds as part of the missing pulse check?

Left on test its keeping time with the master even with the original qualifier so nothing missed up to now.

Peter
 

AllyCat

Senior Member
Hi,

You could use a timeout within SERIN to terminate the blocking if no character is received within the expected time: e.g. SERIN [2000 , nopulse] , ..... Either detect when b0 is unchanged, or jump to the timeout address label.

Alternatively you could use HSERIN but there are quite a few "complications" with an 08M2: It can only use "P" polarity (not a problem if you are in control of the transmitted data) and the receive buffer is only two bytes long (at most) so the program needs to receive the bytes "on the fly", perhaps by using an interrupt. Some of these issues are discussed in my thread entitled "Problems using HSERIN with an 08M2" but that included even more complications because I needed to receive N polarity, and specifically on the Serial Programming input pin.

Cheers, Alan.
 
Top