pwm command

barneydog

Member
Hi,

been trying to use this command with little to no success....

what i want to do is

run an led at 50% its brightness, then from a switch increase to 100% brightness...switch off returns to 50%


all that keeps happening is a pulsing...

which is the best command and do you have any examples please.... i dont want you to solve my problem, maybe just explain the commands a little more...

thanks in advance

James
 

barneydog

Member
have read the manual on the code and feel rather lost over it still...

i have no code as yet, except a sample bit i tried to get it to do whats mentioned above...

its more how do i get it to display 50% brightness and then 100% brightness

pwm 0 , 50 , 255 <--- will that run it at 50% brightness as the duty is 50?

this is what i dont understand about the command
 

eclectic

Moderator
@barney. /James
1. Print out page 160 of Manual 2.

2. Open PE and find the
Wizards > PWM

3. I'm using an 08M (your pin may be different)

Try
Code:
Main:
for b0 = 1 to 255
pwmout 2, 62, b0
pause 100
next
goto main
e
 

John West

Senior Member
Try the PWMOUT command. PWM is just for short control sequences, i.e. stepping a motor to a position.

Also, you will need to set the duty cycle value based on experimentation to determine what the "half bright" value for your particular LED will be.
 

barneydog

Member
ok

so the duty will be how bright i get the led to show...

and the frequency will be how long the period of display it stays on...


as that correct
 

John West

