PDA

View Full Version : Do I need a pause?



tazntex
- 20th August 2008, 03:18
Hello,
while sending data from pic to pic (16F628A) through an rf link,Linx rxm-418-lc modules, all but one thing is working good. I have also done a hard wired connection from pic to pic with the same problem. I am using the checksum that Bruce recommended and I am using manchester. I am making an output on portb come on with the button pressed and with the button on the tx released it goes off. However, frequently an output stays on. Press the button again and it will clear. This is the clip from my program:

IF mydata1=%01011001 THEN PAUSE 10
IF mydata1=%01011001 THEN
HIGH 1
ELSE
LOW 1
ENDIF

goto loop

I added a PAUSE 50 after LOW 1 but no change.

When I go back to the main loop I've added mydata1=%00000000 before going to the SERIN to make sure that the previously received mydata1 is clear instead of using CLEAR although I've tried that to.

Does anyone have any suggestions?

By the way, I have checked the tx side to make sure the button was closed, even listened to the datastream on my service monitor.

Archangel
- 20th August 2008, 05:19
Hi Tazntex,
I really do not get what you are trying to do here with this:


IF mydata1=%01011001 THEN PAUSE 10
IF mydata1=%01011001 THEN

Here is my thinking, you have received the data, done deal, stored it in a variable named mydata, and now you expect it to somehow bounce? Bounce delays are for mechanical switches. I do not see it hurts nor do I see any benefit to including it. It just slows down and bloats your code. Since this is another new thread, refresh us on what this code does not do and what it does do. As written it asks a true / false question, does mydata = 01011001, if yes it pauses 10 and asks again, if true then it procedes to turn 1 high if false it turns 1 low. If mydata is not 01011001 it will always execute the else. If you have a pin to spare why not send a debug or serout with the contents of mydata to a terminal or serial lcd and be sure of the contents?

tazntex
- 20th August 2008, 12:59
Thanks for the reply. I see your point about checking twice but I just wanted to check twice, the first brings me into this and the second does the if/then. I've taken this out and now I have:

IF mydata1=%01011001 THEN
HIGH 1
ELSE
LOW 1
ENDIF

I had a previous previous thread "else" which you help me on and it is all working but like I said before, I press a button on the tx ,the outputs being portb.0-6 on the rx , the momentary outputs 1-4 come on and when I release the button they go off. Every so often one stays on, check the selected output pin with scope and it is high, but if I press and release the same button for the output again it will go back low. I do not have a serial LCD but you mentioned using terminal, what do you mean using a PC??? If so, would you tell me how ?

Thanks

Archangel
- 20th August 2008, 22:41
Thanks for the reply. I see your point about checking twice but I just wanted to check twice, the first brings me into this and the second does the if/then. I've taken this out and now I have:

IF mydata1=%01011001 THEN
HIGH 1
ELSE
LOW 1
ENDIF

I had a previous previous thread "else" which you help me on and it is all working but like I said before, I press a button on the tx ,the outputs being portb.0-6 on the rx , the momentary outputs 1-4 come on and when I release the button they go off. Every so often one stays on, check the selected output pin with scope and it is high, but if I press and release the same button for the output again it will go back low. I do not have a serial LCD but you mentioned using terminal, what do you mean using a PC??? If so, would you tell me how ?

Thanks
download realterm, works well, use a max 232 if needed, some nice kits on ebay for cheap,gets you a PCB, connector, caps and the max chip. Or roll your own, use the code from post 16 of this thread:http://www.picbasic.co.uk/forum/showthread.php?t=4972 here is an ebay seller http://cgi.ebay.com/RS232-Serial-UART-to-TTL-Converter-Adapter-Kit-PIC-MCU_W0QQitemZ260274810796QQihZ016QQcategoryZ4663QQ ssPageNameZWDVWQQrdZ1QQcmdZViewItem
and another http://cgi.ebay.com/MAX232-RS232-Serial-to-TTL-Converter-Board-Adapter_W0QQitemZ310075613286QQihZ021QQcategoryZ46 61QQssPageNameZWDVWQQrdZ1QQcmdZViewItem

Archangel
- 20th August 2008, 22:59
Thanks for the reply. I see your point about checking twice but I just wanted to check twice, the first brings me into this and the second does the if/then. I've taken this out and now I have:

IF mydata1=%01011001 THEN
HIGH 1
ELSE
LOW 1
ENDIF

I had a previous previous thread "else" which you help me on and it is all working but like I said before, I press a button on the tx ,the outputs being portb.0-6 on the rx , the momentary outputs 1-4 come on and when I release the button they go off. Every so often one stays on, check the selected output pin with scope and it is high, but if I press and release the same button for the output again it will go back low. So if I understand correctly, you only want the lights on <b>WHILE</b> receiving mydata=%01011001
HIGH 1 otherwise you<b> WEND</b> want it to stay Low, Correct ?

tazntex
- 21st August 2008, 01:54
"So if I understand correctly, you only want the lights on WHILE receiving mydata=%01011001
HIGH 1 otherwise you WEND want it to stay Low, Correct?"

