Fading LED
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Fading LED
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!
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!
- Attachments
-
- LED Fade aug 31.fcf
- (11 KiB) Downloaded 535 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fading LED
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.
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.
- Attachments
-
- LED Fade aug 31.fcf
- (14.5 KiB) Downloaded 651 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
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!
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!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fading LED
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.
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.
- Attachments
-
- LED Fade 03-Sep.fcf
- (14.5 KiB) Downloaded 548 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
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!
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!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fading LED
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
wow Benj, that's really funny! i searched everywhere coz I didn't notice the "=" sign!
Flowcode customer support is SUPER!
Thanks again!
Flowcode customer support is SUPER!
Thanks again!
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
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.
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!
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.
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!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fading LED
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 -
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};
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
Thank you Ben,
Still sound Greek to me but let me digest it first so I can really understand your reply.
Thanks again!
Still sound Greek to me but let me digest it first so I can really understand your reply.
Thanks again!
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
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?
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?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Fading LED
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 209
- Joined: Thu Oct 19, 2006 11:46 am
- Location: Bakewell, UK
- Has thanked: 20 times
- Been thanked: 16 times
- Contact:
Re: Fading LED
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
Regards,
Mark
Go with the Flow.
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
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!
Regards!
-
- Posts: 94
- Joined: Wed Jul 16, 2008 4:39 pm
- Location: Philippines
- Been thanked: 1 time
- Contact:
Re: Fading LED
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
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
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.
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Fading LED
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
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
- Attachments
-
- LED Fade 03-Sep FCV4.fcf
- (16 KiB) Downloaded 324 times
Martin