help understanding Temperature with 40X2

avner

Senior Member
Hey,

my plan is building a LED display thermometer.
i will have a DS18B20 connected to a PICAXE 40X2.

the 40X2 will have let's say 20 LEDs connected to it - each led on another output.
making a bargraph using these 20 leds, it will make a thermometer starting with the 1st LED showing 10*C, 2nd led indicating 11*C... until led 20 which will indicate 30*C.
each led that lights up will symolize 1*C increament.
well i think you've got it.

MY QUESTIONS are:

i want to keep it simple, thus i want the PICAXE output to directly drive LEDs. not supporting logic\serial decoders and stuff.
how many LEDs could i connect to a 40X2 ? (considering i need 1 input to be used by the DS18b20)

do i have to buy an external 4Mhz resonator for the 40X2 on this project ? or it has an internal one ?

*** if i'm short on outputs - I dont mind using each led increament as 2*C step to have a wider temperature scale.
i plan it to be more a visual effect than a precision device (though i still want to be able to read the temp at +\- 1*C)

any further thoughts ?
thanks!
 

eclectic

Moderator
@Avner

On the 40X2, you do not need a resonator.
See Manual 2, page 185.
Setfreq

You can have 1 input and 31 outputs.
Manual 1, page 33
40X2 pinout

Manual 2, page 112
let dirsA / dirsB / dirsC / dirsD =

e
 
Last edited:

Andrew Cowan

Senior Member
Looking at the PIC18F4520 datasheet;

Maximum output current sunk by any I/O pin................................................................25 mA
Maximum output current sourced by any I/O pin ....................................................................25 mA
Maximum current sunk by all ports ....................................................................200 mA
Maximum current sourced by all ports ....................................................................200 mA

So, you can drive 20 LEDs at 10mA maximum - you'll need resistors on them to limit that. (Or 27 LEDs at 7mA).

A
 

avner

Senior Member
thanks !

I counted 32 pins, where 1 has to be the input, which makes 31 outputs possible....
what did i miss ?
 

Andrew Cowan

Senior Member
PortA = 8
PortB = 8
PortC = 8
PortD = 8
=32

The X2 range have up to 32 configurable input/output pins, which are arranged in 4 ports, labelled A to D. Each
port has up to 8 pins (0-7). See the pinout diagrams for the specific 20 / 28 / 40 pin layouts.
Looks like you have 31 pins then = 6mA per LED bar.

A
 

avner

Senior Member
ah great,
that means 31 outputs = 10*C to 41*C !

dont worry about the current - i'll use transistors, since i want the bargraph to be big and bright.
i'll use high brightness LEDs, probably several of them for every stage or output.

i'd like to get a feedback on the program i wrote:
setfreq m8

let dirsA = %11111111 ;SET ALL PORTS OUTPUT
let dirsB = %11111111
let dirsC = %11111111
let dirsD = %11111111
let dirsB = %11111110 ;SET B.0 pin INPUT (pin 0)

mainloop:

readtemp 0,b3 ; read temp from pin 0

b3 = b3 - 10 ; take 10 degrees off the mesurement because pin #1 symbolizes 10 degrees C


for b1 = 1 to 31

IF b1 <= b3 THEN ; if output pin number is under measured temp.
high b1 ; then turn the led on
ENDIF

IF b1 > b3 THEN ; if the pin number is above the temp measured
low b1 ; then turn the led off
ENDIF


next b1



goto mainloop
 

BCJKiwi

Senior Member
Could be reduced to a single if...then...else...endif statement;

Code:
IF b1 <= b3 THEN ; if output pin number is under measured temp.
    high b1 ; then turn the led on
ELSE
    low b1 ; then turn the led off
ENDIF
 

avner

Senior Member
thanks for that.

apart it, it should work all fine, right ?
at the hardware point - as i've seen the 40X2 doesnt have pins that must be used as onlu input or only output, am i right ?
 

avner

Senior Member
great - i've ordered the 40X2 and the temperature sensor.

next update - when it arrives.

thanks !
 
Top