yes that is correct.

One thing though, I checked the circuit to make sure that is was the processor keep the led on and the output pin is High, while checking the pin I just wanted to make sure that the voltage coming from the output was correct, it is. Looking at the same pin with the scope there is some noise, so I switched from a switch mode power supply to a gel cell (12v). I am using a 7805 regulator with 10uf electrolytic on the input and .01 disc on the regulators output to ground. The noise is still there. Perhaps a cap between the VCC and Vss of the Pic will clear up the rest. I have change processors on both the tx and rx side to rule out a defective one just in case static damage them. On the 4mhz crystal I am using 33pf caps to ground.

I will explore realterm tommorrow, thanks for that info.

Thanks again

Archangel
- 21st August 2008, 06:44
Try something like this:


IF mydata1=%01011001 THEN
WHILE mydata1=%01011001
HIGH 1
WEND
ELSE
LOW 1
ENDIF

tazntex
- 22nd August 2008, 12:32
Thanks Joe for the example, I did try it but it locks up, let me explain. On the receiver I have read and reread what I have written, but I added a datagood LED that way I can see what is going on the the variable mydata1. When the momentary output stays on, datagood is also on so I don't think the mydata1 is %00000000 so what is your opinion. I removed the other outputs from the program to reduce the space here. Here is the receiver:
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_OFF
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ DEVICE pic16F628a, PROTECT_OFF
DEFINE OSC 4
mydata1 VAR byte
mydata2 var byte
address1 var byte
address2 var byte
checksum var byte
chk_sum var byte
'do I need vrcon=0 ?
datagood VAR porta.2
serpin VAR porta.1 'serial input pin
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
PAUSE 50

loop:
mydata1=%00000000
gosub loop1
CheckSum = (address1 + address2)
CheckSum = CheckSum + (mydata1 + mydata2)
IF checksum != chk_sum THEN loop
IF mydata1 != mydata2 THEN loop
IF address1 != address2 THEN loop

IF (mydata1>0) && (checksum = chk_sum) THEN
datagood = 1
else
datagood = 0
endif
if mydata1=%01010110 then loop2
if mydata1=%10101111 then loop2
if portb.0=1 then loop3
goto loop

loop2:
if mydata1=%10101111 then high 0 'master relay turn on
pause 50

if mydata1=%01010110 then portb=0 'master relay turn off
pause 50
goto loop

loop3:
if mydata1=%01011001 then
high 1 'portb.1 is on
else
low 1 'portb.1 is off
endif
GOTO loop


loop1:
SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return

And here is the tx:
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_ON
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ DEVICE pic16F628a, PROTECT_OFF
define osc 4
CMCON=%00000111
trisb = %11111111
trisa = %00010111
chk_sum var byte
dgood var porta.2
serpin var porta.3
nokey con %11111111
synch con 254
address con %00000001
keyin var portb
keydata var byte
E VAR PORTB.0
D VAR PORTB.1
G VAR PORTB.2
A VAR PORTB.3
B VAR PORTB.4
C VAR PORTB.5
F VAR PORTB.6
na VAR PORTB.7
PreAmble CON $A5 ' 10100101 preamble
findkey:
if keyin != nokey then pressed
goto findkey
pressed:
if A = 0 and B = 0 then p3
if A = 0 then p1
if B = 0 then p2
goto findkey

p1:
if A = 0 then keydata = %01010110
gosub validate
gosub transmit
goto findkey

p2:
if B = 0 then keydata = %01011001
gosub validate
gosub transmit
pause 250
if B = 1 then pause 10
if B = 1 then keydata=%00000000
gosub validate
gosub transmit
goto findkey

p3:
if A = 0 && B = 0 then keydata = %10101111
gosub validate
gosub transmit
goto findkey
validate:
chk_sum = (address + address)
chk_sum = chk_sum + (keydata + keydata)
return
transmit:
serout serpin,N2400,[$55,$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,$AA,sy nch,address,address,keydata,keydata,chk_sum]
return

Thanks again

tazntex
- 25th August 2008, 15:05
I have looked over this for the last two days and when the output is stuck on the led I have for datagood is on so this tells me that mydata1 is not clearing. I've search this forum to see if anyone else has or had this kind of problem but could not find any information. Does anyone have any suggestions? Thank you

Dave
- 25th August 2008, 17:43
tazntex, What do you mean by this line?, if mydata1=%10101111 then high 0 'master relay turn on. What is "high 0"?

Dave Purola,
N8NTA

tazntex
- 25th August 2008, 17:57
tazntex, What do you mean by this line?, if mydata1=%10101111 then high 0 'master relay turn on. What is "high 0"?

Good afternoon, Dave, mydata1=%10101111 is the data sent via the transmitter to the receiver, HIGH 0 is portb.0.

'73 Dave, thanks for the reply.

tazntex
- 26th August 2008, 01:36
I've added a 250ms pause after high one and it seemed to be a little better, then I add a 500ms pause and it does not stick so much although this is not a cure.
oop3:
if mydata1=%01011001 then
high 1 'portb.1 is on
pause 500
else
low 1 'portb.1 is off
endif
GOTO loop

