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

PWM multiple pins?

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



Joined: 16 Jan 2019
Posts: 8

View user's profile Send private message

PWM multiple pins?
PostPosted: Sun Feb 17, 2019 3:42 pm     Reply with quote

Hi again. Back with another dopey newbie question. Please administer 2 aspirins before proceeding, to offset head-to-desk banging. As always, preliminary thanks and apologies up front.

OK, I've got 4 LEDs which must illuminate independently, thus:

1 alone
1 + 2
1 + 2 + 3
1 + 2 + 3 + 4

Basically a bar graph. They're each tied to their own I/O pins. So far, so easy. BUT...I need to PWM dim them as a whole. That is, whatever ones that are illuminated at any given time (in the combinations above) will either be dim or bright. If one is dim, the others will be too. I can see how to #USE PWM and select all 4 pins for the 1+2+3+4 option. Or use one of the PIC's 2 built-in PWM modules to dim any individual LED. But what with me being only marginally distinguishable from a Neanderthal (and only then when held up to a light), I can't fathom how to PWM all 4 pins in different combinations. A little help, please?

I'm veering off into feverish ideas like CWG-ing three of them or PWM-ing them all and forcing low or re-configuring as inputs the ones I don't want on. Only madness lies that way, surely.

BTW, a little furniture polish will take those forehead scuffs right off of your desk. I'll send you a coupon for some if you want.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Sun Feb 17, 2019 4:52 pm     Reply with quote

This can be quite easily implemented with a single PWM. That PWM simply drives an n-MOSFET. The source of that FET is connected to ground. For most applications, a 2N7000 (or 2N7002) should suffice. If you're running your processor at ~3V, then you might need to shop around for a different FET with a lower Vgs on voltage.

For argument's sake, let's say that your 4 LEDs are connected to pins A0 - A3. Port pin - series resistor (for current limiting) - LED anode - LED cathode to FET's drain.

You'll need to embrace the idea of having separate "threads" in your firmware. The dimming "thread" runs continuously, no matter what. Based on a brightness setting, it controls the PWM signal which controls the FET. Max brightness = 100% duty cycle, minimum brightness = 10% duty cycle (this is just for example - you'll have to determine the minimum based on your circumstances). The bar graph "thread" just sets the state of pins A0-A3 based on whatever you're measuring or trying to convey. The "threads" are independent.
Drone601



Joined: 16 Jan 2019
Posts: 8

View user's profile Send private message

PostPosted: Sun Feb 17, 2019 5:20 pm     Reply with quote

Hmm, OK. Thanks for the input. I'll ponder on it while I try to flee from the mighty saber-tooth cats.

As it turns out these are 12V LEDs, each switched by it's own transistor in an array chip, with the PIC driving each base. That hardware is carved in stone. When this design was originated, the LEDs weren't intended to be dimmed. It's a 12th hour commandment from on high. So...I'm still thinking I need to PWM each pin? Or am I still not getting what you're obviously clearly saying?
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Mon Feb 18, 2019 12:11 am     Reply with quote

Odds are the PWM on each pin solution can't be done.
But, it does depend on the PIC involved, and what pins?.
Some of the larger more sophisticated PIC's do support multiple PWM
outputs, but few (if any) allow them to be routed to independent pins.

So hardware solution is almost certainly needed. How this needs to be
done, will depend on your hardware, but (for instance), many of the
driver 'array chips' do have a master 'enable' pin. If yours does, then PWM
control _this_.
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