PWM object - confused
geokonst
Posts: 48
Dear all,
I can't understand why the following code doesn't work
I am using this code for producing analogue audio signals. I've reduced the resolution in PXMx8 so I can have higher frequency. The loudspeaker is connected to output pin. Since the speaker can't respond to 30KHz I don't really need a low pass filter (do I?).
Problem is that although the code is expected to create a sound of constant frequency but varying amplitude the opposite happens. In particular the pitch changes with every increase by 4 of the duty cycle. Any clues?
Also is there an easy way -like an object- to use the sigma-delta modulation from spin. My assembly skills are really bad. I've already searched around and couldn't find anything. I guess I could modify the Microphone to Headphone code, but as I mentioned I lack the skills.
Thanks everybody
Post Edited (geokonst) : 10/8/2008 9:18:29 AM GMT
I can't understand why the following code doesn't work
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 base_pin = 16 OBJ pwm: "PWMx8" PUB start | j, duty pwm.start(base_pin, %1111_1111, 30000) repeat repeat j from 0 to 64 repeat 500 pwm.duty(base_pin, j) waitcnt(8000 +cnt) pwm.duty(base_pin, 0) waitcnt(8000 +cnt)
I am using this code for producing analogue audio signals. I've reduced the resolution in PXMx8 so I can have higher frequency. The loudspeaker is connected to output pin. Since the speaker can't respond to 30KHz I don't really need a low pass filter (do I?).
Problem is that although the code is expected to create a sound of constant frequency but varying amplitude the opposite happens. In particular the pitch changes with every increase by 4 of the duty cycle. Any clues?
Also is there an easy way -like an object- to use the sigma-delta modulation from spin. My assembly skills are really bad. I've already searched around and couldn't find anything. I guess I could modify the Microphone to Headphone code, but as I mentioned I lack the skills.
Thanks everybody
Post Edited (geokonst) : 10/8/2008 9:18:29 AM GMT
Comments
Thank you for your patience
Thank you for your help [noparse]:)[/noparse]
You could use PWM. I suspect your problems had more to do with timing interactions between the PWM generation and the routine continually calling the PWM duty cycle set routine. Maybe there was a beat frequency or something like that.
There was a sinewave synthesis program that was pasted here quite some time ago. I don't have a link to it. If you have the time and patience, you could search for it on this Propeller forum.
Look for Tracy Allens post with sinewave programs.
http://forums.parallax.com/forums/default.aspx?f=25&p=8&m=113109#m146258