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.

computer Christmas lights

Status
Not open for further replies.

MrDEB

Well-Known Member
years ago I assembled a Compurterized Christmas light display but since sold the entire setup.
I recall the SSR or triac boards used an opti-isolator, couple resistors but instead of using a computer, I want to just use a PIC to drive the opti_isolator. Just started looking for leftover plans and parts but figure would ask first.
 
I think the Swordfish modules has an interrupt example. will research.
This sounds better than the way I was headed.
Been tracking down a loose pin in one of the male/female connectors. All is good now. All the strip LEDs come on.
I populated a second board as well. It corrected the messy wires.
 
Has anyone got an example of an ISR in swordfish basic?

Mike.

for a simple, single interrupt:
Code:
interrupt TMR1_isr() 
  // code statements here… 
end interrupt 

// main code to enable interrupt
enable(TMR1_isr)

This should be fun (not what Mike comes up with, but what will follow...)
 
here is a 4x16 bit interrupt Will try out both examples
Code:
// if device and clock are omitted, then the compiler defaults to
// 18F452 @ 20MHz - they are just used here for clarity...
device = 18F452
clock = 20

include "ISRTimer.bas"         

// constant ID to 4 * 16 bit timers...
const
   Timer1 = 0,
   Timer2 = 1,
   Timer3 = 2,
   Timer4 = 3
      
// OnTimer1 event...
event OnTimer1()
   toggle(PORTD.0)
end event

// OnTimer2 event...
event OnTimer2()
   toggle(PORTD.1)
end event

// OnTimer3 event...
event OnTimer3()
   toggle(PORTD.2)
end event

// activate the timer module...
Timer.Initialize

// initialise the timers - refresh every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 50        // 50ms
Timer.Items(Timer1).OnTimer = OnTimer1   // timer event handler
Timer.Items(Timer2).Interval = 250       // 250ms
Timer.Items(Timer2).OnTimer = OnTimer2   // timer event handler
Timer.Items(Timer3).Interval = 500       // 500ms
Timer.Items(Timer3).OnTimer = OnTimer3   // timer event handler
Timer.Items(Timer4).Interval = 2000      // 2000ms, no event handler

// enable the timers...
Timer.Items(Timer1).Enabled = true
Timer.Items(Timer2).Enabled = true
Timer.Items(Timer3).Enabled = true
Timer.Items(Timer4).Enabled = true

// start processing all timers...
Timer.Start

// main program loop...
while true
   // this is a polled timer, not event driven - check to see
   // if it has timeout...
   if not Timer.Items(Timer4).Enabled then
      toggle(PORTD.3)
      Timer.Items(Timer4).Enabled = true
   endif
      
   // background flash LED...
   high(PORTD.7)
   delayms(500)
   low(PORTD.7)
   delayms(500)
wend
 
Let's try to clear up some points:

● What you are trying to do IS NOT POV (Persistence Of Vision). POV is creating an image with moving LEDs that depends on the eyes' relatively slow response time to see a continous image. You may have seen the effect where a message is created from a strip of LEDs on a rotating bicycle where.

● What you ARE TRYING TO DO is multiplex LEDs so many appear to be on at the same time when in fact alternate groups are on from brief periods, making them all appear to be on at once. A multi-digit 7-segment LED display is an example of this. Eight digits may appear to be illuminated, but in fact, only one digit is illuminated at a time. This arrangement is typically done to reduce wiring and circuit complexity. A directly-controlled, always on 8 digit 7-segement LED requires 72 connections. A multiplexed 8 digit display requires 8 segment connections + 8 digit connections = 16 connections. Quite a savings!

These two concepts are similar, but not the same, so let's keep the terminology straight.


The question is what is MrDEB trying to do. A recent comment was "I want it to look like a bunch of LEDs are on at the same time" but the LEDs have also been described as "sprinkles on a birthday cake". Since this thread is called "Christmas Light Controller" and twinkles and sparkles have been discussed in MrDEB's numerous Christmas light projects, perhaps I have confused "sprinkles" and "sparkles" as the goal.

If the plan is to have "a mess of" static "sprinkles",, multiplexing is certainly the hard way to get there....a bunch of LEDs+series-resistors could easily be driven by a single mosfet, or several mosfets if separate colors is desired. Multiplexing the LEDs in this case leads to additional complexity and reduced brightness.*

Since the letters are animated, I assumed that the sprinkles would be too. Individual LEDs flashing on and off, and that appears to be the goal of MrDEB's code.

Some clarity of what's desired would be beneficial to everyone's sanity.


* Yes, when multiplexing with the LEDs only on for a brief period and off for an extended period, the LEDs may be pulsed at higher currents. However, during program development, this will lead to problems. Maybe an LED can be pulsed at 100mA, but can handle only 20mA continuously. If the software hangs leaving LEDs on at 100mA, the magic smoke will be released.

Pardon the long-winded post, but some clarity now will prevent murderous thoughts later.
 
Last edited:
here is a 4x16 bit interrupt
I think Mike was looking for a simple interrupt routine that he could use with a hardware timer, not something like the ISRtimer module that creates a number of software timers, event handlers, etc.

The ISRtimer module is handy, but it's a bit of overkill for setting up a single background timer.
 
Yes, MULTIPLEXING is the correct term Thanks for the clarity of terms.
Was thinking that the posted code in post#263 could be used to cycle through the Rows and columns every 50ms or ??
Yes it looks like overkill.
 
Was thinking that the posted code in post#263 could be used to cycle through the Rows and columns every 50ms or ??

So you want them ALL to appear on steady? No flashing, twinkling, sparkling?

Yeah, you made this way more difficult than it needs to be. With 330 ohm resistors, each LED draws less than 10mA – less than 160mA total. The micro could have easily handled that load.

