Does PWM really look like DAC output?
I recently had access to an oscilloscope so I decided to see if I could reproduce the PWM example from the Propeller Application Note AN001.
The measured waveform was depicted as a saw tooth with a 125ms period (Fig 6). I can in no way repeat this. All I get is a square wave with varying full on time depending on the state of the loop. The note mentioned no special circuitry required as for duty cycle DAC. I interpreted this to mean that, as an example, for LED brightness control the human eye is acting as some sort of integrator device and the LED really only sees full voltage for varying amounts of time.
Am I missing something here?
The measured waveform was depicted as a saw tooth with a 125ms period (Fig 6). I can in no way repeat this. All I get is a square wave with varying full on time depending on the state of the loop. The note mentioned no special circuitry required as for duty cycle DAC. I interpreted this to mean that, as an example, for LED brightness control the human eye is acting as some sort of integrator device and the LED really only sees full voltage for varying amounts of time.
Am I missing something here?
''Demonstration of PWM version of NCO counter mode
CON _clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR long parameter
PUB go | x
cognew(@entry, @parameter) 'start assembly cog
repeat
repeat x from 0 to period 'linearly advance parameter from 0 to 100
parameter := x 'a constant here locks to value x percent high
waitcnt(100_000 +cnt) 'wait a little while (1000 periods) before next update
DAT
''assembly cog fetches the value in parameter for PWM percentage
org
entry mov dira, diraval 'set APIN to output
mov ctra, ctraval 'establish counter A mode and APIN
mov frqa, #1 'set counter to increment 1 each cycle
mov time, cnt 'record current time
add time, period 'establish next period
:loop rdlong value, par 'get an up to date pulse width
waitcnt time, period 'wait until next period
neg phsa, value 'back up phsa so that it trips "value" cycles from now
jmp #:loop 'loop for next cycle
diraval long |< 0 'APIN=0
ctraval long 100 << 26 + 0 'NCO/PWM APIN=0
period long 100 '800kHz period (_clkfreq / period)
time res 1
value res 1
Comments
If you want a DAC, you would have to add 1k resistor in series and then 8.1nf cap to ground (or some other values)
EDIT: An 82 ohm resistor and .1uf cap will give about the same frequency. A 1k resistor and .1uf cap is 1.5Khz, 10k/.1uf is 159Hz.
Hope this helps,
David
Here's how you can get that waveform (I think):
Set your scope to 20 ms per division (really, really slow).
Turn your bandwidth down to about 10 MHz or less.
Then, I think you'll see it...
You may still have trouble with a good scope though. Then, you can use an RC filter to smooth it out to the triangle shape...
My scope is set to 20ms/div but I do not know what you mean set the bandwidth to <10MHz.
Is there an article where I can get more info on this low pass cutoff filter effect?
The Fig 6 has to include some Low Pass filtering, which is why it is not a clean line - you can see some of the PWM still here. - ie it is NOT a direct good-scope on a pin.
Notice also how it has the most ripple at 50% duty cycle.
You are right, that averaging systems like heating, and the human eye, will do their own integration/low pass filtering.