Page 1 of 1

Fading LED

Posted: Sun Aug 31, 2008 9:34 am
by mimiyum
I tried the PWM example for fading LED and played around with it. It works fine as it is but I am having trouble fading another LED after the first one.

What I am trying to do is after the end of the Interrupt, I tried to disable it and start another interrupt calling another macro. Flowcode simulation shows it's working but when I download the program to the PIC using the HP-488 pic devt board, only the first LED fades.

Attached is my flowcode program. Please see what is wrong with it.

Thanks!

Re: Fading LED

Posted: Mon Sep 01, 2008 9:25 am
by Benj
Hello

I have made some minor modifications to your program and both LEDs should be working as PWM now. Also the program should give a good indication of how to add more PWM output channels.

Re: Fading LED

Posted: Tue Sep 02, 2008 4:15 pm
by mimiyum
Thanks Benj!

I get it now! I understand how it works. I am able to edit it and add more LEDs and make them fade in and out! I just love it!

To make the brightening or fading smoother, I make brightness increase or decrease between 0 and 255 by increments of 15.

One last question...if I were to keep one LED off (steady at 0) and the other one getting brighter (from 0 going up to 255) I noticed that the LED remains dim. Is there a way to keep this totally off?

Thanks again!

Re: Fading LED

Posted: Wed Sep 03, 2008 9:16 am
by Benj
Hello

Please can you try the attached program. It should allow for the LED to be turned off (PWM of 0) without still glowing slightly. Before the LED was getting switched on at index 0 but now the LED should remain off for index 0 if the preset pwm control is configured to 0.

Re: Fading LED

Posted: Wed Sep 03, 2008 1:43 pm
by mimiyum
Thanks again Benj!

It's working great!

Sorry for sounding newbie...I really am...I can't figure out how you "preset the PWM control to 0" Where was that done?

Thanks for your patience!

Re: Fading LED

Posted: Thu Sep 04, 2008 9:34 am
by Benj
Hello

Sorry by presetting the LED brightness I meant giving the LED PWM variables values

Eg
LED_Brightness = 0
LED_Brightness2 = 255

Before the decision in the timer0 interrupt service routine was making this decision.

LED_Count > LED_Brightness //When LED brightness and LED count are 0 the decision returns false which switches on the LED.

It is now making this decision.

LED_Count >= LED_Brightness //When LED brightness and LED count are 0 the decision returns true which switches off the LED.

Re: Fading LED

Posted: Fri Sep 05, 2008 3:14 am
by mimiyum
wow Benj, that's really funny! :lol: i searched everywhere coz I didn't notice the "=" sign!

Flowcode customer support is SUPER!

Thanks again!

Re: Fading LED

Posted: Mon Sep 08, 2008 3:36 am
by mimiyum
Hello!

Back to the continuing saga of the Fading LEDs...

As we go along, I, together with many other members of this forum are learning a lot. With such interest to learn the many uses of the components of flowcode, I have a new idea. :idea:

I am now thinking that maybe there is a way to use data tables as the source of info for the brightness level.

Lets say the data table (in excel) contains the brightness level per LED and length of time it should be at that level, for example:
Step 1: LED1 Brightness = 0 Time = 100 ms; LED2 Brightness = 100 Time = 100ms
Step 2: LED1 Brightness = 10 Time = 150ms; LED2 Brightness = 50 Time = 50 ms
Step 3: LED1 Brightness = 0 Time = 100 ms; LED2 Brightness = 25 Time = 100ms
and so on...

I imagine this would shorten the program if we already have a long sequence of steps to perform.

Can you give us an example on how this could be done?

Thanks!

Re: Fading LED

Posted: Mon Sep 08, 2008 12:38 pm
by Benj
Hello

It would actually be fairly hard to implement what you are suggesting. Basically the program would have to scan through all the delay values for that particular step, find the shortest delay, perform the tasks that all start at once, perform the delay, perform the specific task and then delay for the other tasks that were started. More problems enter the loop if things need to stop and start while other things are still running.

Its probably going to be a lot easier to do it by hand if you are going to have a fixed sequence of steps.

Another possibility is this.

LED0 - 50%
LED1 - 25%
LED2 - 80%
Wait 50ms
LED1 - 18%
Wait 50ms
LED0 - 50%
LED2 - 80%
Wait 350ms
LED2 - 0%
etc

This could be done via a spreadsheet file fairly easily but it could also be done by Flowcode fairly easily so it seems pointless to add the extra steps. I could be wrong here though.