Anyway....you have columns of 4 LEDs sharing each 330 ohm resistor. If you leave the column lines fixed at HIGH (i.e., +5v), and take exactly one row low (i.e., ground) at a time, each row of 4 LEDs will draw less than 40mA total, each row will be on for ¼ the time and you'll have to keep track of far less stuff.
 
On to another addition to this project--
I have a single white led on the locomotive and am playing with the idea of making the white LED flicker to simulate motion. My understanding of an interrupt is I can have the main code executing plus have the interrupt doing something else. A sort of multitasking?
Have the white LED flicker while the white and red LED strips are sequencing etc.
 
Have a
look here
and at my following posts. What you are trying to do is STILL NOT multitasking. This is what you need to do to get your sequencing letters, flashing LEDs and a twinkling "headlight".
 
I printed out post#269, read through it, reconfigured to my application and thinking about making the columns all on but doesn't configure. too many leds ON so put the post269 on back burner and go with the K I S S method (see code snippet) this appears to work but need to get integrated with rest of the code.
Code:
      //cake sprinlkes colums
             //all colums HIGH
             RED = 1
             WHITE = 1
             BLUE = 1
             GREEN = 1
            
            Row_1 = 0   //led 1 is ON
            delayms(25)//enough to see ON?
            Toggle(RED) // turn off RED colum
            Toggle(Row_1) //turn OFF  row_1
            
                Row_2 = 0
                delayms(25)//enough to see ON?
                Toggle(WHITE)
                Toggle(Row_2)//turn OFF  row_2
                
                    Row_3 = 0
                    delayms(25)//enough to see ON?
                    Toggle(BLUE)
                    Toggle(Row_3)//turn OFF  row_3
                        
                       Row_4 = 0
                       delayms(25)//enough to see ON?
                       Toggle(GREEN)
                       Toggle(Row_4)//turn OFF  row_4
 
blue in the face.jpg
 
Ignoring the obvious, just one suggestion...

When you have something like this:
Code:
            Row_1 = 0   //led 1 is ON
            delayms(25)//enough to see ON?
            Toggle(RED) // turn off RED colum
            Toggle(Row_1) //turn OFF  row_1

When you want to turn something ON or OFF I think it's better to explicitly code it that way, instead of using 'toggle'. Toggle relies on flipping the current setting, so if you ever add something or change the order you can get into trouble.

It's also easier to see what should be going on since you don't have to read through the code and figure out the current state.

just my 0.02
 
I take tumbleweed's suggestion a step further, especially on code I expect to be around for a while.

Usually, I design boards where a low port pin turns on an LED, but there are exceptions. At some point, I may forget that a particular board is an exception, and not understand what's going on when I scan through the code or make a quick change.

LED1 = 0 may usually mean an LED is on, but not always.

To remove any doubt, I create constants for the LED state:

Const LEDOn = 0
Const LEDOff = 1

There's no doubt about the state, no matter which way the LEDs are wired:

LED1 = LEDOn
LED2 = LEDOff

It takes a little more effort to type, but reading the code is so much easier.
 
My comment above is particularly true when others are trying to understand your code. Without seeing a schematic, nobody knows if LED1 = 1 turns the LED on or off. PortB.1 = 1 is worse because nobody knows what it is or what it does.

Adding a comment helps, but making statements clear as possible is even better.
 
YES using TOGGLE has made it difficult to figure out what is going on.
I am trying to get my head around the code that popcorn posted. In the process I am trying to see if using the IRS will not affect the other parts of the code.
Using the IRS timer example in the help file was/am hoping that the background LED could head some light. Seems to be able to do 2 different things at once?
 
I think you mean ISR, unless you're worrying about a tax audit!

Yes, you'll probably want to use an ISR routine.... to multiplex the "segment and row" LEDs. It will just take care of the busy work of keeping those LEDs going.

But everything else? That all has to happen in a program loop with NO DELAY STATEMENTS. You can't delay for a minute between each letter turning on and have anything else going at the same time. DELAY = STOP EVERYTHING and WAIT. You can't be flashing the train headlight while you're waiting for the next letter to illuminate. Everything you want animated comes back to the method I've talked about. A counter is continuously running and you take actions based on the "time" represented by the counter. Turn some on when the counter = 100. Turn it off then the counter = 200. Turn it on again when the counter = 300. You doing things "in the future" based on the counter changing by 100 from the last time you did something.

This has been explained in many of your past threads...and ignored just as many times.....
 
Well let's review my issues with this project

What I am trying to do??


I have a sign I installed LED 12v neon strips (RED & WHITE)


On this sign I have a “cake with RED “100” on top.


Then I have 3 flickering candles on top of the “100” (this for the Ryderwood Cenienial celebration in July.)


Now the problem of incorporating the 16 LEDs that make up the cake “sprinkles” (the 16 LEDs are a 4 x 4 matrix).


The colums labeled RED, WHITE, BLUE, GREEN (anodes) & the rows ROW_1, ROW_2, ROW_3 ROW_4 (cathodes)


To enable an LED one colum is HIGH while one of the the rows are taken LOW


To avoid excessive load on the pic I figure make all the colums HIGH and increment the rows LOW but only one LED per row.


Now while this is sequencing the rows etc. I want to sequence the white led strips (12v controlled using a mosfet)


So basically multitasking
 

Attachments

  • revisions2.png
    revisions2.png
    86.8 KB · Views: 254
No, it's not multitasking. You are attempting to run a set of coordinated events in a loop.

Maybe you'll be done for the bicentennial.
 
My definition of MULTITASKING is doing 2 or more things at one time
been working with the ISR and I think I am discovering how it actually works.
will post a snippet after I get a usable code doing what I want.
I only have 4 LEDs plugged into the PCboard. Contemplating plunging all 16 into the board.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top