Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 25th June 2008, 01:34 PM   #1
Default BoostC Charlieplexed PWM 32

Would anyone care to study or critique my very first BoostC program?

It's a novelty 12F683 program that does 32 PWM brightness levels per LED in a Charlieplexed matrix of 20 LEDs. The refresh rate is 62.5 Hz and each LED duty cycle can be varied from 0% to 20% in thirty two 0.625% (100 usec) steps.

The picture doesn't seem to show the smooth transitions I'm seeing. In fact you can hardly tell those are green LEDs.

Mike



Attached Files
File Type: c 12F683_Test_v1.c (7.3 KB, 212 views)

Last edited by Mike, K8LH; 25th June 2008 at 01:44 PM.
Mike, K8LH is online now  
Old 25th June 2008, 02:15 PM   #2
Default

Very nice indeed. Managing 32 PWM levels on a 4*5 matrix completely in software is impressive. And a good refresh rate as well.

Code wise, I like the way you lay it out, especially the comments. I hate the recent trend of putting comments within a procedure and in the code space ( and on every other line). Your full width comments before and right side comments during a procedure (and initialisation) should be mandatory.

I also like the neatness of the end_of_period and end_of_cycle checks. I'm assuming that you couldn't find a way to avoid the asm - the shift at end_of_period looks like it should be C able.

The only thing I can see that isn't required is the clearing of PIE1.

Overall an excellent example. A++.

Mike.
Pommie is offline  
Old 25th June 2008, 02:50 PM   #3
Default

WOW!!
Yes, I must agree with Mike(Pommie); this is very well done, and your source is so well commented and very easy to follow.

Mike(Mike, K8LH,) I think you should have an award for getting the most punch out of the least resources!!
BeeBop is online now  
Old 25th June 2008, 06:24 PM   #4
Default

That's really impressive. I was considering doing something similar with the 8x8 square LED blocks from Futurelec to display patterns, I hadn't considered PWM to dim the lights. I might have to try on a much smaller scale with the Junebug LEDs tonight

What's the board you are using, it looks like a nice size for prototyping or small projects.
edeca is offline  
Old 25th June 2008, 06:32 PM   #5
Default

Mike: I like it
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)

Last edited by 3v0; 25th June 2008 at 06:34 PM.
3v0 is online now  
Old 25th June 2008, 08:02 PM   #6
Default

Gentlemen,

Thank you all for the nice comments.

Pommie,

I'm still trying to come up with optimized C code to replace those remaining few assembler sections. The C code equivalent for those rlf instructions uses two more words and cycles. I guess I'm being a "tightwad" (grin).

edeca,

That's a small Radio Shack proto' board made of phenolic or similar material.

Regards, Mike
Mike, K8LH is online now  
Old 26th June 2008, 12:55 AM   #7
Default

Quote:
Originally Posted by Mike, K8LH View Post
What is that second "jack" thing - lower left? Is that your programming connector? Better lighting and a second 3/4 angle shot would be good.

Cool little doohickey! You should do a YouTube movie so we can see it in action.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 26th June 2008 at 12:58 AM.
futz is offline  
Old 26th June 2008, 01:59 AM   #8
Default

I use 3.5mm sterio jacks on proto' boards for TTL232 connections.

Sorry about the picture. I tried several different shots, lighting, shutter speeds, etc., trying to show off the smooth fade from about 10% to 100% brightness but never did come up with a good shot. I even tried it with red LEDs (below) but "no joy" as the color is all washed out.

I don't have any video equipment for YouTube. Sorry.

BTW, thanks for turning me onto BoostC. Writing C code for 12F' and 16F' devices for the first time is a blast.

Regards, Mike
Attached Thumbnails
BoostC Charlieplexed PWM 32-pwm-32-red.jpg  
Mike, K8LH is online now  
Old 26th June 2008, 02:10 AM   #9
Default

The green LEDs look good on my monitor. The brighter ones are a little washed out but the effect is perfect.

Photography is a lot better than I would normally do.
mneary is online now  
Old 26th June 2008, 03:34 AM   #10
Default

