| Swordfish Tutorial - Large LED Array & Brightness Control via PWM |
|
|
| Saturday, 04 April 2009 09:26 | |
|
Pulse Width Modulation (PWM) is extremely handy for multiple purposes, one in particular is controlling high current devices such as DC motors and large LED arrays. PIC's have their limitations, namely 25mA per output, so if you want to drive something a lot larger, using PWM and a high power switching device such as a logic MOSFET will do the job perfectly.
* 1KHz 50% Duty Cycle PWM Signal
The 10 Ohm resistor is very important, as it controls the maximum amount of current that can be supplied to the LED's, without it, the LED's would self destruct themselves when the duty cycle percentage becomes high enough, and you can say goodbye to 12 LED's in a matter of moments...
Now for the source code;
Device = 18F4550 Clock = 8 Config FOSC = INTOSCIO_EC Include "INTOSC8.bas" // import PWM module... Include "PWM2.bas" // local duty variable... Dim Duty As Byte // main program... PWM.SetFreq(5000) PWM.Start1 While true Duty = 0 Repeat PWM.SetDuty1Percent(Duty) Inc(Duty) DelayMS(25) Until Duty > 100 Repeat PWM.SetDuty1Percent(Duty) Dec(Duty) DelayMS(25) Until Duty = 0 Wend You will notice that I am using the PWM2.bas library, this is not a standard library within Swordfish, you need to download it and save it in your \Swordfish\UserLibrary directory. The module can be found here..
|
|
| Last Updated ( Friday, 02 October 2009 08:21 ) |
Whos Online
- andyo
- Jon Chandler
- MrDEB
Forum Activity
LCD / 18F1320 - mrdeb Saturday, 20 March 2010 06:21 - [3 replies]
A 'throw-away" PIC board - mrdeb Thursday, 18 March 2010 06:19 - [32 replies]
Credit Where Credit's Due - jon chandler Tuesday, 16 March 2010 12:01 - [9 replies]
Marching LEDs - mrdeb Saturday, 13 March 2010 22:54 - [7 replies]
USB 8 Channel Servo Controller - andyo Saturday, 13 March 2010 01:19 - [2 replies]
Dedicated Servo Controller - graham Friday, 12 March 2010 17:58 - [0 replies]
Must have....delta temperature glowies! - graham Friday, 12 March 2010 17:31 - [3 replies]
Recent Comments
- 2010-03-20 07:58:45 andyo
Nice. The TAP-28 boards are looking good. When I've had a buzzi...
- 2010-03-19 22:05:12 ozbec...
The author (Hop) suggests to "set the target PIC's configuratio...
- 2010-03-17 22:58:18 Jon C...
Graham, Thanks for fixing the spacing on the array. This is how i...
- 2010-03-17 21:14:34 ASDne...
Thanks Graham, It is a problem with Flowcode because the demo wa...
- 2010-03-17 19:50:32 Graha...
Looks like you've pretty much solved every minor issue that was enc...
- 2010-03-17 11:42:03 Jon C...
The low-cost servo does have one other feature. The origina...
- 2010-03-17 10:56:44 Graha...
I am not familiar with flowcode, though did you try powering the bo...
- 2010-03-15 21:47:55 ASDne...
Hello there, I am still trying to get the LCD to work but I am pro...




I will be trying this in the near future!
Excellent!!