CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Precise 4 software based PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vladtess



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

Precise 4 software based PWM
PostPosted: Thu Apr 26, 2012 10:13 pm     Reply with quote

Hello fellas again.

I am planning to use a dedicated PIC to create 4 PWM sources that are precise and controlled via SPI. Now 100% accurate software PWM would really block the thread (and we have only one processor on PIC). So is that even closely reliable to say that it is possible to create 4 software based PWMs which will be able to alter the frequency and on top of it communicate through SPI while maintaining same frequency?

Thanks much for your help!!!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 2:15 am     Reply with quote

Can you be a bit more precise with your design brief?

Are you planning to use four PICs communicating via SPI?
Will you use just one external clock?
Will the PWM frequencies be different?
Can you tolerate minor glitches during PWM changes?
Do you want the individual PWMs to be locked in any way?
............

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 5:14 am     Reply with quote

Like Mike says we need MORE information !!

Yes, a 4 channel software PWM and SPI is possible with any PIC that will work 100% WITHIN limitations.
Heck even a 16C84 could handle 8 channels and soft UART 20 years ago

But...

more info..
like PIC type(yours or new choice)
speed(frequency) of PWM (hz or khz)
resolution of PWM(4,8,10,16 bits)
all 4 in sync or free running ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 7:51 am     Reply with quote

Two key things:

First, what direction will the SPI be?. Master will be relatively easy, being a slave is much harder.

Second what sort of PWM frequency & resolution.

Now, look at the MicroChip BLDC motor control examples, in particular AN857. The key thing here is a combination of software & hardware. What they do, is to use a hardware timer, but generate the pulses in software based on what the timer is doing. This way, the pulse trains can remain synchronised, and timings are quite closely controlled. Sending or receiving a byte with the hardware SPI, only involves testing if the buffer register is empty, and transferring a byte if it is, and you want to send something, then reading the reply. With this type of approach, you can keep the frequencies completely accurate, and with careful writing, the worst that happens is a fractional delay on the falling edge of the waveforms.
_If_ you can accept a situation where the PWM's don't allow you to go to 100% duty cycle, then you can just perform the SPI, and other calculation, in the (say) last 10% of the waveform time, and keep the timings accurate. Effectively you have a small 'null' time at the end of all four cycles, where you perform the other jobs.

Best Wishes
vladtess



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 1:10 pm     Reply with quote

Excuse me for my vague statements.

Here are my goals:

I want to have a PIC18 control a PWM generator (PIC16) via SPI (or w/e for that matter really). That PWM (PIC16) will have to have 4 PWM outputs. The PWMs will drive a variable regulator, so I will need to have a resolution of voltage (0.5V) at least. (output will feed into opamp to amplify voltage) I plan to use Caps on the outputs to smooth the waveform. I need pretty high consistency because I don't want voltage to go up and down in a final project (project: variable supply driven by a PIC)

In this case PIC18 is a master and PIC16 is a slave, I am guessing.
Also Frequency doesn't matter as long as the voltage remains at high enough resolution.

Is this more clear?!! Thanks much you all!!!
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 1:24 pm     Reply with quote

I would just get a PIC with 4 or more hardware PWM or get external multi channel PWM controller chip like the PCA9685, 16ch 12bit.
I made a driver for this just a few weeks ago.
_________________
I'm could be wrong many time's, at least I know what I'm doing Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 2:49 pm     Reply with quote

Or, seriously, if you are just using the PWM's to generate a voltage, use a cheap quad DAC.....

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 2:52 pm     Reply with quote

You're still not really telling us what you want.

From what you're saying, I'm concluding that you need 4 DACs.

What's the required resolution, response time, etc?

Mike

Sorry Ttelmah, you replied while I was typing.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 27, 2012 4:32 pm     Reply with quote

It is easy to use any PWM output with a Sallen Key,
low pass 2nd order filter (rc parts plus an op amp) to provide
up to, a 10 bit voltage output "quasi dac".

The parameters for the filter r/c selection depend on the frequency of the Pwm.

Response time and ripple are all adjustable - within certain limits:
you can't have very fast response and very low ripple at the same time.....

It is VERY easy to make a 0-5v output or a +/-5v output if you can use a dual +/-5 v opamp.

If being VERY crude a simple first order RC low pass will do the same thing passively - except the output impedance of the "dac" can be too high for many uses.

Hence the sallen key filter approach which has a very low source impedance.
vladtess



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 11:23 pm     Reply with quote

Hey guys! I think what someone has suggested is that I need a voltage generator, actually 4 of them. I may end up using DAC for this project. Can some one recommend one for me? I am currently looking at a cheap Quad DAC What do ya'll think?

Can anyone recommend anything that has ISP and resolution above 8bits?

dezso, I cannot find PCA9685 on ebay.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 6:02 am     Reply with quote

Quote:

I want to have a PIC18 control a PWM generator (PIC16) via SPI (or w/e for that matter really). That PWM (PIC16) will have to have 4 PWM outputs. The PWMs will drive a variable regulator, so I will need to have a resolution of voltage (0.5V) at least. (output will feed into opamp to amplify voltage) I plan to use Caps on the outputs to smooth the waveform. I need pretty high consistency because I don't want voltage to go up and down in a final project (project: variable supply driven by a PIC)

Do you really mean voltage resolution of 0.5V out of 5V. That's ~10% or 3bit resolution.

Please give us more detail about what you actually need, otherwise we're second guessing and wasting our time and yours.

Sounds to me you're setting voltages on a four output power supply, OR setting voltage and current limits on two outputs.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 8:10 am     Reply with quote

I'd be thinking of something like the DS3211T 4*10bit DAC's, in one package. I2C interface, and cheap. There are many others.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group