basic temperature ajustment

novolts

Senior Member
Hi Guys
I have been reading up on readtemp and readdac
I have constructed a couple of bread board circuits using the DS18B20 and the the circuits have worked the way I wanted them to

ie readtemp B.0,w1
if readtemp >= 55 then
high C.0
end if

What I would like to do is use a pot to give another 10oC



so I could vary the temp between 55 and 65oC
so readdac B.1,w2
so if I used
w2=w2*10
w2=w2/1002

so between 0 and 10k on a pot I am getting a value between 0 and 10 as the pot is ajusted

and added w2 to w1 am I on the right lines
thanks
novolts
 

AllyCat

Senior Member
Hi,

Firstly, you need to use readadc. readdac would read the DAC output signal.

Assuming you're connecting the pot directly across the PICaxe supply rails (and wiper to b.1), then readadc b.1,w2 will input a value between 0 and 255 (so a word variable is not strictly necessary). Then simply divide w2 by 25 to give a value between 0 and 10 and add that to the temperature (in degress C) supplied by the DS18B20.

Cheers, Alan.
 

premelec

Senior Member
@AllyCat I notice there's a READDAC10 command - what's up with that? PICAXE DACS are well below 8 bits - is there a finer DAC available? [I've used external multi channel 8 bit DACs with good results].
 

hippy

Technical Support
Staff member
@AllyCat I notice there's a READDAC10 command - what's up with that? PICAXE DACS are well below 8 bits - is there a finer DAC available?
No, there is only a single DAC controller and output. The READDAC and READDAC10 commands simply read that analogue level with different resolutions.
 

AllyCat

Senior Member
Hi premelec,

Yes, the DAC has only 5 bit resolution, i.e. 32 levels (or strictly 33), but it has a high output impedance (it's basically a 160 kohms pot) so the actual output voltage on the pin can be quite different to the "set" level. In some cases you might even set the "wiper" to the centre (daclevel 16) and use the "DAC output" as an analogue input. ;)

Or with a POKESFR to the DAC control register you can even partially disconnect the internal "DAC Pot" from the supply rails. Then use the SO "Output Only" pin (in most M2s) even more as another analogue input.

Cheers, Alan.
 

novolts

Senior Member
H Guys
thanks for the replies to my thread last month sorry in advance for the next question


readtemp C.4,w1
if w1<56 then ;B.5 goes low when temperature reaches 55oC
high B.5
endif

readadc C.0,w2 ;pot value is between 0 to 10
w2=w2/25

I want to add w1 to w2 to give allow an increase of 56 to 65oC
my next line was going to be w3 =w1+w2
i dont know what other basic commands to use , to say rather than B.5 going low at 55oC it goes low at 60oC when the pot is say approx mid way
I know how to get B.5 to go low by using fixed values ie say 54oC
What I want to be able to do is have B.5 going low between 55 and 65oC depending on the position of the pot
I don't want to be ungreatfull but I don't want any kind member of the forum giving me the code but would appreciate a point in the right direction
many thanks to all
kind regards novots
 

AllyCat

Senior Member
Hi,

In most cases you can use either a (constant) "number" (e.g. 56) or a "variable" (w1 , b1, etc.) in PICaxe expressions.

So in your case, you should be able to read an analogue value into a variable such as w4, apply suitable scaling/offsetting and then use (for example) IF W1 < W4 THEN....etc. Also note that in the example you've given, byte variables would probably be large enough.

Cheers, Alan.
 

novolts

Senior Member
AllyCat Thanks for the reply

I have come up with the code below
It would appear to work, comments from forum members would be great fully appreciated

#picaxe 14M2

main:

readadc C.0,w2 ;10k pot connected to pin C.0
w2=w2/25

readtemp C.4,w3 ;DS18B20 connected to pin C.4
if w3<50 then
high b.4
endif

w4=w2+w3
w5=w4+1

if w5>w4 then
high b.4
endif
if w5>60 then
low b.4
endif

goto main

thanks to all

novolts
 

BeanieBots

Moderator
The use of symbols would make it much easier to follow.
Then you could have lines like this:-

ReadTemp DS18B20,Temperature
If Temperature < Setpoint then
High Heater
EndIf
 

novolts

Senior Member
BeanieBots
Thanks for the reply I will try and use symbols I just wanted to make sure I was on the right track
To get as far as have has been a long learning block but very enjoyable

kind regards
novolts
 

hippy

Technical Support
Staff member
w5=w4+1
if w5>w4 then
high b.4
endif
That is always going to set B.4 high, w5 will always be greater than w4.

Also your code and maths seems very convoluted, you seem to be adding your temperature pot setting to the actual temperature read which I don't understand.

The following (untested) will allow a pot to set the temperature wanted to a value between POT_MIN and POT_MAX, then compare the actual temperature to that ...

Code:
#Picaxe 14M2

Symbol temperature = b0
Symbol tempWanted  = b1

Symbol POT_MIN     = 55
Symbol POT_MAX     = 65

Do

  ReadTemp C.4, temperature
 
  ReadAdc C.0, tempWanted
  tempWanted = POT_MAX - POT_MIN * tempWanted / 255 + POT_MIN

  If temperature >= tempWanted Then
    High B.4
  Else
    Low B.4
  End If

Loop
 
Last edited:

novolts

Senior Member
hippy
Thank you
" temperature pot setting to the actual temperature" is what I wanted to achieve
On the site where I am based as a maintenance electrician I have a water heater where I don't want the temperature of the water to
fall below 50oC and have a maximum temperature of 60oC
I wanted to be able to increase the set point of 50oC by +10oC in increments of 1oC
kind regards
novolts
tha
 
Top