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 CCS Technical Support

8ch PWM

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

8ch PWM
PostPosted: Sun Aug 07, 2011 1:34 am     Reply with quote

Hi Everyone,

Quick question. I need to control 8 0-10v dimming ballasts. Is there a free running PWM driver out there with 8 individual outputs, or does any PIC have 8 individual channels? I know the dsPIC have 8 outputs, but you can't have (as far as I can tell) have 8 different duty settings.

OR do you think it is a better idea to do this with a digital pot?

Thanks

Mark
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Sun Aug 07, 2011 2:24 am     Reply with quote

NXP, do an I2C controlled PWM chip with I think 16*12bit channels. PCA9685. It is designed as an LED controller, but could be used fairly easily for other applications. Texas do a similar chip as well (TLC5940), but this has current sink outputs, which might be harder to interface.

Might well be simpler just to use a couple of PIC's. The PIC18F2331 for example, has the four channel power control PWM module, offering up to 14bit resolution. Two of these as I2C slaves, and "Robert's your parent's brother".

Best Wishes
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Sun Aug 07, 2011 4:09 am     Reply with quote

EXCELLENT! That is exactly what I need. It even can even have pins configured as ON\OFF only. Perfect.

Now just to write the driver.

Thanks

Mark
temtronic



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

View user's profile Send private message

PostPosted: Sun Aug 07, 2011 5:37 am     Reply with quote

Depending on the speed you require (and other features..)

You could do it with just one PIC and create a software 8 channel PWM.

I've run 16F84s this way for(sigh) decades.....
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 22, 2011 5:21 am     Reply with quote

I think I have lost my mind here (and 2 PCA chips).

I have written the driver (took me 10 min, which I was quite happy about) and it works like a charm.

However -- I would like to use it with a PNP transistor as I need to push 0-10v thought it. I have made it work with a NPN transistor, but can't work out how to connect a PNP. The PCA has been configured in open drain mode, so I would of thought I can just connect the base leg of the PNP to the PWM pin, and bob's your mum, 0-10v output. Each time I do it, all I end up doing is blowing the PWM driver (Lucky the chip has 8 of them).
If I put the resistor in the base leg, the transistor always stays on, and I get 10v out of it.

I am no superstar when it comes to transistors, but have tried for the last few days to get this going and cant seem too work out what I am doing wrong. Has anyone got a circuit for a PNP PWM driver, or any hints on what I am doing wrong?

Thanks
temtronic



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

View user's profile Send private message

PostPosted: Thu Sep 22, 2011 5:33 am     Reply with quote

One (easy) way is to have the NPN drive the PNP. I've done that for almost 30 years using MPSA92/93 transistors to control +60 volt logic lines. Cost is maybe 5 cents...

Another is to use an optocoupler(4N26 ?).This one also allows you to isolate the power supplies,if necessary.

I've also used opamps (in diff mode) to 'level shift / polarity control' in telecomm circuits...

