how i can generate 6 pwm output

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
kerelous58
Posts: 8
Joined: Fri Aug 17, 2012 2:30 pm
Location: egypt

how i can generate 6 pwm output

Post by kerelous58 » Fri Aug 24, 2012 1:51 pm

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 :)

richardb
Posts: 306
Joined: Tue Oct 03, 2006 8:54 pm

Post by richardb » Wed Aug 29, 2012 7:09 am

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
Hmmm..

kerelous58
Posts: 8
Joined: Fri Aug 17, 2012 2:30 pm
Location: egypt

Post by kerelous58 » Sat Sep 15, 2012 5:35 pm

thanks for your replay and sorry for my wait

but i can't write the code

i can't note the code in the library spwm which control the pwm in each channel

i want simple code which provide me to control on the pwm of each channels

thanks for your interesting

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Fri Sep 21, 2012 10:24 am

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.

kerelous58
Posts: 8
Joined: Fri Aug 17, 2012 2:30 pm
Location: egypt

Post by kerelous58 » Fri Sep 21, 2012 3:38 pm

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

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Mon Sep 24, 2012 1:49 pm

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.

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Tue Sep 25, 2012 12:57 pm

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.

Post Reply