Fixed amplitude PWM 14M2

I assumed that by putting an output into PWM mode the voltage level on the pin would remain a constant when I varied the duty cycle. However I see the amplitude varying, which I think is not what is generally needed for modulating a LED.

It could easily be my rubbish scope setup but it is not easy to crosscheck so would appreciate an informed view.

I am using PWMOUT to initiate, then PWMDUTY to change the duty ratio. The pin output goes straight to a LED/Resistor (no capacitors involved). This is on 3 outputs c.0, c.2, b.4

BTW this is my first use of the PICAXE and I think it is fantastic!
 

nick12ab

Senior Member
However I see the amplitude varying, which I think is not what is generally needed for modulating a LED.
It shouldn't do.

Try...
  • Measuring the PWM output with just the scope and no LED attached
  • Reducing the PWM frequency (with the pwmdiv16 or pwmdiv64 keyword in the pwmout command.
 
Thanks for that very quick input; confirming my view that the scope is the problem. I am already using pwmdiv64 so am going to blame my scope as I already measured with no output connected. Might buy a proper scope downstream.
 

nick12ab

Senior Member
Before you blame your scope, you could put a diode (with very low reverse leakage) and capacitor in series to 0V from the output pin and measure the voltage across the capacitor - it should be around Vdd (5V) - Vf (diode forward voltage drop) for any duty cycle however it could be more as the voltage drop of a diode is smaller at tiny currents.
 
It's the scope (=xoscope +pc sound card). I deserve a proper scope and one day I am going to have one! Meanwhile this lash up suffices to indicate activity. Thanks for your help.
 

IronJungle

Senior Member
As mentioned, the P-P voltage should stay the same.

Video shown below is from the PWM routine of:
Code:
pwmout C.2,99,400    'start PWM on Port C Pin 2 @ 100%
main:	
for w1 = 0 to 400	' pwmduty needs a (W)ord var, not a (B)yte var
	pwmduty C.2, w1 'adjust PWM Duty from 0% to 100% 
	pause 2		
next w1

for w1 = 400 to 0 step -1 'same as above, but reduce the ON time
	pwmduty C.2, w1
	pause 2
next w1
goto main
 

inglewoodpete

Senior Member
It's the scope (=xoscope +pc sound card). I deserve a proper scope and one day I am going to have one! Meanwhile this lash up suffices to indicate activity. Thanks for your help.
Sound card scopes are problematic at low frequencies. They will almost invariably be AC coupled and their bass roll-off can start as high as 200Hz.

If trying to measure PWM with a soundcard scope, try a mid-frequency like 800Hz or 1 kHz.
 
Top