Loop2 does fine its just noticable in loop3. I thought there might me something with PICBASIC PRO 2.50, i've already installed the A patch and went there today and they have a 2.50b patch. I didn't see anything that might affect what I am trying to accomplish here. I know there are a lot of people here on this forum with much, much more experience with microcontrollers than I'll ever have. I have search time and again to see if anyone has had similar problems but have not not found anything revelant to this type. Certainly someone sees what I have missed. Thank you

Dave
- 26th August 2008, 12:19
tazntex, That is not the way you would access a port pin (atleast I have never done it that way), You should access it by the way of "portb.0" or referencing everything from porta.0. Just saying "HIGH 0" would lend me to believe it would be accessing porta.0. Also I see you are turning off all of port b by the syntax "if mydata1=%01010110 then portb=0 'master relay turn off". Is this what you want to do? Why not just use an alias for the relay output like "Relay var Portb.0". Then all you need to do is use the syntax "Relay = 0 or Relay = 1" I would investigate your use of the port syntax before I placed any pauses into the code....

Dave Purola,
N8NTA

tazntex
- 26th August 2008, 12:44
Thank you Dave, an excellant suggestion. I will update my program to reflect on your advice. I will report back on how this worked out.

73

tazntex
- 26th August 2008, 13:33
Ok, I have changed my program as recommend before but it is still doing the same. As I said earlier everything works the way I planned it BUT, every so often about the fourth or fifth time I press and release the tx button, the output selected will stay on instead of going back off and by datagood led is still lit so I am convinced mydata1 has not cleared. Like I said everything works great except when that little gremlin decides to pop up.

I have most likely spent more time on this than most people so I may take my sons advice and fix it, with a hammer:)

Dave
- 26th August 2008, 16:59
Tazntex , Can I please see a listing of the modified code?

Dave Purola,
N8NTA

tazntex
- 26th August 2008, 18:06
Here is the revision Dave,
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_OFF
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ DEVICE pic16F628a, PROTECT_OFF
DEFINE OSC 4
mydata1 VAR byte
mydata2 var byte
address1 var byte
address2 var byte
checksum var byte
chk_sum var byte
master var portb.0
vacuum var portb.1
datagood VAR porta.2
serpin VAR porta.1 'serial input pin
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
PAUSE 50

loop:
mydata1=%00000000
gosub loop1
CheckSum = (address1 + address2)
CheckSum = CheckSum + (mydata1 + mydata2)
IF checksum != chk_sum THEN loop
IF mydata1 != mydata2 THEN loop
IF address1 != address2 THEN loop

IF (mydata1>0) && (checksum = chk_sum) THEN
datagood = 1 'mydata1 > 0 so I know whether or not mydata1 has returned to %00000000 if 1 then my led will come on
else
datagood = 0 'If mydata1 is %00000000 then var mydata1 is 0, my led is off
endif
if mydata1=%01010110 then loop2
if mydata1=%10101111 then loop2
if portb.0=1 then loop3
goto loop

loop2:
if mydata1=%10101111 then master=1 'master relay turn on
pause 50

if mydata1=%01010110 then master=0 'master relay turn off
pause 50
goto loop

loop3:
if mydata1=%01011001 then
vacuum=1 'portb.1 is on
else
vacuum=0 'portb.1 is off
endif
GOTO loop


loop1:
SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return

tazntex
- 28th August 2008, 20:30
Not much has changed since my last posting, I haven't taken the hammer out of the toolbox just yet. The rf modules are capable of 5000bps so I did move up from 2400. I've been over under and through this forum, and saw a post where bruce had use a 100k to pull down the data, if I read this correctly, line coming in to reduce noise on the input. I have monitored my data on the serial input of the 628a, looks pretty clean. I haven't had any luck getting rid of the little gremlin who pops up every now then and holds the output pin high. Anyhow I am open to criticism, constructive preferred:)

Archangel
- 28th August 2008, 20:46
Hi Taz.
I see you have 2 ports as inputs, what is connected to them? PortB.7, I see no reference to in code, possibly my bad eyesight, but if open as input might allow "gremlins" to leak in.

mackrackit
- 28th August 2008, 21:28
address con %00000001
This equals 1

chk_sum = (address + address)
chk_sum = 2

if A = 0 && B = 0 then keydata = %10101111
keydata = 175

chk_sum = chk_sum + (keydata + keydata)
chk_sum = 2 + 175 + 175

chk_sum = 352

chk_sum var byte
byte = 0 to 255

Maybe try WORD sized variables.

Or maybe I am missing something

tazntex
- 29th August 2008, 03:34
Hello again Dave, you have a good point however I am using Bruce's idea for validating the in coming data. It is my understanding that the checksum will overflow which should not be a problem. I've been using it and that part doesn't seem to be the problem however I will experiment with it to see. I hope your right. Thanks Dave and 73

mackrackit
- 29th August 2008, 04:32
OVERFLOW...Yep I was missing something.
I will keep looking at it.

Do not get the hammer yet.