how i can generate 6 pwm output
Moderators: David Barker, Jerry Messina
-
- Posts: 8
- Joined: Fri Aug 17, 2012 2:30 pm
- Location: egypt
how i can generate 6 pwm output
hi
i am new user in swardfish , i want to genrate 6 pwm output and i can control on the duty of each channel
note i did it on proton pic basic with software pwm but the main problem it take long time it take about (3 sec)
so how i can genrate 6 pwm output with short time at least 0.5 sec
thanks
i am new user in swardfish , i want to genrate 6 pwm output and i can control on the duty of each channel
note i did it on proton pic basic with software pwm but the main problem it take long time it take about (3 sec)
so how i can genrate 6 pwm output with short time at least 0.5 sec
thanks
Don't forget that there is a search option at the top of the page
have a look at this thread
http://www.sfcompiler.co.uk/forum/viewt ... hlight=pwm
have a look at this thread
http://www.sfcompiler.co.uk/forum/viewt ... hlight=pwm
Hmmm..
-
- Posts: 8
- Joined: Fri Aug 17, 2012 2:30 pm
- Location: egypt
-
- Posts: 113
- Joined: Mon Jan 11, 2010 10:39 pm
- Location: Chesterfield
What are you driving with these PWMs and what sort of resolution and frequency do you need?
Software PWMs are fairly easy to implement but use a lot of processor time at high resolutions and frequencies.
It may be easier to use a dedicated chip or a combination of hardware and software PWM but we really need to know the application to advise.
Software PWMs are fairly easy to implement but use a lot of processor time at high resolutions and frequencies.
It may be easier to use a dedicated chip or a combination of hardware and software PWM but we really need to know the application to advise.
-
- Posts: 8
- Joined: Fri Aug 17, 2012 2:30 pm
- Location: egypt
I'm biomedical engineer and try to make ultrasonic device which use for medical application
the device consist of the control (micro) and 6 crystal 1MHZ (pezo element) which produce the ultrasound
there are oscillator circuit which simulate the crystal and the function of the micro here is control the oscillator circuit by transistor
but my main problem is there are 6 crystal with 6 oscillator circuit so i want 6 PWM signal with any resolution and with any frequency
the only important thing is the speed of the micro
the device consist of the control (micro) and 6 crystal 1MHZ (pezo element) which produce the ultrasound
there are oscillator circuit which simulate the crystal and the function of the micro here is control the oscillator circuit by transistor
but my main problem is there are 6 crystal with 6 oscillator circuit so i want 6 PWM signal with any resolution and with any frequency
the only important thing is the speed of the micro
- Senacharim
- Posts: 139
- Joined: Tue Aug 10, 2010 5:19 pm
- Location: Ventura, CA
If you're looking for somebody to write code for you, you might try hiring somebody for a one-time job. Might I suggest http://www.reddit.com/r/forhire/?
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992
Voted "Most likely to time travel"--Class of 2024.
Bermuda Triangle Battalion
from 2026 to 1992
Voted "Most likely to time travel"--Class of 2024.
-
- Posts: 113
- Joined: Mon Jan 11, 2010 10:39 pm
- Location: Chesterfield
I'm afraid you need to be a little more specific than any resolution and any frequency - you can get 2 bit resolution at 1Hz with no trouble, but 12 bit resolution at 1MHz is simply not viable.
It is also useful to know what else the micro needs to be doing. If you can dedicate the majority of the processor power to generating these PWMs then it is easier, otherwise you really need to be looking in to an interrupt-driven generator.
A simple way to do it with an 8 bit resolution would be to have 6 counter registers and 6 master reload registers. Have an ISR called at 256x your PWM frequency. Test each counter register in sequence, if it is zero then turn the corresponding output off, if it is non-zero then decrement it. Don't worry about repeatedly turning outputs off, it is quicker sometimes to do this than test if it is already off. You'd also have a master counter which you decrement each loop. Once this reaches zero you reload the counters from the reload registers, turn the outputs back on (unless the reload value is zero) and off we go again.
You need to make sure your ISR code is tight enough to complete before the next timer roll-over. If you are struggling then you can reduce the resolution and call the ISR less often. You aren't even restricted to full-bit resolutions using this method, there is nothing to stop you have a range of 0-100 for example.
One thing to bear in mind is that you at 8 bit you may get around a 250Hz PWM frequency when clocked at 4MHz and doing nothing else in the background.
It is also useful to know what else the micro needs to be doing. If you can dedicate the majority of the processor power to generating these PWMs then it is easier, otherwise you really need to be looking in to an interrupt-driven generator.
A simple way to do it with an 8 bit resolution would be to have 6 counter registers and 6 master reload registers. Have an ISR called at 256x your PWM frequency. Test each counter register in sequence, if it is zero then turn the corresponding output off, if it is non-zero then decrement it. Don't worry about repeatedly turning outputs off, it is quicker sometimes to do this than test if it is already off. You'd also have a master counter which you decrement each loop. Once this reaches zero you reload the counters from the reload registers, turn the outputs back on (unless the reload value is zero) and off we go again.
You need to make sure your ISR code is tight enough to complete before the next timer roll-over. If you are struggling then you can reduce the resolution and call the ISR less often. You aren't even restricted to full-bit resolutions using this method, there is nothing to stop you have a range of 0-100 for example.
One thing to bear in mind is that you at 8 bit you may get around a 250Hz PWM frequency when clocked at 4MHz and doing nothing else in the background.