Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

The simplest alternative to multiple PWM channethat is so simple it's not even funny.

Status
Not open for further replies.

Bracer

New Member
I have a circuit containing 4 LEDs that goes from left to right.

It occurred to me to make them fade out slowly.
They could instantly turn on, I have no issue with that, I just wish they would "fade" out.

I go into PWM in PICBASIC, no problem. the PWM command is very easy to use.
But Multiple PWM using the PWM command [controlling multiple channel simultaneously] ? Forget it.

I then search around looking at the codes and complicated ways people go about achieving this.

Then it occur to me, an idea that is sooooo STUPID and SIMPLE, it might just work.
But I don't own an electronic store and I have to preorder things from the net and wait for weeks just to see if something works so I will put my "theory" here.


You know, all those talks about fading out multiple PWMs....what if....what if we just use a capacitor ?
When the idea first struck me, I was like no f**king way.

So I shall ask here....6 volts...PIC Chip...470 ohm resistors and LEDs.

How do you guy suggest a simple capacity could work, how would the wiring be made ? [Parallel connection ?]

Or this is just a dumb idea :(
 
Last edited:
Some times the simplest methods are too obvious to see. :D

Have your output charge up the capacitor then dump through the current limiting resistors to each LED. Thats about a simple as it gets.

For a longer dim out time just use a larger capacitor, try it and see! :)
 
I also don't own an electronics store but I don't wait weeks for parts.
I order from Digikey or Newark online and the parts are delivered the next morning. They aren't even in my country.
 
You could try something like this:
Code:
lum1  CON 255
lum2  CON 100
lum3  CON 50
lum4  CON 30
lum5  CON 5

duration   CON 4

hold  VAR Byte
ht    CON 4
x VAR Byte
stage_it:
 FOR x = 1 TO 3
    FOR hold = 0 TO ht
   PWM 15, lum1, duration
   PWM 0, lum2, duration
   PWM 1, lum3, duration
   PWM 2, lum4, duration
   PWM 3, lum5, duration
   NEXT
  FOR hold = 0 TO ht
   PWM 14, lum1, duration
   PWM 15, lum2, duration
   PWM 0, lum3, duration
   PWM 1, lum4, duration
   PWM 2, lum5, duration
   NEXT
  FOR hold = 0 TO ht
   PWM 13, lum1, duration
   PWM 14, lum2, duration
   PWM 15, lum3, duration
   PWM 0, lum4, duration
   PWM 1, lum5, duration
   NEXT
   FOR hold = 0 TO ht
   PWM 12, lum1, duration
   PWM 13, lum2, duration
   PWM 14, lum3, duration
   PWM 15, lum4, duration
   PWM 0, lum5, duration
   NEXT
 FOR hold = 0 TO ht
   PWM 11, lum1, duration
   PWM 12, lum2, duration
   PWM 13, lum3, duration
   PWM 14, lum4, duration
   PWM 15, lum5, duration
   NEXT

 FOR hold = 0 TO ht
   PWM 10, lum1, duration
   PWM 11, lum2, duration
   PWM 12, lum3, duration
   PWM 13, lum4, duration
   PWM 14, lum5, duration
   NEXT

 FOR hold = 0 TO ht
   PWM 9, lum1, duration
   PWM 10, lum2, duration
   PWM 11, lum3, duration
   PWM 12, lum4, duration
   PWM 13, lum5, duration
   NEXT

 FOR hold = 0 TO ht

   PWM 8, lum1, duration
   PWM 9, lum2, duration
   PWM 10, lum3, duration
   PWM 11, lum4, duration
   PWM 12, lum5, duration
   NEXT
 FOR hold = 0 TO ht
   PWM 7, lum1, duration
   PWM 8, lum2, duration
   PWM 9, lum3, duration
   PWM 10, lum4, duration
   PWM 11, lum5, duration
   NEXT
 FOR hold = 0 TO ht
   PWM 6, lum1, duration
   PWM 7, lum2, duration
   PWM 8, lum3, duration
   PWM 9, lum4, duration
   PWM 10, lum5, duration
   NEXT
  FOR hold = 0 TO ht
   PWM 5, lum1, duration
   PWM 6, lum2, duration
   PWM 7, lum3, duration
   PWM 8, lum4, duration
   PWM 9, lum5, duration
   NEXT
    FOR hold = 0 TO ht
   PWM 4, lum1, duration
   PWM 5, lum2, duration
   PWM 6, lum3, duration
   PWM 7, lum4, duration
   PWM 8, lum5, duration
   NEXT
  FOR hold = 0 TO ht
   PWM 3, lum1, duration
   PWM 4, lum2, duration
   PWM 5, lum3, duration
   PWM 6, lum4, duration
   PWM 7, lum5, duration
   NEXT
 FOR hold = 0 TO ht
   PWM 2, lum1, duration
   PWM 3, lum2, duration
   PWM 4, lum3, duration
   PWM 5, lum4, duration
   PWM 6, lum5, duration
   NEXT

 FOR hold = 0 TO ht
   PWM 1, lum1, duration
   PWM 2, lum2, duration
   PWM 3, lum3, duration
   PWM 4, lum4, duration
   PWM 5, lum5, duration
   NEXT

 FOR hold = 0 TO ht
   PWM 0, lum1, duration
   PWM 1, lum2, duration
   PWM 2, lum3, duration
   PWM 3, lum4, duration
   PWM 4, lum5, duration

   NEXT

NEXT
where "PWM 4," would use the port that your led's are on.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top