Pulsout vs PWM

RustyH

Senior Member
I guess comparing both

I made a circuit with Pulse out a while ago, it works ok, although the LED lights don't fade down very far, so was just wondering if PWM commands are better
 

nick12ab

Senior Member
The pwmout command runs continuously but only works on a limited selection of pins.

The pulsout command would need constant execution to achieve a dimming effect and you would have to choose between either having a minimum variable brightness setting above off or a maximum variable brightness setting below on because the slow PICAXE interpreter means you won't be able to achieve a 100% duty cycle or anything near it with the pulsout command.

The pwm command also needs constant execution.

Have you read PICAXE Manual 2?
 

RustyH

Senior Member
This was the pulsout code I used

Code:
up_fadeup:

    for LED = b.3 to b.7          
    
        for on_time = 0 to 3000 step 100
            pulsout LED,on_time
            off_time = 3000 - on_time
            pauseus off_time
        next on_time
        high LED
    
    next LED
   pause 5000


up_fadedown:

    for LED = b.3 to b.7 

        for on_time = 0 to 3000 step 100
          pulsout LED ,on_time
          off_time = 3000 - on_time
          pauseus off_time
       next on_time
       low LED

    next LED

pause 5000
goto main
 

hippy

Ex-Staff (retired)
I would say PWMOUT beats PULSOUT if you are simply using PULSOUT to create a varying duty.

There may however be other factors which make PULSOUT more appealing, perhaps lower frequency operation.
 

nick12ab

Senior Member
This was the pulsout code I used

Code:
up_fadeup:

    for LED = b.3 to b.7          
    
        for on_time = 0 to 3000 step 100
            pulsout LED,on_time
            off_time = 3000 - on_time
            pauseus off_time
        next on_time
        high LED
    
    next LED
   pause 5000


up_fadedown:

    for LED = b.3 to b.7 

        for on_time = 0 to 3000 step 100
          pulsout LED ,on_time
          off_time = 3000 - on_time
          pauseus off_time
       next on_time
       low LED

    next LED

pause 5000
goto main
The problem with this is that the duty cycle range is limited to 0 to 25% (if the pins are initially set to low) or 75% to 100% (if the pins are initially set to high) so the brightness range is more limited compared to using pwmout. The pwm command would suffer from the same problem. Ignore that as you are only using the pulsout command with one pin at a time in a loop then moving on to the next LED.

If the brightness range is acceptable then stick with the current code. If not, then because you are only using four channels then you could use the pwmout command on a PICAXE that has four channels such as the PICAXE-14M2.
 

premelec

Senior Member
Rusty - in practice it's hard to dim LEDs to nothing as they are so darned efficient - So I've put bypass resistors around them so they'll go more off.
 

hippy

Ex-Staff (retired)
What speed is the PICAXE being run at ?

Not dimming close to off suggests the on time is still reasonably large compared to the off time; shrink the on time or increase the off time and you will get dimmer. The problem with increasing the off time is that it can introduce flicker so better to shrink the on time. Increase PICAXE speed and you will get shorter on times.
 
Top