so grab a breadboard and see which works best for you !
(wished I'd invented those things.......)
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 22, 2011 5:36 pm     Reply with quote

thanks Temtronic,

Yep, I also thought of NPN-PNP back to back. This will, and has in this case, worked. I was just wondering if there is a cleaner way of doing it. The datasheet says you can use a PNP, I just don't know how.

Sounds like I need too blow some more PCA up Smile

Thanks
freesat



Joined: 08 Feb 2011
Posts: 32

View user's profile Send private message

do PWM with software, its easy and doesnt need components
PostPosted: Thu Sep 22, 2011 5:41 pm     Reply with quote

Hi, do a PWM with software using an interrupt, its easy and u dont need buy more chips, works great with me on a 8 pwm channels on 16F628 runnibg at 4Mhz.

im tested it only with DC PWM for Leds and Motors, at AC PWM im working, but is dificult without have a scope.

see an example.
Code:

inside interrupt...
// PWM Software ( 0..255 ) 
   if ( pwm_counter < DMX_Canal[canal_red] ) { output_high(PWM_RED_PORT); } else { output_low(PWM_RED_PORT); }
   if ( pwm_counter < DMX_Canal[canal_green] ) {output_high(PWM_GREEN_PORT); } else { output_low(PWM_GREEN_PORT); }
   if ( pwm_counter < DMX_Canal[canal_blue] ) { output_high(PWM_BLUE_PORT); } else { output_low(PWM_BLUE_PORT); }       
   if ( pwm_counter < DMX_Canal[canal_ambar] ) { output_high(PWM_AMBAR_PORT); } else { output_low(PWM_AMBAR_PORT); }       
   if ( pwm_counter < DMX_Canal[canal_white] ) { output_high(PWM_WHITE_PORT); } else { output_low(PWM_WHITE_PORT); }
   if ( ++pwm_counter == 256 ) { pwm_counter = 0; }
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 22, 2011 8:31 pm     Reply with quote

Hi Freesat,

Thanks for that, but I can't do software. The pic is quite busy as it is.

I don't mind using the extra hardware, and it is working fine. I just want to connect a PNP transistor to the PCA.

I have now also tried PNP-NPN Sziklai pair, but can't seem to get 10v out. It only gets to about 4.8 then stops.
I think I might just use a voltage doubler.

Thanks

Mark
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri Sep 23, 2011 3:45 am     Reply with quote

Markdem wrote:

I don't mind using the extra hardware, and it is working fine. I just want to connect a PNP transistor to the PCA.

I have now also tried PNP-NPN Sziklai pair, but can't seem to get 10v out. It only gets to about 4.8 then stops.
I think I might just use a voltage doubler.
Mark


It sounds as though you are falling into a basic IC trap. Sad

Unless specificially designed for extended voltage ranges, most ICs have clamp diodes on all inputs and outputs. These diodes are not specific circuit elements as such, they are inherent to the IC/semiconductor structure. Body diodes on power FETs are much the same: they are part of the way the devices are made. For inputs these clip/clamp diodes can give useful protection, by ensuring the input cannot easily go beyond about 0.5V above the supply or -0.5V below ground. The same goes for the output, which in this case means that despite having an open drain output the outputpin cannot rise to 10V, it stubbornly refuses to go more than 0.5V or so above the ICs supply voltage. This is a big issue when it comes to systems with multiple supply rails and it requires some sort of level translator to cope with outputs from one supply domain driving inputs at different supplies.


This would be easier if I had a schematic editor available to me, as I could show you the circuit configuration. As I don't I'll just have to describe it.

I presume what you are trying to do is hot side switch a 10V supply to whatever it is you are driving. In this day and age I'd automatically do this with FETs but the same principles go for bipolar transistors. Only the voltage levels (and drive currents) are different. What you probably need is an NPN run common emittor driven by the IC output via a suitable base resistor of course (not needed if using logic level n-channel FET). You need a split collector load for the NPN. The upper resistor of the load is connected between the +10V and the base of the PNP. The resistors should be sized so that you have about 0.7V across the upper resistor when the NPN is in saturation. With FETs its a lot simpler as you dont have to worry about gate drive current, nor over driving the PNP. You might still be wondering why you have to have the NPN at all when the IC could have done it for you. Well, it can't as it cannot deal with the voltage that may be on its collector when its off due to that diode. Its output cannot rise above the Vcc + 0.5V. The external NPN's collector, being a single discrete device rather than in an IC, can rise as high as its Vce max rating will allow. So, when it is off, its collector voltage rises to around 10V, pullerd up by the resistors. This reduces the base-emittor voltage on the PNP to significantly less than 0.6V and the PNP turns off.

All this is very basic transistor stuff. Its treating the transistor as a simple switch, on or off, nothing more. Its even simpler with FETs.

By the way these pesky diodes cause trouble with PICs analogue inputs. On all the PICs I've used (16F and 18Fs) if you try to drive the analogue inputs beyond the rails, which is easy to do with +/-12V supplied op-amps for example, then all ADC readings will be severely corrupted. If you try to drive them below ground you'll very likely damage the PIC in quite subtle (as in difficult to detect) ways. We've had temperature circuits messed up by our CEMs: they had a new BOM from us but only changed one side of a double sided PCB. The result was the the temp cct was hopelessly unbalanced and tried to drive the PIC analogue input to -10V. The op-amp got hot. The PIC seemed to work at first glance... but in fact its ADC readings were total screwed up. That wouldn't have been so bad, had not the replacement of the PIC been not *quite* perfect, leaving the SPI CLK out on one part intermittent. That meant that last Friday I had to "debug" an RF module.... the PIC couldn't drive the DAC that set the bias to the RF Gan power FETs. No bias means the FET conduct hard. As the PSU is quite happy to deliver 60A continuously and around 250A for short periods... well, there was quite a blow up. Two FETs had blown up, at £600 each. Last thing on a Friday..! Evil or Very Mad

RF Developer.
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Sun Sep 25, 2011 5:09 pm     Reply with quote

Thanks for that RF. That is what I think was going one too. Still a little confused as to why the datasheet is saying that I can use a PNP.

No matter, I have gone down the voltage doubler path. Works well and smooths out the PWM perfectly too.

Thanks for all the help.

Mark
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sun Sep 25, 2011 5:28 pm     Reply with quote

If you mean the 0-10v DC dimming controls so long as you dont need to update each one every FEW milliseconds -
and it is a CLEAN DC value for each control ( my but thats an OLD dimmer system ;-)))