Quote:
Originally Posted by Mike, K8LH View Post
I don't have any video equipment for YouTube. Sorry.
You have a digital camera!?!? Never seen one yet that won't do video. That's how I do mine.

Quote:
BTW, thanks for turning me onto BoostC. Writing C code for 12F' and 16F' devices for the first time is a blast.
Kewl, huh? And C code is very very portable from PIC to PIC. I wrote code for 16F88 and with only minor changes ran it on 18F248.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 26th June 2008 at 03:35 AM.
futz is offline  
Old 26th June 2008, 04:13 AM   #11
Default

I'll grab the camera docs' tomorrow and see what it says about a video mode.
Mike, K8LH is online now  
Old 26th June 2008, 07:53 AM   #12
Default

Hi Mike, K8LH nice work.

I have a problem.Can you tell me whats the meaning of "Refresh rate is 62.5 Hz"?

I did a small matrix 5X7 recently.I can light up any LED on that.But I don't know what is Refresh rate?
Suraj143 is offline  
Old 26th June 2008, 09:19 AM   #13
Default

Quote:
Originally Posted by Suraj143 View Post
I have a problem.Can you tell me whats the meaning of "Refresh rate is 62.5 Hz"?

I did a small matrix 5X7 recently.I can light up any LED on that.But I don't know what is Refresh rate?
The lights are multiplexed (charlieplexed actually) meaning that the code needs to quickly light each segment lots of times per second to give the impression that they are on. In addition the fading means that some need to be on for longer than others, a longer 'duty cycle'.
edeca is offline  
Old 26th June 2008, 11:43 AM   #14
Default

Hi Siraj143,

In multiplexed displays the refresh rate is the number of times per second that an LED is lighted or refreshed. A refresh rate of less than 60 Hz may be perceived as flickering.

Another important factor in multiplexed displays is duty cycle. That's the total amount of time an LED is lighted during a given period expressed as a percentage or a fraction. Duty cycle affects peak and average current requirements to light a display to full brightness. In this case for dimming or fading an LED, we use PWM to change the duty cycle without changing the peak current supplied to the LEDs and this has the effect of changing the "average" LED current and brightness level.

Mike

Last edited by Mike, K8LH; 26th June 2008 at 11:54 AM.
Mike, K8LH is online now  
Old 26th June 2008, 12:10 PM   #15
Default

Quote:
Originally Posted by Mike, K8LH View Post
Hi Siraj143,

In multiplexed displays the refresh rate is the number of times per second that an LED is lighted or refreshed. A refresh rate of less than 60 Hz may be perceived as flickering.

Another important factor in multiplexed displays is duty cycle. That's the total amount of time an LED is lighted during a given period expressed as a percentage or a fraction. Duty cycle affects peak and average current requirements to light a display to full brightness. In this case for dimming or fading an LED, we use PWM to change the duty cycle without changing the peak current supplied to the LEDs and this has the effect of changing the "average" LED current and brightness level.

Mike
Hi thanks for the explanation now I understood.If I flash an LED 50 times per second it will show us a flickering.But if I flash it 60 times per second it will stay like a charm without noticing any flicker.

OK for one bulb is ok I understood.

Let say I have multiplexed 5 columns so I have called 5 delays in between them.

In this situation the refresh rate is given to the whole multiplex routine (5 columns) or to a single column?
Suraj143 is offline  
Reply

Tags
boostc, charlieplexed, pwm

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
BoostC question.. AddressOf Mike, K8LH Micro Controllers 8 25th June 2008 12:20 AM
LCD degree symbol with sprintf (BoostC) futz Micro Controllers 29 5th June 2008 05:19 AM
math.h and lib for BoostC? futz Micro Controllers 3 31st March 2008 06:29 AM
Charlieplexed code segment for the Cricket Thermostat William At MyBlueRoom Micro Controllers 2 14th March 2006 05:12 PM
My PIC Projects Site NEW (includes 2 Charlieplexed Display) William At MyBlueRoom Electronic Projects Design/Ideas/Reviews 0 28th February 2006 02:31 PM



All times are GMT. The time now is 12:21 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker