Good evening guys, I'm relatively new to picaxe programming and i'm working on a little task at the minute: using a temperature sensor (ds18b20) and microcontroller to vary the speed of a 5v motor. The motor is connected via a N-channel mosfet transistor with a diode to block some of the back emf.
I have each part of the circuit working if I use them separately; the sensor reads, the motor runs at varying speeds and the screen shows the display I want (except the temperature variable does not.)
When i put all the components into one program and wire the circuit up - i get a motor running at what i'm guessing is 100% and no temperature readout on the OLED screen.
I know my coding is possibly not the best way to do a pulse width modulation project, but like i said this is my first attempt. I've included my latest coding attempt below; if anyone has any help as to where i may be going wrong i'd be very grateful.
EDIT: i am using an 18m2 project board, the output pin for the OLED screen is soldered directly to the pin of the IC chip and not through the darlington driver. I have the transistor connected to b.3 and the sensor connected to c.1
Regards
I have each part of the circuit working if I use them separately; the sensor reads, the motor runs at varying speeds and the screen shows the display I want (except the temperature variable does not.)
When i put all the components into one program and wire the circuit up - i get a motor running at what i'm guessing is 100% and no temperature readout on the OLED screen.
I know my coding is possibly not the best way to do a pulse width modulation project, but like i said this is my first attempt. I've included my latest coding attempt below; if anyone has any help as to where i may be going wrong i'd be very grateful.
EDIT: i am using an 18m2 project board, the output pin for the OLED screen is soldered directly to the pin of the IC chip and not through the darlington driver. I have the transistor connected to b.3 and the sensor connected to c.1
Regards
Code:
; Constants:
symbol temperature = b1 ;Rename b0 variable to temperature
symbol pwmfan = b.6 ;Rename pin b.6 to Pwmfan
symbol tempsens = c.1 ;Rename pin c.0 to tempsens
; Temperature Settings
; --------------------------------------------
; Temperature Fan Speed PWM duty
;
; <= 20 30% 119
; 21 41% 159
; 22 50% 199
; 23 58% 231
; 24 67% 267
; 25 75% 299
; 26 80% 319
; 28 90% 359
; >=30 100% 399
;
; --------------------------------------------
main:
READTEMP tempsens, temperature ; read the temperature of DS18B20 on pin c.0, load variable into b1
debug b1
serout b.2, n2400, ( 254, 1 ) ; Clear OLED display
pause 50 ; pause to clear
serout b.2, n2400, ( 254, $80 ) ; First line of display
serout b.2, n2400, ( "Temperature" ) ; Display "Temperature"
serout b.2, n2400, ( 254, $C0 ) ; Second line of display
serout b.2, n2400, ( #temperature, "C" ) ; Display the temperature
wait 2 ; wait 2 seconds
if temperature <=20 then lowspeed ; if variable in b1 is less than or equal to 20 degrees goto section
if temperature =21 then speedforty ; if variable in b1 is equal to 21 degrees goto section
if temperature =22 then speedfifty ; if variable in b1 is equal to 22 degrees goto section
if temperature =23 then speedfive8 ; if variable in b1 is equal to 23 degrees goto section
if temperature =24 then speedsix7 ; if variable in b1 is equal to 24 degrees goto section
if temperature =25 then speedseven5 ; if variable in b1 is equal to 25 degrees goto section
if temperature =26 then speedeight0 ; if variable in b1 is equal to 26 degrees goto section
if temperature =28 then speednine0 ; if variable in b1 is equal to 28 degrees goto section
if temperature >=30 then fullspeed ; if variable in b1 is more than or equal to 30 degrees goto section
goto main ; return to main
lowspeed:
peek temperature, b1 ; check temperature in variable b1
if temperature >20 then goto main ; if temperature is more than 20 degrees return to main
if temperature <=20 then pwmout B.3, 99, 119 endif ; if temperature is less or equal to 20 degrees, adjust pwm to 10000Hz at 30% @ 4MHz
pause 1000 ; wait 1 second
goto lowspeed ; return
speedforty:
peek temperature, b1 ; check temperature in variable b1
if temperature <>21 then goto main ; if temperature is more or less than 21 degrees, return to main
if temperature = 21 then pwmout B.3, 99, 159 endif ; if temperature is 21 degrees, adjust pwm to 10000Hz at 40% @ 4MHz
pause 1000 ; Wait 1 second
goto speedforty ; return
speedfifty:
peek temperature, b1 ; check temperature in variable b1
if temperature <>22 then goto main ; if temperature is more or less than 21 degrees, return to main
if temperature = 22 then pwmout B.3, 99, 199 endif ; 10000Hz at 50% @ 4MHz
pause 1000 ; Wait 1 second
goto speedfifty ; return
speedfive8:
peek temperature, b1 ; check temperature in variable b1
if temperature <>23 then goto main ; if temperature is more or less than 23 return to main
if temperature = 23 then pwmout B.3, 99, 231 endif ; if temperature is 23 degrees, adjust pwm to 10000Hz at 58% @ 4MHz
pause 1000 ; Wait 1 second
goto speedfive8 ; return
speedsix7:
peek temperature, b1 ; check temperature in variable b1
if temperature <>24 then goto main ; if temperature is more or less than 24 degrees return to main
if temperature = 24 then pwmout B.3, 99, 267 endif ; if temperature is 24 degrees, adjust pwm to 10000Hz at 67% @ 4MHz
pause 1000 ; Wait 1 second
goto speedsix7 ; return
speedseven5:
peek temperature, b1 ; check temperature in variable b1
if temperature <>25 then goto main ; if temperature is more or less than 25 degrees return to main
if temperature = 25 then pwmout B.3, 99, 299 endif ; if temperature is 25 degrees, adjust pwm to 10000Hz at 75% @ 4MHz
pause 1000 ; Wait 1 second
goto speedseven5 ; return
speedeight0:
peek temperature, b1 ; check temperature in variable b1
if temperature <>26 then goto main ; if temperature is more or less than 26 degrees return to main
if temperature = 26 then pwmout B.3, 99, 319 endif ; if temperature is 26 degrees, adjust pwm to 10000Hz at 80% @ 4MHz
pause 1000 ; Wait 1 second
goto speedeight0 ; return
speednine0:
peek temperature, b1 ; check temperature in variable b1
if temperature <>28 then goto main ; if temperature is more or less than 28 degrees return to main
if temperature = 28 then pwmout B.3, 99, 359 endif ; if temperature is 28 degrees, adjust pwm to 10000Hz at 90% @ 4MHz
pause 1000 ; Wait 1 second
goto speednine0 ; return
fullspeed:
peek temperature, b1 ; check temperature in variable b1
if temperature <30 then goto main ; if temperature is less than 30 degrees return to main
if temperature >= 30 then pwmout B.3, 99, 399 endif ; if temperature is more than or equal to 30 degrees, adjust pwm to 10000Hz at 100% @ 4MHz
pause 1000 ; Wait 1 second
goto fullspeed ; return
end
Last edited: