Jump to content
Sign in to follow this  
lpdc

Beginner's question : software PWM + Charlieplexing

Recommended Posts

Hello everyone,

 

I am a complete beginner with micro controllers and I chose to get started with a Launchpad as its small price made it pretty much risk-free even if I failed.

 

As a first project, I have set myself the goal to duplicate the following circuit :

http://www.fangletronics.com/2010/02/am ... ndrum.html

The author of this project used a different microcontroller so I thought it would be a nice exercise to try and obtain the same behaviour with a MSP430 included in the Launchpad kit.

Basically, the micro controller drives 2 RBG LEDs and gets imput from 3 potentiometers. A random color is displayed on one of the 2 LEDs and the goal is to match that color on the second LED by adjusting the potentiometers for R, G and B values.

 

My first though was to use the MSPG2231 as it features the ADC required to read values from the potentiometers. Then I started to count the pins and fell off short 1 pin.

I need 6 pins to drive the 2 RGB LEDs and 3 pins for the potentiometers. This amounts to 9 pins but as far as I can understand, I have only 8 pins available to use on the MSPG2231.

 

I stumbled accross a website that describes "charlieplexing", according to this website, I could then use only 3 pins to drive my 6 LEDs.

 

After such a long introduction, my question is : do you think it is possible to achieve my goal by doing both software PWM and charlieplexing at the same time ? I don't really know where to start from and I don't even know if PWM and charlieplexing can even mix together.

I was considering to base the PWM part on the following post :

http://blog.hodgepig.org/2010/09/30/jam-jar-lamp/

 

The other 2 options I considered are :

*Waiting until a launchpad compatible chip with more pins becomes available (the MSP430G2252 for instance)

*Using another IC that could talk to the MSP430 with only a few pins and that would maybe have hardware PWM ports to drive the LEDs directly (does such a component even exist ?)

 

Thank you in advance to anyone who may give me advices/comments and thank you simply to all of you who read this far.

 

LPDC

Share this post


Link to post
Share on other sites
... my question is : do you think it is possible to achieve my goal by doing both software PWM and charlieplexing at the same time ? ...

 

Greetings lpdc,

 

It is possible to do software PWM on a Charlieplexed matrix. If you're using RGB LEDs where the red, green, and blue LED are all contained in a single 4-pin package (common anode or common cathode), you'll need to use four pins for the Charlieplexed matrix in order for the LEDs to fit into the matrix wiring scheme correctly.

 

I wish I could help you with an example or two but my studies are getting in the way of learning the intricacies of the MSP430G2231. The old youtube video shows 32 soft PWM levels on a 5-pin Charlieplexed display of 20 LEDs. The sketch shows a similar design using very high performance BAM (Bit Angle Modulation) driver with gamma correction. I do not have enough experience at this time to duplicate my experiments on the MSP430. Sorry!

 

Cheerful regards, Mike

 

post-1059-135135495644_thumb.png

Share this post


Link to post
Share on other sites

Thanks a lot Mike.

this is good news, even if it take 4 pins instead of 3 to drive the common cathode LEDs, this means that it is still doable with the 8 port microcontroller that came with the launchpad kit.

Now that you mention it, I understand how a common annode/cathode could make the charlieplexing matrix more complex.

 

Now I guess that I just need to do my homework : first try to use simply PWM and ADC to drive a single RGB LED with 3 potentiometers, then try to drive the 2 LEDs without PWM through a charlieplexing matrix and finally try to merge the 2 parts together.

 

This is really a great forum,

 

LPDC

Share this post


Link to post
Share on other sites

Charlieplexing not worth in this case.

1. You can use 2 crystal pins bringing total number of available pins to 10

2. You do not need to Charlieplex, just multiplex, with 5 pins you can control 6 LEDs.

3. Charlieplexing will add complexity since you have to switch outputs to inputs to get hi-z state and cycle through 6 LEDs, with multiplexing, all you do is alternate between 2 sets of 3 LEDs.

Share this post


Link to post
Share on other sites

I was so focused on answering your question I missed the obvious, which Rob pointed out. Thank you Rob.

 

Standard multiplexing would be better. The driver would be a little easier than a Charlieplexed driver. As for the number of pins required, you could probably do it with just four pins, R, G, B, and Column_Select. Perhaps something like the two transistor column driver arrangement in the drawing below (2nd transistor needs a pull-down resistor, not shown).

 

Cheerful regards, Mike

post-1059-135135495654_thumb.png

Share this post


Link to post
Share on other sites

Wow, that is a cool trick driving 2 digits with the same output!

 

I have few more ideas, but I think it's time to start a new thread: "LEDs and displays - tips, tricks, and solutions" :)

 

Also, if you decide to Charlieplex, try something like this:

post-197-135135495659_thumb.png

 

post-197-135135495945_thumb.png

Share this post


Link to post
Share on other sites

You'll notice there's no way to wire those 4-pin RGB LEDs into a 3-pin Charlieplexed matrix. None of the pins will support the common anode or the common cathode for three LEDs (R, G, and B).

 

BTW, if you were to draw a Charlieplexed matrix in a more traditional column and row format it's easier to track signal paths and easier to see how adding column driver transistors will allow lighting multiple LEDs per column.

 

post-1059-135135495925_thumb.png

While we're all brain-storming. How about using a Sony Remote on a single pin instead of three pots on three pins? I did something like this last year for an RGB accent light controller and it worked out quite well. Each individual color has 64 gamma steps spanning the 256 step PWM duty cycle range. Gamma correction improves brightness and color mixing and ultimately reduced the time it takes to make color adjustments with "up" and "down" buttons for each color on the remote (only 64 steps per individual color).

 

More later. Cheerful regards, Mike

post-1059-135135495935_thumb.png

Share this post


Link to post
Share on other sites
Basically, the micro controller drives 2 RBG LEDs and gets imput from 3 potentiometers. A random color is displayed on one of the 2 LEDs and the goal is to match that color on the second LED by adjusting the potentiometers for R, G and B values.

I LOVE that project! I hope you'll post your code and schematics when you finish.

 

1. You can use 2 crystal pins bringing total number of available pins to 10

I think everybody's missing this solution. Keep it simple! If you're not using the external crystal oscillator, you have 10 i/o pins available! This even gives you an extra above your initial requirement. :D

Share this post


Link to post
Share on other sites
You'll notice there's no way to wire those 4-pin RGB LEDs into a 3-pin Charlieplexed matrix.
That is correct, but it's still an option if you use individual LEDs.

 

BTW, if you were to draw a Charlieplexed matrix in a more traditional column and row format it's easier to track signal paths and easier to see how adding column driver transistors will allow lighting multiple LEDs per column (see drawing below).

It is in a column and row format :) Plus this solution does not require transistors (the drawback is only one LED can be on at any time.)

Share this post


Link to post
Share on other sites
BTW, if you were to draw a Charlieplexed matrix in a more traditional column and row format it's easier to track signal paths and easier to see how adding column driver transistors will allow lighting multiple LEDs per column (see drawing below).

It is in a column and row format :) Plus this solution does not require transistors (the drawback is only one LED can be on at any time.)

Forgive me Rob but I'm not following you. Are you saying the solution, whether it's Charlieplexed or multiplexed, doesn't require transistors and you'd prefer to light the LEDs one at a time at a 16.7% duty cycle? Or are you saying your 3-pin Charlieplexed solution doesn't require transistors?

Share this post


Link to post
Share on other sites

Wow, thanks a lot everyone for you input. I do not often use forums in general but I am really impressed with how helpful everyone is here.

 

Charlieplexing not worth in this case.

1. You can use 2 crystal pins bringing total number of available pins to 10

 

I see now. I did not know that the 2 crystal pins could be used as regular input/output pins, I guess that I should have read the specs better instead of just reading the silkscreen print on the Launchpad board.

This is very good news indeed, as a beginner's project it is good that I need only to worry about PWM and ADC without being required to throw some kind of multiplexing in there too.

 

With a total of 10 pins, I will have enough leeway now to drive each LED independently, get the 3 potentiometer inputs and that will even leave me 1 last pin if I want to add in a piezzo buzzer to notify that a player won.

 

Once again, thanks a lot everyone.

 

LPDC

Share this post


Link to post
Share on other sites
I LOVE that project! I hope you'll post your code and schematics when you finish.

 

As I said, it is not my original idea. But I understand you, I also fell in love with the concept imediately. This looks so much like the experiments, carried out at the beginning of the 20th century, that led to the empiric creation of all the colour spaces and metrics on which are based today's colour management (CIE RGB, standard observers, CIE L*a*b* etc..).

 

If I manage to carry out this project to its end, I will definitely post the code and pictures on this forum.

 

LPDC

Share this post


Link to post
Share on other sites
As I said, it is not my original idea. But I understand you, I also fell in love with the concept imediately.

Yes, I was referring to the original project. It was a game for his daughter, I believe. I have it bookmarked somewhere, but I have hundreds of bookmarks, which makes them less than convenient. :?

 

The code to use the two extra pins is:

//select i/o function of pins
P2SEL &= ~(BIT6|BIT7);
//set them as outputs
P2DIR = 0x00 | BIT6 | BIT7;

Then just treat them as other i/o pins. P2.6 is pin 12 ("XOUT") and P2.7 is pin 13 ("XIN"). Yay! Extra i/o! :D

Share this post


Link to post
Share on other sites
...Plus this solution does not require transistors (the drawback is only one LED can be on at any time.)

Forgive me Rob but I'm not following you. Are you saying the solution, whether it's Charlieplexed or multiplexed, doesn't require transistors and you'd prefer to light the LEDs one at a time at a 16.7% duty cycle? Or are you saying your 3-pin Charlieplexed solution doesn't require transistors?

Just the 3 pin solution. Since only one LED is on, we should be fine with what MSP's outputs can source/sink.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...