| 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
- MrDEB
Forum Activity
simulation program - mrdeb Thursday, 11 March 2010 22:52 - [0 replies]
MARCHING ledS - mrdeb Thursday, 11 March 2010 19:13 - [3 replies]
REALISTIC LED candle flicker - mrdeb Wednesday, 10 March 2010 05:48 - [0 replies]
the LCD demo hello world - mrdeb Wednesday, 10 March 2010 05:41 - [29 replies]
USB problem - jon chandler Tuesday, 09 March 2010 11:31 - [3 replies]
Servo Module - andyo Tuesday, 09 March 2010 03:39 - [3 replies]
pic to ps2 communication - roshan Friday, 05 March 2010 01:30 - [7 replies]
Recent Comments
- 2010-03-11 21:03:32 Jon C...
If this wasn't a class project that had to be done on a PIC16F690 u...
- 2010-03-11 15:30:06 uuu
I am going to send two data from ADC to USART(async mode) to serial...
- 2010-03-05 13:24:23 mrpse...
I was thinking of battery with powered routers or powered for every...
- 2010-03-05 12:17:40 andyo
50 rooms - wow. The XBee modules are very easy to use but I'm not ...
- 2010-03-05 11:46:37 mrpse...
Thanks AndyO. What I have to do is design a device to monitor temp...
- 2010-03-05 03:08:58 andyo
The circuit used for the remote sensor can be found here: [url]http...
- 2010-03-04 07:19:06 renno
plz i need help do u know from where i could download it or how cou...
- 2010-03-04 07:16:05 renno
hello everyone i'm trying to finish my final project and i want to ...




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