PWMPAL Sine wave generation.
Vitor
Posts: 13
I purchased the PWMPAL to generate sine waves and after reviewing the documentation I did not find much besides the sample to light the tri-color LED.
I purchased the PWMPAL because it was advertised for producing sine waves.
I need to generate four sine waves from 1 Hz to 600 Hz (or 1,000 Hz, this is not critical). This is to simulate four wheel speed sensors in a car.
I need to ramp the signals up to 600 Hz over a period of 60 sec (not critical).
Then, I drop one of the signals about 50% (not critical) and keep all other three at original frequency (one wheel locks up while applying the brakes).
I do the same for the other 3 signals over a period of time.
I reduce the frequency down to zero (or close to) to simulate stopping the car.
With this code I get 200 Hz
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", 100, 0, 100, 0]
SEROUT 0, 6, [noparse][[/noparse]"!PWMSS", %00010000]
I have tried a resistor out of P12, pwmm1 and grounding the signal thru a 1uf capacitor as the sample in page 37, Understanding signals.
I get a shark fin wave.
I changed the frequency, resitors, capacitors to smooth the wave but the shark fin is the best I can do.
Am I missing something?
In the tri-color example, two outputs are used.
Do I need two outputs to generate one sine wave? If so, I will only be able to produce 2 sinewaves?
Can I generate a fairly decent sinewave out of every motor output?
Help will be greatly appreciated if you have a sample circuit and/or code.
Thank you.
·
I purchased the PWMPAL because it was advertised for producing sine waves.
I need to generate four sine waves from 1 Hz to 600 Hz (or 1,000 Hz, this is not critical). This is to simulate four wheel speed sensors in a car.
I need to ramp the signals up to 600 Hz over a period of 60 sec (not critical).
Then, I drop one of the signals about 50% (not critical) and keep all other three at original frequency (one wheel locks up while applying the brakes).
I do the same for the other 3 signals over a period of time.
I reduce the frequency down to zero (or close to) to simulate stopping the car.
With this code I get 200 Hz
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", 100, 0, 100, 0]
SEROUT 0, 6, [noparse][[/noparse]"!PWMSS", %00010000]
I have tried a resistor out of P12, pwmm1 and grounding the signal thru a 1uf capacitor as the sample in page 37, Understanding signals.
I get a shark fin wave.
I changed the frequency, resitors, capacitors to smooth the wave but the shark fin is the best I can do.
Am I missing something?
In the tri-color example, two outputs are used.
Do I need two outputs to generate one sine wave? If so, I will only be able to produce 2 sinewaves?
Can I generate a fairly decent sinewave out of every motor output?
Help will be greatly appreciated if you have a sample circuit and/or code.
Thank you.
·
Comments
The frequency (and PWM) is set by specifying the on time and off time in 25us units. Since you probably want a symmetric pulse, the on time and off time would be the same. To get 600 Hz, you would need a total cycle time of 1/600 or about 66 units. The on time should be 33 units and the off time should be 33 units which will give an output frequency of 606Hz. For a 1Hz frequency, you will need 10,000 units for the on time and 10,000 units for the off time. This is supplied as two bytes as you've noticed before in the documentation. To ramp this up, you will need to decrease the units from 10,000 to 33 over the 60 second period. You'll have to decide what kind of change curve you want and what kind of formula or table you need to get the changes you want.
You might be able to take the triangle waveform (shark fin) and run it through a converter like this one (cut and paste the diagram and use a fixed width font like Courier to view it).
There's another converter described here (www.oldtemecula.com/theremin/sixthvoice/index.htm)
If you search the web for "square wave to sine wave" you'll find lots of converters.
I have under control the portion for frequency and duty and curve for modifying.
I missed that tiny little portion of the PWMPAL spec. AC square wave.
In the tri-color led sample.
I hooked my scope to it but I has having a problem·and I did not see the wave.
What portion of the code prompts PWMM2 to generate the negative voltage (opposite polarity of PWMM1) and not just another PWM positive square signal?
And, out of curiosity, why are the duration values in·hexadecimal·in the PWMPAL documentation samples?
Thank you again.
·