Page 2 of 4

Re: LED string with PWM

Posted: Sat Aug 04, 2012 5:35 pm
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

Re: LED string with PWM

Posted: Sat Aug 04, 2012 6:15 pm
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

Re: LED string with PWM

Posted: Sat Aug 04, 2012 9:10 pm
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

Re: LED string with PWM

Posted: Sat Aug 04, 2012 9:18 pm
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 9:57 am
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 11:00 am
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 12:46 pm
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 5:39 pm
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 5:54 pm
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 6:26 pm
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

Re: LED string with PWM

Posted: Tue Aug 07, 2012 6:35 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 1:33 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 1:44 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 1:54 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 2:12 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 2:38 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 3:22 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 4:14 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 4:18 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 7:45 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 8:46 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 9:26 pm
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

Re: LED string with PWM

Posted: Wed Aug 08, 2012 9:28 pm
by Enamul
Hi Uli,
No problem, I mean light off time which means PWM pin output ON time..
Enamul

Re: LED string with PWM

Posted: Thu Aug 09, 2012 9:44 pm
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

Re: LED string with PWM

Posted: Fri Aug 10, 2012 1:04 pm
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