As i think you mean
then, i did this YEARS ago as an early PIC project - first on a 16f877
and OP AMPS are your friend too you know ;-))

This can actually be done with a SINGLE PIC PWM channel - and a second order, fast settling SK LP filter - one or more DG406's and and a bunch of
of +12v/-5V fet input OP amps - configured as S&H buffers ( the DG406's charge - discharge 2200 PF metal film caps and you simply step thru your
dimmer values while addressing the right mux channel using an ancient NE5532 - one half as the PWM SK filter to dc circuit and the other half to charge the 2200pf caps through the MUXES as the capacitor charge control amp.

With 2200 PF GOOD Metal film caps and TL074 quads - i could go for several MINUTES without having any noticeable droop in the stored dimmer values. The pic program would update ALL dimmers when ANY was changed and also update every appx 60 secs using an 8 mhz pic clock. This also takes VERY little pic overhead to do to.

BTW: the time per channel for charge to 'take' was allocated very nicely at just 16 msec each SETUP ( + 10 ms filter settling)

Who says the answer has to be all digital ??
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Sun Jul 14, 2013 2:14 pm     Reply with quote

Dear asmboy,

I just read all the datasheet of the multiplexer you used and seems that the MUX you used does not hold the value of the dimmer. What I can't understand in your design, where you put the 2200uf capacitor? What is the voltage used? You need to wipe the values of all the channels everytime to keep the dimming settings?

Thanks
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sun Jul 14, 2013 4:11 pm     Reply with quote

Quote:
this can actually be done with a SINGLE PIC PWM channel - and a second order, fast settling Sallen Key LP filter - one or more DG406's and and a bunch of of +12v/-5V fet input OP amps - configured as S&H buffers ( the DG406's charge - discharge 2200 PF metal film caps and you simply step thru your dimmer values while addressing the right mux channel using an ancient NE5532 - one half as the PWM SK filter to dc circuit and the other half to charge the 2200pf caps through the MUXES as the capacitor charge control amp.

With 2200 PF GOOD Metal film caps and TL074 quads - i could go for several MINUTES without having any noticeable droop in the stored dimmer values. The pic program would update ALL dimmers when ANY was changed and also update every appx 60 secs using an 8 mhz pic clock. This also takes VERY little pic overhead to do to.

BTW: the time per channel for charge to 'take' was allocated very nicely at just 16 msec each SETUP ( + 10 ms filter settling)


the reason the MUX does not hold the value is because it is not supposed to !!!

the METAL film CAP you charge thru the MUX - using the OUTPUT of the SK filter is what keeps the voltage ......
you don't know what i was talking about circuit wise, do you ??

you need some analog circuit skills to understand what i described in the OP........

a primitive version:
http://www.daenotes.com/sites/default/files/field/image/sample-hold-circuit.png

where the FET represents one channel of the MUX
and this is the PWM to DC circuit with appropriate time constants for YOUR app

http://en.wikipedia.org/wiki/File:Sallen-Key_Lowpass_General.svg
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