PWM help

SKL BOI

Member
Hi

I have shown the circuit i am using previously so if you want to see that then I can add the picture!

I am trying to run a computer fan/pump on PWM from a picaxe 08m ( for the moment I might need to expand) and im having problems figuring out the code and why the picaxe programming editor doesn't like the code.

I am using the "programming and customizing the picaxe micro controller" book and the picaxe manuals for my coding.

so far I have:

main:
readadc 1,b0

if b0 = 100 then top
if b0 = 200 then bot
if b0 = 256 then dot
goto main

top:
pwmout4 150, 100,
high 6
goto main

bot:
pwmout4 b0 100
high 7
goto main

dot:
pwmout4,b0,100
high 8
goto main

This is just testing i want to work out the correct values at the top through testing.

Unless any one has done this before and can tell me how they have done it and the code?

Thanks for any help

SKL BOI
 

Andrew Cowan

Senior Member
Your problem is that if the potentiometer isn't at 100, 200 or 256, it will not change.

If you move the pot quickly, and it does not ytake a reading at a certain value, it won't update. Better code would be:

Code:
main:
readadc 1,b0

if b0 < 100 then top   'if it is less than 100
if b0 < 200 then bot   'if it is between 101 and 199
if b0 < 255 then dot   'if it is between 200 and 255
goto main
Note b0 will between 0 and 255 - not 1 and 256.

PWMout will only work on pin2 on an 08M.

I presume you want three control levels (Low, medium and high). In this case, the code should be:
Code:
top:
pwmout2,99,120     '30% speed
high 0
goto main

bot:
pwmout2,99,240    '60% speed
high ?
goto main

dot:
pwmout2,99,400   'full speed
high 4
goto main
I changed the output numbers to the appropriate pins on an 08M - 0, 1 and 4.

2 is the PWM pin, and 3 is a digital input only. However, as you have the potentiometer on pin 1, you only have two other ouputs (for LEDs etc), so you can only use two indicators. Maybe use a larger chip (the 14M?)

Andrew
 

SKL BOI

Member
pwm help

Ah yes sorry i was using that code to try and get it to work so i was changing lots of stuff just to get it to simulate. I know it only goes up to 255 but my programming editor didn't flag up that it was a problem should it?

Will the top bot and dot section part vary dependant on the input then because i am actualy running a thermistor and i want a three stage output from that.

Thats interesting that its wrong because i checked it was right before i made the board by posting it on this forum and apparently i wasn't.

Thanks for replying so quickly ill stay online this time.

SKL BOI
 

Andrew Cowan

Senior Member
Ahh, this is a case of confusion over pin numbers. Your circuit diagram and board are correct.

Leg 7 = input / output 0
Leg 6 = input / output 1
Leg 5 = input / output 2 and PWM output pin
Leg 4 = input 3
Leg 2 = input / output 4

Therefore, you circuit diagram shows the output on leg 4 and pin 2. Your code says pin 4, where it should read pin2.

Will the top bot and dot section part vary dependant on the input then because i am actualy running a thermistor and i want a three stage output from that.

Yes - the output will be 30%, 60% or 100% depending if it is cold, medium or hot.

A
 

SKL BOI

Member
Brilliant thank you very much for your help.

So that coding you wrote is correct?

Thanks very much

SKL BOI
 

SilentScreamer

Senior Member
Replace the question mark with the correct pin number (NOT leg number) and this will work. The pwmout commands didn't have the space between pwmout and the pin number (i.e. "pwmout2" rather than "pwmout 2")

Code:
#PICAXE 08M

main:
readadc 1,b0

if b0 < 100 then top   'if it is less than 100
if b0 < 200 then bot   'if it is between 101 and 199
if b0 < 255 then dot   'if it is between 200 and 255
goto main

top:
pwmout 2,99,120     '30% speed
high 0
goto main

bot:
pwmout 2,99,240    '60% speed
high ?
goto main

dot:
pwmout 2,99,400   'full speed
high 4
goto main
 
Last edited:

Andrew Cowan

Senior Member
You will also need to turn the unused outputs off in the subroutines. I would recommend:

Routine1:
High 0
Low 4

Routine 2:
Low 0
High 4

Routine3:
High 0
High 4

Note that the pwmout parts and the goto main parts are ommitted from the above.

A
 
Last edited:
Top