Senior Member
The frequency is how fast it goes on and off. (Set it high enough so you don't see any flicker.) Then the duty cycle will determine how bright it appears.
 
Last edited:

barneydog

Member
sooo


this is an example to see if i got the understanding correct


40000 frequency and 50% duty would be PWMout 2, 24, 50 (wizard did it so i know its correct haha)

so that would flicker very very fast wouldnt see it flicker, and it would run the led at 50% of its duty....

sorry if i seem dumb... most other commands i have found straight forward... this ones killing me slowly :eek:
 

John West

Senior Member
PWMOUT runs constantly in the background, and is perfect for controlling the brightness of an LED. The frequency value is how fast the overall on/off toggling of the pin takes place, and needs to be high enough so you don't see a flicker from the LED. 100Hz on up should be good.

The duty cycle determines how long during each "on/off" frequency cycle the voltage will be high. A low value means it will spend most of each cycle turned off. A high value means it will spend most of each cycle turned on.

As the average "on" time goes up (higher duty cycle) the averaged voltage out goes up, making the LED appear brighter and brighter.
 

eclectic

Moderator
sooo


this is an example to see if i got the understanding correct


40000 frequency and 50% duty would be PWMout 2, 24, 50 (wizard did it so i know its correct haha)

so that would flicker very very fast wouldnt see it flicker, and it would run the led at 50% of its duty....

sorry if i seem dumb... most other commands i have found straight forward... this ones killing me slowly :eek:
1. Try the program in post 4,
then, try your program

You're getting much closer. :)

e
 

Technical

Technical Support
Staff member
Err....shouldn't that be w0 and 1023.
(Pwmout takes a word value.)
But 62 x 4 = 248, so really it should be from 'for b0 = 1 to 248', which is still a byte value and so b0 is ok. remember one number can only be 4 times the other max.
 

John West

Senior Member
The values of frequency and pulse width look to be interrelated such that using the correct frequency/pulse-width combination will provide a brightness range of zero to full on while operating within stepping values of 0-255.

EDIT: I see Technical beat me to it.
 

AndyGadget

Senior Member
But 62 x 4 = 248, so really it should be from 'for b0 = 1 to 248', which is still a byte value and so b0 is ok. remember one number can only be 4 times the other max.

Gach! Absolutely. Apologies.
(That will teach me not to bang off a quick reply after a long drive ;¬)
 

John West

Senior Member
eclectics code is fine, Barney. It would just leave you a tiny bit short of full LED brightness. Not even enough to even notice.
 

barneydog

Member
im using the 14 m... after looking i see input pin 2 is the one i need to be connected to.. is that correct ? (ic pin 5)


and nothing seems to happen at all :(

im running electrics code as is on it...

led goes dimly lit for a second then turns off....


code i have is

Main:
for b0 = 1 to 255
pwmout 2, 62, b0
pause 100
next
goto main
 

barneydog

Member
thats the pin im connected to...


tried a few different leds and it just does the same...

pin 1 - +5V
pin 5 - LED
pin 14 - 0V

thats all thats connected
 

eclectic

Moderator
thats the pin im connected to...


tried a few different leds and it just does the same...

pin 1 - +5V
pin 5 - LED
pin 14 - 0V

thats all thats connected
2 things.
1. I've just tried a 14 M on an AXE091 board
Code:
Main:
for b0 = 1 to 255
pwmout 2, 62, b0
pause 100
next
goto main
Works perfectly.


Do NOT try any more LED's yet.

2. Errr, please tell us
and better would be a photo
of ALL your setup.

You HAVE got a resistor there?
Haven't you?

e
 

Technical

Technical Support
Staff member
barneydog said:
pin 1 - +5V
pin 5 - LED
pin 14 - 0V

thats all thats connected
Are you moving a programmed chip about - if so you need the serial download pin connected to 0V - see minimum operating circuit in part1 of the manual.
 

barneydog

Member
Led is the correct way round...

I am using a 220R resistor... have tried a few others aswell incase it was wrong value...

im programming it in the programmer, then moving it to a breadboard to test...
 

barneydog

Member
ok... heres whats happening now

when first switched on it sits there doing nothing for 1 minute roughly


then it starts doing the program

it slowly lights up then turns off and starts again...


why the minuter delay at the start ?

started working when i changed resistor to 100R
 

eclectic

Moderator
reference to both posts 28/29

What's the "programmer"?

Please post a photo of your breadboard

The program appears to work. :)

It should slowly change from
zero to full brightness, then
zero and start again.

Here's a modified version:
Code:
#picaxe 14M

Main:
for b0 = 1 to 255
pwmout 2, 64, b0
sertxd (#b0," ")
pause 100
next
goto main
e
 

John West

Senior Member
Led is the correct way round...

I am using a 220R resistor... have tried a few others aswell incase it was wrong value...

im programming it in the programmer, then moving it to a breadboard to test...
As Technical stated in comment #27, the PICAXE programming pin must be tied low in your operating circuit. You made no comment in that regard.

Is it? If not, that would certainly lead to erratic operation, if any.
 
Last edited:

barneydog

Member
if you mean pin 13 serial out then its going to 0v

will take a pic and upload

programmer is a RKP14LP... its worked perfect in the past....
 

barneydog

Member
serial pin low and it worked :eek:


is that a standard thing with all picaxe's...

as other programs i have made i have never done that and they have worked fine...

does it need a resistor when held low or just straight to low

sorry for delay in answering, after you all been so helpful...son wanted me to watch indiana jones with him
 

barneydog

Member
its a programmer i found on ebay by a company called RK Education...

its ok, not the one i really wanted.. the one i wanted had been discontinued at the time of going to buy it... didnt have enough in paypal for the new version of it.. so settled for them.. they not bad...

Dimming program has worked...

i have made some additions to try understanding better

Main:
for b0 = 1 to 255
pwmout 2, 64, b0
pause 10
next


for b0 = 255 to 1 step -1
pwmout 2, 64, b0
pause 10
next
goto main

I think im understanding it a lot more...still not 100% sure on frequencies...I very new to picaxe (im sure you hadnt guessed) so have been using Logicator.. it seems its way of dealing with frequencies is different... maybe im just not understanding fully still...

and at last the picture.. power unplugged so led didnt dazzle...

 

barneydog

Member
i stopped pin 13 going 0v and made pin 2 go 0v and it worked...

you are correct on the missing track problem....

your suggested fix worked perfectly....

serial in, on every circuit i make should i make that low ? or does it only matter for certain picaxe's
 

eclectic

Moderator
its a programmer i found on ebay by a company called RK Education...

its ok, not the one i really wanted.. the one i wanted had been discontinued at the time of going to buy it... didnt have enough in paypal for the new version of it.. so settled for them.. they not bad...
Right, you're on your way.

A couple of points:

1. In future, it really will be easier if you post a photo / schematic / program.

2. No, I don't work for RevEd, but many people here
are familiar with the RevEd project boards.
A hint for your future purchases. :)
(I won't say any more about the RK provenance.)

3. What colour was the LED? Blue?


e
 

barneydog

Member
ok i will remember that....

the board i wanted was RevEd.. hobbyist board i think they called it... had the bread board in the middle...


Led's i tried was red, blue, yellow....its the red one in the pic...the type is perfect for my model trucks i build...


does serial in need to be set low on every circuit ???
 
Top