LED string with PWM

For users of Matrix Multimedia Electronics software to discuss projects, circuits and any other electronics concepts.

Moderators: Benj, Mods

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi Enamul.
I did not have any decent Capacitors.
So I put 10uF on the outputs.
The flicker is gone.
The only other option is 100uF 16 volt.
Would there be a risk that they fail?
The LM317 gets quite warm, but I can still touch it fora few seconds.
Do they need a heat sink?
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I did not have any decent Capacitors.
So I put 10uF on the outputs.
The flicker is gone.
It's nice to know that even 10uF worked....
The only other option is 100uF 16 volt.Would there be a risk that they fail?
16v capacitor is risky as if voltage exceed; though very little chance of exceeding for a nominal 12 v battery..By the way, when will you use the battery..is there any chance of using it when battery is in charging state? If yes, in that case it's better to not use 16V capacitor.
The LM317 gets quite warm, but I can still touch it fora few seconds.
Do they need a heat sink?
In my terminology, I always says to my employees if you feel heat more than fever temp(99 deg F) then it will not going to survive without heatsink..
But from your post it seems that they become quite hot and you should use heatsink...
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi Enamul,
Thanks for the info.
Ok I understand what you say.
Heat sink is always better.
Then it gets a bit bulky.
From the output of the regulator it should not get that high because the forward voltage of two LED in series is about 7.5 volts.
Or will there be voltage spikes from the Regulator?
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

From the output of the regulator it should not get that high because the forward voltage of two LED in series is about 7.5 volts.
Or will there be voltage spikes from the Regulator?
In output side, you can easily use 100uF/16V, I don't think any spike possibilities..at least never faced..
I was talking about input of LM317...10uF/25V would work there..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi.
Things are working but now is the challenge of the heat sink for the LM317's
I want move them to point away as far as possible from the LEDs. I was thinking of using a flat piece of Aluminium to make a common heat sink.

I do not have any insulation material Is there a way to improvise make insulation with common materials.
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I was thinking of using a flat piece of Aluminium to make a common heat sink.
Yes, flat piece of aluminium tied with the metal portion of LM3317 will work fine.
I do not have any insulation material Is there a way to improvise make insulation with common materials.
Insulation fiber material normally used for insulation in transformer and electrical insulation where needed..you can manage similar kind of insulation material from hardware shops.
I forget to mention you could use...un-used x-ray film which is quite thick and can work nice..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: LED string with PWM

Post by dazz »

or at a push you could use a colour copier transparency, these are heat stable up to about 225 degrees centigrade, do not use ohp ones as they will melt

regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi,
I found a Pic 12F617 that was lost.
I just wrote this program for the camping light and everything works fine.
Since I use a pull up resistor for the fet, which gets pulled down by a transistor.
Everything is the other way around.
I have attached the code.
I have a remote switch with 3 tactile buttons that work through the ADC
The middle one acts as an on off switch.
The top one acts as an increase switch.
And the bottom one acts as an decrease switch for the duty cycle.
Now I want to be able to save the Duty cycle in the EEPROM
However as soon as I use any EEPROM macro Flowcode gives an error message during compiling.
I am not sure If I do something wrong.
Could someone give an example how to use EEPROM on a Pic12F617
Best Regards:
Uli
Attachments
Camping Light3.fcf
(18.75 KiB) Downloaded 618 times
Last edited by Creative25 on Tue Aug 07, 2012 6:21 pm, edited 1 time in total.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I just wrote this program for the camping light and everything works fine.
Since I use a pull up resistor for the fet, which gets pulled down by a transistor.
Everything is the other way around.
I have attached the code.
I have a remote switch with 3 tactile buttons that work through the ADC
The middle one acts as an on off switch.
The top one acts as an increase switch.
And the bottom one acts as an decrease switch for the duty cycle.
Seems everything works fine.. :)
Now I want to be able to save the Duty cycle in the EEPROM
However as soon as I use any EEPROM macro Flowcode gives an error message during compiling.
I am not sure If I do something wrong.
The compiler is giving error message because PIC 12f617 doesn't have any EEPROM...it's obvious when you try to compile something which is actually not in hardware. We can use external EEPROM but pin number in this chip(I guess you have used all) and price is an issue!
Could someone give an example how to use EEPROM on a Pic12F&17
So it's not possible with PIC12f617..but easily possible with PIC12f675..as it has internal EEPROM.
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Sorry the first
Code was not right.
Because a power failure I lost everything.
And what I posted was the Program at the beginning stage.
Now I uploaded the code I am using.
Do you mean Flowcode cannot use the EEPROM of a Pic12F617?
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

Do you mean Flowcode cannot use the EEPROM of a Pic12F617?
No.. I didn't mean that..it's not a Flowcode issue..if you look at the datasheet of PIC12f617, you can see there is no EEPROM in this ic..

That's why you can't use this IC for EEPROM...FC could be more intelligent by not giving you option to drag EEPROM IC if this chip is selected which I guess we will get soon.
Enamul
Attachments
12f617.PNG
(80.84 KiB) Downloaded 8242 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi Enamul,
Thanks for the Info.
I dont' know why I was thinking That the Pic 12F617 has EEPROM.
So if I need EEPROM the easiest way would be to get another chip.
I see the Pic12F1822 is a but cheaper than the 12F675, is there anyone who has experience with those chips?

