Sertxd & strange Readtemp readings when servo command used

Peter-C

Member
I have been troubled with a simple circuit that uses an 8M to monitor two ds18b20 temperature probes and operate a servo.
When I use sertxd to see the temperatures the program runs smoothly, but as soon as I rem the sertxd command out I start to get erratic readings out of the probes. (Sertxd creates a flutter on the servo so needs removing)
This happens even when the servo is disconnected so isn't a straight case of noise.
I have found a solution without understanding why this works and post this in the hope it may be useful to somebody in the future.
The servo is on 'out 0'. After each servo command I have added a low 0 and the problem magically goes away. I spotted that the servo pin stays high once called in a program and pushing it low seems to eradicate the spurious readings on the temp probes.
Can anyone suggest why this solution works?
 

Technical

Technical Support
Staff member
You've got a mixed up setup there, so will get strange interactions between commands.

The main issue is using servo on output 0.
As this is also the sertxd (and debug and download serial) pin, you will get both servo background pulses and sertxd serial pulses all mixed up together on the same pin, which is not ideal.

A 'low 0' actually stops the servo pulses completely, which is probably not what you wanted (servos need repeated signals to work reliably).

Have you tried moving the servo onto a different output?
 

Peter-C

Member
Sorry, a correction: I actually have the servo on out 2, not 0 as previously stated. I have a buzzer attached to 0, which of course is shared with serout.
 

Technical

Technical Support
Staff member
A servo pin does not 'stay high' after use, it provides a small positioning pulse in the background every 20ms or so whilst other commands run. It could be your setup is sensitive to noise etc created by these background pulses - how is your supply decoupled etc.

Using a 'low' command stops this pulse stream.
 

Peter-C

Member
Thanks Technical, I had read the advice to run Picaxe and servo on separate power supplies, with a shared Negative. However, my point was that this behaviour happens even when the servo is completely disconnected, so unless the 'noise' is coming from the unconnected servo signal wire I don't understand why it would upset the circuit?
 

Peter-C

Member
Thanks for your interest BB. Here is the code. I also found the same problem using a 14m, with the same solution.
Code:
'watchdog on 8M chip to monitor Coll min temp, Base overheat
'Red LED powered from power supply
'If risk freezing, maybe main controller ,pump or power is down, so open base to drain and circulate.
'If risk overheat then start sound alarm at 80C and vent at 85C, still alarming throughout.
servo 2,200
low 2

Main:
Readtemp 1, b0              'solar temp reading to var b0 
Readtemp 4, b1              'tank base temp reading to var b1
sound 0,(100,5)
pause 20
sound 0,(100,5)
'sertxd ("Coll= ",#b0,"  Base= ",#b1,cr,lf) 'NB. causes pulse sound if left inprog as 0 is shared with sounder
if b0<3 then                ' if appearing to freeze then:
gosub freezing
else   
end if
if b1>80 then      '*** set max temp before dumping*******
gosub heatdump
else end if
if b0>95 then  'if collector temp indicates pump has stopped
gosub heatdump
else end if

goto main                  'start program from the top

freezing:
let b3=b3+1
sound 0,(100,50)                        'short buzz sound
if b0<2 then     'if below temp and at risk imminently then....
servo 2, 160     'open the valve slightly to flush panel from tank base 
pause 5000       'allow water to flow for X secs  *** reset X after trial *******
servo 2,200      'close again and restart main to test temp again
pause 2000
else end if
return

heatdump:
let b4=b4+1
sound 0,(100,300)           'double buzz between 80 and 85 before dumping
pause 700          'pause short urgent buzz
sound 0,(100,300)           'buzzer on between 80 and 85 before dumping

if b1>85 then      'if temp gain increases from 80 to 85 then dump..
servo 2, 140       'open the valve 
pause 10000        'allow water to flow for X secs  *** reset X to 45 secs??*******
servo 2,200        'close again and restart main to test temp again
pause 2000
else end if
return
 

hippy

Ex-Staff (retired)
There does appear to be some unwanted interaction between SERVO and READTEMP in some circumstances which we will investigate further.

Do
Servo 2,140
ReadTemp 4,b0
SerTxd(#b0," ")
Pause 500
Loop
 

BeanieBots

Moderator
OK, I'll not bother testing then.
Did suspect (from the post) that there might be a conflict between servo and the one-wire timing which is why I offered to try it. Never tried the two together before.
 
Top