Finally the third and most efficient way would be to create n+1 arrays where n is the number of LEDs. The arrays must be large enouth to handle all states of the LED.

eg
a[0] = 50
b[0] = 20
c[0] = 6
delay[0] = 100

a[1] = 50
b[1] = 24
c[1] = 26
delay[1] = 500

then you could fill up the arrays at the start of your program, or define them in a C file etc. then just have a main loop to step through the arrays and then wait the correct amount of time.

C code array initialisation -

Code: Select all

char a[] = {0,5,35,240,45,...,0};

Re: Fading LED

Posted: Tue Sep 09, 2008 7:23 am
by mimiyum
Thank you Ben,

Still sound Greek to me but let me digest it first so I can really understand your reply.

Thanks again!

Re: Fading LED

Posted: Tue Sep 09, 2008 8:15 am
by mimiyum
Hello!

Still another question while I'm still digesting your message...

I realize that no matter what kind of setting I use on the pic16f88, the LEDs still do not fade smoothly because it is set on RC. When I program it with target chip as 16f88 lvp-xtal, I use the following settings on the PIC devt board:
S2- XTAL
Jumpers are on LVP

I am using USB Power supply.

All this works well when the progam is run on the pic devt board.

When I transfer the IC to my circuit following the PIC16f88 data sheet using a 18.432 MHz Crystal Oscillator, 15pF on both C1 and C2, 2.2M Rs, the LEDs don't even light up.

Did I miss something here? :oops:

Re: Fading LED

Posted: Tue Sep 09, 2008 9:03 am
by proton
Have you taken MCLR (pin 4) high

Re: Fading LED

Posted: Tue Sep 09, 2008 9:48 am
by mimiyum
Yes. Pin 4 has a 1k to Pin 5 (+)

Isn't this correct?

Re: Fading LED

Posted: Tue Sep 09, 2008 10:22 am
by Benj
Hello

Check the settings in Flowcode under Chip -> Configure. you will need to change the oscillator type to XTAL (simple mode) or HS (expert mode).

1K resistor should be fine for your MCLR pin. Ive also had problems with non ceramic caps on the oscillator in the past.

Re: Fading LED

Posted: Tue Sep 09, 2008 11:03 am
by Mark
I suggest writing a simple test routine to flash an LED or something until you are sure the oscillator is working OK. At high frequencies the length of the leads to the crystal can be enough to give the required vcapacitance and you can sometimes get an oscillator that is not working, working by omitting the capacitors. There is a Microchip Application note on the capacitance values and in practice the devices seem tolerant to over/under driving, as I think the issue that capacitors are supposed to cure is termed.

Regards,

Mark

Re: Fading LED

Posted: Tue Sep 09, 2008 2:01 pm
by mimiyum
Thanks. I'll look into those. A while ago, we discovered that the oscillator is not working at all. We still don't know why. I'm having that checked. Will get back to you once I've checked on those.

Regards!

Re: Fading LED

Posted: Wed Sep 10, 2008 3:28 pm
by mimiyum
Hello!

We tried different crystals and finally got the 4MHz and 8MHz to work. We have to find the right combination. We noticed that the 4MHz causes the LEDs to flicker more than the 8MHz. I guess if we could make the 18MHz or 19MHz crystals work we would finally lose that flicker of the LEDs. The flicker usually occurs at the lower end when the LEDs are made to fade out towards 0.

I will update you on further experiments.

Regards
Mimiyum

Re: Fading LED

Posted: Thu Nov 24, 2011 12:06 pm
by Stanga
Is anyone able to convert the LED Fade 3 example to Flowcode 4? I would like to open and have a look at the code routine, but don't have V3 to do that. ANy help would be appreciated.

Re: Fading LED

Posted: Thu Nov 24, 2011 1:29 pm
by Spanish_dude
You should be able to open Flowcode v3 programs with Flowcode v4.

Re: Fading LED

Posted: Thu Nov 24, 2011 6:19 pm
by Stanga
It won't open in 4.5 for me, which is why I asked.

Re: Fading LED

Posted: Thu Nov 24, 2011 7:10 pm
by medelec35
Hi Stanga,
The reason why it wont open in V4.5 is because the target device file with fcd extension was created in Flowcode3 to set configuration for LVP (Low Voltage Programming).
The same fcd has not made it into FC4, Hence reason for the error that you can see.
Here is the same flowchart converted to V4.

Martin

Re: Fading LED

Posted: Sat Nov 26, 2011 6:49 pm
by Stanga
Thanks Martin :) .