I have a question about programming.
On PWM I would like to use a maximum dutycycle of 99% or so.
At the moment the LED's are off I would like to Measure the battery voltage.
I tried to do this by disabling the PWM measuring the voltage of the battery and then enabling it again.
But It gives a flicker. Is there a way to measure exactly at the moment the PWM is low.
Since I use a pull up resistor for the fet, it would actually be exactly when the PWM pin is high.
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I dont' know why I was thinking That the Pic 12F617 has EEPROM.
So if I need EEPROM the easiest way would be to get another chip.
Yes..that's true
I see the Pic12F1822 is a but cheaper than the 12F675, is there anyone who has experience with those chips?
Yes. you can use this chip. I will post the last program in this chip with duty cycle saved in EEPROM.
On PWM I would like to use a maximum dutycycle of 99% or so.
Your switch is controlling duty cycle it reaches to max 254 value which is 99%..
At the moment the LED's are off I would like to Measure the battery voltage.
what really you mean by that...in PWM with 99% duty cycle LED will be almost always on...did you mean when the PWM will not be enabled..
I tried to do this by disabling the PWM measuring the voltage of the battery and then enabling it again.
If you are using PWM to illuminate light..in that case it's not a good idea to do in between...
But It gives a flicker.
That's why it gives flicker...
Is there a way to measure exactly at the moment the PWM is low.
It's a bit tough in 99% PWM and how will you synchoronise?
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi
That was exactly my question.
Is It possible to synchronize with the PWM? I could reduce the duty cycle to maybe 90-95% if necessary.
I was also wondering if it is possible to make a software PWM. And simply turning the Pin on and off every minute or so just to measure battery voltage.
Would that give less flicker?
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

Hi,
That was exactly my question.
Is It possible to synchronize with the PWM? I could reduce the duty cycle to maybe 90-95% if necessary.
One solution could be to use PWM output as input whenever it get low we can read adc for battery...other option is to check TMR2 interrupt which is used in PWM to identify status of PWM output internally...
I was also wondering if it is possible to make a software PWM. And simply turning the Pin on and off every minute or so just to measure battery voltage.
Bit-bang software pwm can be used as well in that case you can identify off-time easily...Are you intended to control duty cycle of PWM still?
Would that give less flicker?
What do you think as source of flicker?
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi Enamul.
Maybe I used the wrong word.
I was wondering if it will be possible to read the ADC fast enough so that the LED will not be off for long enough to notice it.
Still want to control the duty cycle.
I guess to check the TMR2 interrupt would be the easiest way to determine. (I have no idea how to do this)
Since I use a pull up resistor for the fet the LED's are off when the PWM pin is high.
Therefore I would need to measure the Voltage while the PWM pin is high.
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I was wondering if it will be possible to read the ADC fast enough so that the LED will not be off for long enough to notice it.
In 4KHz PWM, with 90% duty cycle off -time will be (1/4000)*0.10us/2 = 12.5us which is not enough for ADC read.
I guess to check the TMR2 interrupt would be the easiest way to determine.
This will be bit more faster...
Still want to control the duty cycle.
It that case hardware PWM is better...but ADC will be a problem
Since I use a pull up resistor for the fet the LED's are off when the PWM pin is high.
Therefore I would need to measure the Voltage while the PWM pin is high.
Ok...I got that point..in that case do you need 10%on and 90%off cycle in pwm output or reverse?
ENAMUL
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

HI
I was thinking of setting the PWM to about 250 or 500Hz
And have minimum on time about 10% according to what is needed to read the ADC.
With the fet it will be inverted.
I always can put a few extra miliamps through the LED's to get the same average. As long as I don't go to the maximum.

Best regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I was thinking of setting the PWM to about 250 or 500Hz
In hardware PWM that much low freq will be tough...but software PWM is fine..
And have minimum on time about 10% according to what is needed to read the ADC.
I understand what you mean..
Ok. I will post some flowcode...
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi Enamul,
I meant PWM frequency of 250 With a clock speed of 4Khz
With software PWM does not have to be slow since one Could just turn the Pin high for the period until the ADC is read.
Also there would be no need for a minimum on time for the pin.
What delay is needed for the voltage on a 5 meter cable to rise to no load voltage?

Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

I meant PWM frequency of 250 With a clock speed of 4Khz
I think you meant 4MHz not Khz for PIC clock...
With software PWM does not have to be slow since one Could just turn the Pin high for the period until the ADC is read.
Yes we can use 250 Hz software PWM with duty cycle controlled...I have started to write FC for that..in off time we will read ADC
What delay is needed for the voltage on a 5 meter cable to rise to no load voltage?
If it's 5V then should wait fraction of ms..its better in that case to raise the voltage to up to +12V to have better response...
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi Enamul
I think you meant 4MHz not Khz for PIC clock...
Yes
It actually should read during on time.
Else I have to wait till I get an PNP transistor.
Of course the battery voltage will be +12volt.
Best regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

Hi Uli,
No problem, I mean light off time which means PWM pin output ON time..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: LED string with PWM

Post by Creative25 »

Hi
I just wonder if it is easier to just use the Comparator
Since I just need to be able to read about three different threshold voltages.
Would that be faster and easier?
Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED string with PWM

Post by Enamul »

Hi Uli,
Sorry for late response..
I just wonder if it is easier to just use the Comparator
Which comparator you are thinking to use? The comparator that is built-in PIC or any external comparator IC like LM324 or LM358?
Since I just need to be able to read about three different threshold voltages.
Would that be faster and easier?
If you use any external comparator, in that case you just need to check an input in light off duration which will take couple us only..so definitely much faster than adc read.
I have managed to make one simple software PWM with 250 frequency...with normally high output at RB5 which will decrease duty cycle with increment in UP switch..decrement with down sw..
I know you want to do both using one sw..I will post that soon..
Enamul
Attachments
LOW_FREQ_PWM_I.fcf
250 Hz using PIC16f877a for test
(18.18 KiB) Downloaded 525 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply