pwm out on 08M

adub

New Member
Hi, I'm the proud new owner of four 08M's and a new breadboard thanks to what I've read here and on Stan's web site.

I'm trying to do something that I've been doing on my oopic-r for some time as a simple test of the pwmout.

I want to be able to ajust the brightness of the led I have on pin0. Is the pwmout ok to use on pin 0?

I can make the led flash in the usual manner but can't adjust the brightness up and down like I want.

Haven't put an led on pin2 to try it but thought I'd say hello first.
-----code follows------
'PWMOUT pin,period,duty cycles
pause 5000
high 0
pause 1000
low 0
top:
for b0 = 256 to 0 step -16
pwmout 0,b0,100 ' set pwm
' pwmout 0,100,b0 ' tried this too
pause 250
next b0


 

hippy

Technical Support
Staff member
As per "PICAXE Manual 2 - Basic Commands", only Pin 2 ( Leg 5 ) can be used for PWMOUT on an 08M.
 

BeanieBots

Moderator
As one who has moved from OOpic-R to PICAXE myself, I can strongly suggest it is the right thing to do. It's a little frustrating at first because PICAXE is not quite as flexible and does have a few limitations. However, PICAXES will talk to each other and you can have about 20 08Ms for the same price and size of one OOpic-R. That's a lot of processing.
As Hippy says, PWM is only available on specified pin(s) with the PICAXE range. If you need more, use another one.
 

Rickharris

Senior Member
This code provides PWM on an 08 and drives 3 outputs dimming the LEDs at various rates to give a colour changing display - This is not my code - I picked it from a web site in NZ quoted somwhere here in the forum but am now unable to find the site or the post some if this is your code please claim it.

The original had a switch input to pin 3 to turn all outputs full on but I removed it as it did not suit my application.

The code runs through 255 cycles and the stops you may wish to change this.

'Random colour

' Simple LED controller
' For PICAXE-08
' LEDs on pins 0,1,2


symbol temploop = b0
symbol count1 = b1
symbol maximum = b2

' ***** start of program reset counters *****
' first reset the counter count to 0

main:
low 1
low 2
low 4
nap 4

' ***** end of main loop *****

' ***** PWM control routine *****
animate:
nap 4
for maximum=255 to 0 step -1
if maximum < 1 then main
gosub cycle
next maximum

' ***** PWM routine *****
cycle:

random b4
b4=b4/4
b4=b4*3+64

random b5
b5=b5/4
b5=b5*3+64

random b6
b6=b6/4
b6=b6*3+64

high 1
if pin3 = 1 then fullon
pause b4

high 2
if pin3 = 1 then fullon
pause b5

low 1
if pin3 = 1 then fullon
pause b6

high 4
if pin3 = 1 then fullon
pause b4

low 2
if pin3 = 1 then fullon
pause b5

high 1
if pin3 = 1 then fullon
pause b6

low 4

return

 

adub

New Member
My apologies. I found the answer last night and put off writing til this morning. Used the DMM on all the pins and only pin2 had on output so I searched a little closer and found it not in one place but two.

The oopic-r is a very good processor but I scared my self thinking I had released the magic blue smoke and had to buy another one for the project we were working on. Then I found this one at Cheap prices. I thought I had read there were two channels of pwm on the 08M but have been proven wrong. Still 2 08M's are a lot cheaper than one oopic.

Thank you all for you responses.
Arvin
 

premelec

Senior Member
Just a suggestion that output 0 can be used for PWM - HOWEVER unlike the other pins it doesn't end up floating - so you could use the pin through a diode to a capacitor or whatever... and set the pin LOW at end of the PWM sequence.
 

adub

New Member
Rickharris,
I didn't have 3 led's hooked up plus I was working on something else so no time.

The code you posted has reference to a fullon label that isn't there so I remmed them out and it ran...but, there is no PWM in the code. PWM is in one of the Rems but not in the code at all other than that.

It makes nice dancing lights but not at varying brightnesses.

Would be interesting to see the use of pwm on three leds.

Arvin
 
G

Guest

Guest
This will drive LEds on output 0,1,2,4 It needs a brief input to pin3 to start the sequence off then it will repeat for a while. this code isn;t mine I found it on the afore mentioned site that seems to have vanished.

PS this is working as I am looking at i now. ;0 sorry about butchering the earlier code i seem to have disabled it.

ode:

'No lookup?
' Simple LED controller
' For PICAXE-08
' LEDs on pins 0,1,2
' Push switch on pin 3

symbol cycle=b0
symbol loop=b1
symbol loop2=b2

' ***** main loop *****

start:
low 1
low 2
low 4
nap 4
start2:
nap 1
if pin3 = 0 then start2

' ***** end of main loop *****

' ***** LED control routine *****

nap 4

for cycle=255 to 0 step -10

b5=1
b6=0
gosub fade
b5=2
gosub fade
b5=4
gosub fade
b5=1
b6=2
gosub fade
b5=2
b6=4
gosub fade
b5=4
b6=1
gosub fade

next cycle
goto start

' *****PWM drive routine*****
fade:

for loop=0 to cycle
pwm b5,loop,1
pwm b6,loop,1
if pin3 = 1 then fullon
next loop

for loop=cycle to 0 step -1
pwm b5,loop,1
pwm b6,loop,1
if pin3 = 1 then fullon
next loop

return

' ***** Full on routine *****
fullon:
high 1
high 2
high 4
nap 4
fullon2:
if pin3 = 1 then start
goto fullon2

 

Rickharris

Senior Member
This will drive LEds on output 0,1,2,4 It needs a brief input to pin3 to start the sequence off then it will repeat for a while. A second input to pin 3 will turn all LEds full on

This code isn;t mine I found it on the afore mentioned site that seems to have vanished.

PS this is working as I am looking at i now. ;0 sorry about butchering the earlier code i seem to have disabled it.

ode:

'No lookup?
' Simple LED controller
' For PICAXE-08
' LEDs on pins 0,1,2
' Push switch on pin 3

symbol cycle=b0
symbol loop=b1
symbol loop2=b2

' ***** main loop *****

start:
low 1
low 2
low 4
nap 4
start2:
nap 1
if pin3 = 0 then start2

' ***** end of main loop *****

' ***** LED control routine *****

nap 4

for cycle=255 to 0 step -10

b5=1
b6=0
gosub fade
b5=2
gosub fade
b5=4
gosub fade
b5=1
b6=2
gosub fade
b5=2
b6=4
gosub fade
b5=4
b6=1
gosub fade

next cycle
goto start

' *****PWM drive routine*****
fade:

for loop=0 to cycle
pwm b5,loop,1
pwm b6,loop,1
if pin3 = 1 then fullon
next loop

for loop=cycle to 0 step -1
pwm b5,loop,1
pwm b6,loop,1
if pin3 = 1 then fullon
next loop

return

' ***** Full on routine *****
fullon:
high 1
high 2
high 4
nap 4
fullon2:
if pin3 = 1 then start
goto fullon2

 

adub

New Member
Well, I must say, that is good. Now I will definately have to order one of those 4 wire rgb led's.

Thanks
Arvin
 

Rickharris

Senior Member
I used this to drive 3 LEDs red Green and Blue - I drilled the ball out of a deoderant bottle and inserted the LEds - the effect is of a large colour changing ball. Workes well.
 
Top