Pwm dimmer strip led

Nandino

Active member
Salve buon giorno,
Uso La funzione pwm su pic 08m2 per comandare un irf530 che a sua volta comanda una strip led 12v 10w
Mi serviva una rampa di accensione più lenta possibile
seguendo l esempio del manuale l accensione è lenta ma ad ogni step c è un sfarfallio sui led cioè si vede come uno scatto..... Come posso fare per eliminare questo scatto?
sol
 

Nandino

Active member
Hello good morning,
Use the pwm function on pic 08m2 to control an irf530 which in turn controls a 12v 10w led strip
I needed an ignition ramp as slow as possible
following the example of the manual, the ignition is slow but at each step there is a flicker on the LEDs that is it is seen as a click .....
Thank you thank you for any replies
 

inglewoodpete

Senior Member
You haven't posted any code or your circuit, so it is difficult for forum members to know what could be improved.

Points to consider when a smooth transition is required are:
  1. Use a 10-bit duty value (Ie values = 0 to 1023) in the setup command (PWMOut) - this gives the smallest steps between values
  2. Ensure the period value is as long as possible to give the lowest possible PWM frequency (Period = 255). This will improve the efficiency of the MOSFET due to the large gate capacitance.
  3. Always use PWMDuty command to change brightness of the LED
 

tmfkam

Senior Member
Some years back I wrote some code for generating some "slow" PWM, around 150Hz though the frequency could be varied. I also wrote some ramp up and down routines. I'm sure these simply calculated the on and off time periods required then generated a few cycles of PWM before checking if there were any changes required to the duty cycle or frequency then generating another few cycles and so on. This could ramp up and down very smoothly. The built in routines were less flexible for what I needed. If you wanted to see my approach I could have a look and see if the code made the transfer from macOS to W10.
 

Nandino

Active member
sorry , you have right
For b1 = 0 to 255 step 1
PWM 2,b1,1023
Next b1
high 2
wait 2
end
yes, i didn't use the pwmduty maybe that's the problem
or maybe it can be the 12k pulldown resistor between pin2 and ground?
tonight I connect pin 2 directly to the gate of my irf530 and then I also try the pwmduty
very kind in the meantime, as soon as everything is done, I am writing to you
thanks for everything
 

lbenson

Senior Member
IRF530 may not work as you wish with logic level voltage (or maybe it will, for your use, I don't know for sure). "Logic Level" mosfets IRL540 and IRL520 definitely work for PWMing with a PICAXE.
 

AllyCat

Senior Member
Hi,
For b1 = 0 to 255 step 1
PWM 2,b1,1023
b1 is changing the period (frequency) of the PWM not the Duty Cycle !
Also, the frequency may be too high for a simple FET drive, and you should use PWMDUTY not PWMOUT to avoid "glitches" at the change of Duty Cycle.

Therefore, try the following:
Code:
PWMOUT PWMDIV16 , c.2 , 255 , 0        ; 250 Hz should be fast enough.
FOR w1 = 0 to 1023                     ; Can use STEP {n > 1} to change faster
   PWMDUTY c.2 , w1                    ; Note that this instruction takes many ( < 10) ms to execute
   PAUSE 10                            ; ~100 steps / sec , i.e. ramp in 10 seconds.
NEXT
Cheers, Alan.
 

Nandino

Active member
Ooookkkk now works fine, it was the pwmduty function we needed
I didn't understand one thing though, in the first line
Pwmout, pwmdv16, 255.0
What is 0 for?
Thanks everyone for the help
 

AllyCat

Senior Member
Hi,

From the Command Reference, the "0" is the initial Duty Cycles (i.e. OFF) until it is replaced by the value of w1 inside the loop.

Normally, the LEDs (or a typical motor) need a significant voltage before there is any "activity" (brightness or rotation) so a better template for the program might be:
Code:
Symbol Start_Duty_Cycle = 200                             ; 200 / 1000 = 20% Duty Cycle , e.g. 1 volt @ 5 v supply
Symbol End_Duty_Cycle = 1000
Symbol Period = 250 - 1                                   ; 4 MHz / (4 * 250 * 16 ) = 250 Hz should be fast enough

PWMOUT PWMDIV16 , c.2 , Period , Start_Duty_Cycle
FOR w1 = Start_Duty_Cycle TO End_Duty_Cycle               ; Can use STEP n  {> 1} to change faster
   PWMDUTY c.2 , w1                                       ; This instruction may take many ( ~ 10) ms to execute
   PAUSE 10                                               ; ~100 steps / sec , i.e. ramp in > 10 seconds.
NEXT w1
Cheers, Alan.
 
Top