PDA

View Full Version : Help! PWM & LED driver


rocky79
Aug 28, 2007, 10:33 PM
I have managed to get the hardware PWM using the pic12f683 at a frequency of 245 hz. It Outputs a nice square wave. However when i interface it to a an Led driver board( switching regulator, the board take a PWm input) the Pwm output from the microcontroller skips a few percent duty cycle when i increase the duty cycle to somewhere close to the max.

Any idea what could be an issue when interfacing a Pwm signal into an Led driver board? I have been struggling with that issue for the past two weeks :(

Thanks in advance

Acetronics
Aug 29, 2007, 03:11 AM
Hi,Rocky

Did you see the little greyed notes of the 11.3.2 Chapter from the Databook ??? ...

it's a known issue of the '683 PWM module ...

Nothing perfect in this world !!!

Alain

rocky79
Aug 29, 2007, 11:44 AM
Hi,Rocky

Did you see the little greyed notes of the 11.3.2 Chapter from the Databook ??? ...

it's a known issue of the '683 PWM module ...

Nothing perfect in this world !!!

Alain

Alain,
The hardware PWM works great by itself. I connected the Pwm signal to a scope
and I would get the perfect pwm.
I saw the greyed notes of the 11.3.2 . The pulse width is never greater than the pwm period.

The problem comes up when i connect the pwm pin to the Led driver board like i described earlier.

AndyOne
Aug 29, 2007, 08:16 PM
rocky79,

The resolution seems to be dependent on the frequency with a lot of LED drivers, the higher the frequency of the PWM dimming signal the bigger the steps, but I'm not too sure why this is the case. It could be something to do with the dimming signal aliasing with the switching frequency in the regulator. It's not an easy one to solve , I've looked into this very problem.

Andy.

andrewm1973
Aug 30, 2007, 01:38 AM
May be Non trivial - but you could sync your PWM with theirs.

Could be as simple as tapping off from their generator to run your alternate clock source pin (if the pic has an alternate pin for the PWM generator).

Could be very difficult if you can't see their clock anywhere.

GeneSS
Aug 30, 2007, 09:37 AM
Rocky:

You might try decoupling the PIC from the LED driver two different ways.

1. If the pin from the PIC is going directly to the driver, you might try inserting a resistor; say 5K-10K in series.
2. If that doesn't work, try decoupling by inserting a capacitor in series. Again, you may have to experiment until you find something that works.

Gene

rocky79
Aug 30, 2007, 11:07 AM
Rocky:

You might try decoupling the PIC from the LED driver two different ways.

1. If the pin from the PIC is going directly to the driver, you might try inserting a resistor; say 5K-10K in series.
2. If that doesn't work, try decoupling by inserting a capacitor in series. Again, you may have to experiment until you find something that works.

Gene


Gene,why does a resistor solve the problem? some explanation will help. Will a buffer help in this case? the only useful thing about a buffer is the impedance transformation. The buffer output impedance will be very low and it can sink more current if needed. But the pic can sink up to 25mA which is plenty.

P:S Thanks guys for all the replies, believe it or not many companies have been struggling with this exact problem including mine ;)

Dan Baldwin
Aug 30, 2007, 11:13 AM
Are you powering the PIC and the LED driver board from the same (5 volt?) power source? When you say "the Pwm output from the microcontroller skips a few percent duty cycle when i increase the duty cycle to somewhere close to the max" do you mean that the PWM output from the PIC goes from 0% to 100% perfectly when the LED driver board is not connected, but will not quite go to 100% when the LED driver board is connected?


Dan

rocky79
Aug 30, 2007, 11:21 AM
Are you powering the PIC and the LED driver board from the same (5 volt?) power source? When you say "the Pwm output from the microcontroller skips a few percent duty cycle when i increase the duty cycle to somewhere close to the max" do you mean that the PWM output from the PIC goes from 0% to 100% perfectly when the LED driver board is not connected, but will not quite go to 100% when the LED driver board is connected?


Dan

Hi Dan,

the pic and the Pwm LED driver run from the same supply which is 28v. The pic has a voltage regulator on board.
The PWM output from the microcontroller works great standalone, but when i connect it to the LED driver board i see some pulse skipping.
It will still go from %0 %100 in either case. It's just that the pulse skipping problem and sometimes a jump in the pwm duty cycle when connected to the Led Driver board

Thanks

rocky79
Aug 30, 2007, 11:46 AM
rocky79,

the higher the frequency of the PWM dimming signal the bigger the steps, but I'm not too sure why this is the case. It could be something to do with the dimming signal aliasing with the switching frequency in the regulator. It's not an easy one to solve , I've looked into this very problem.

Andy.

Hi Andy,

I think that The reason why higher frequency results in a low resolution is the following:
Let's say high frequency is 20 Khz.
That means the Pwm pulse period is 50 us.
therefore the microcontroller has to increment so many steps to get to 50us
on the pic12f683 has minimum timing based on a 4 Mhz oscillator or minimum step time which is 0.25us for a hardware pwm.
That means it takes 200 steps to go from 0 to 100% duty cycle ( equivalent to a pulse width from 0 to 50us)

you can imagine If you have a lower frequency let's 245 hz that means its longer period therefore more steps and better resolution.

I still need to be verified, but i think that's what it is.

GeneSS
Aug 30, 2007, 02:39 PM
Why, I can't tell you exactly. I have been playing with PICs for years and they do funny, unexpected things. Sometimes the output loading can affect the operation even though it appears to be well within the specs of the PIC. The resistor in series simply limits the maximum loading of the output pin. Also, the "pull up" resistors don't seem to always do their job. I had one PIC that would go crazy whenever it was near a fluorescent light fixture. The solution that worked for me was an external "pull up" resistor on 4th output pin on the 12F675's. Even though the 4th output didn't go to anything, leaving it floating with the software pull up didn't work.

Some of these things simply take some experimentation to get them working as desired.

Gene

xorcise
Aug 30, 2007, 04:27 PM
A couple more things to consider:

Do you have the power supply pins decoupled with a small cap at the PIC? This is a cardinal rule with PIC's. Be sure that all unused pins are TRIS'd as outputs. Else, if unused pins are inputs anchor them with resistors high or low. Be sure that MCLR is off or anchored high.

rocky79
Aug 30, 2007, 09:47 PM
A couple more things to consider:

Do you have the power supply pins decoupled with a small cap at the PIC? This is a cardinal rule with PIC's. Be sure that all unused pins are TRIS'd as outputs. Else, if unused pins are inputs anchor them with resistors high or low. Be sure that MCLR is off or anchored high.

I have 0.1 and 10uf cap next to the supply and i made all unused pins an output. I still have some skipping.
but there is one more problem which is on power up I get a quick high (5v) on the HPWM pin and then the Pwm.Even if the Hpwm is not connected to anything.

Problems all along....Hpwm is a tricky business.

rocky79
Aug 30, 2007, 09:49 PM
Why, I can't tell you exactly. I have been playing with PICs for years and they do funny, unexpected things. Sometimes the output loading can affect the operation even though it appears to be well within the specs of the PIC. The resistor in series simply limits the maximum loading of the output pin. Also, the "pull up" resistors don't seem to always do their job. I had one PIC that would go crazy whenever it was near a fluorescent light fixture. The solution that worked for me was an external "pull up" resistor on 4th output pin on the 12F675's. Even though the 4th output didn't go to anything, leaving it floating with the software pull up didn't work.

Some of these things simply take some experimentation to get them working as desired.

Gene

Gene, i did try 4.7k resistor in series and the skipping was even worse, i will try the cap tomorrow and I will see if it helps. Thanks

GeneSS
Aug 30, 2007, 10:38 PM
Gene, i did try 4.7k resistor in series and the skipping was even worse, i will try the cap tomorrow and I will see if it helps. Thanks

Hummm? I'll have to give this some thought

Dan Baldwin
Aug 31, 2007, 12:25 PM
but there is one more problem which is on power up I get a quick high (5v) on the HPWM pin and then the Pwm.Even if the Hpwm is not connected to anything.

Problems all along....Hpwm is a tricky business.

You need to TRIS the PWM output pin as an input (with a pulldown resistor) for at least one PWM period on powerup to keep this from happening.

Dan

AndyOne
Aug 31, 2007, 04:29 PM
Why, I can't tell you exactly. I have been playing with PICs for years and they do funny, unexpected things. Sometimes the output loading can affect the operation even though it appears to be well within the specs of the PIC. The resistor in series simply limits the maximum loading of the output pin. Also, the "pull up" resistors don't seem to always do their job. I had one PIC that would go crazy whenever it was near a fluorescent light fixture. The solution that worked for me was an external "pull up" resistor on 4th output pin on the 12F675's. Even though the 4th output didn't go to anything, leaving it floating with the software pull up didn't work.

Some of these things simply take some experimentation to get them working as desired.

Gene


I used to have trouble like this but then I discovered that the analogue inputs default to analogue and not digital as I assumed. If you define all unused inputs as digital this seems to cure the problem.

Andy.

rocky79
Aug 31, 2007, 05:51 PM
I used to have trouble like this but then I discovered that the analogue inputs default to analogue and not digital as I assumed. If you define all unused inputs as digital this seems to cure the problem.

Andy.

That's exactly what i did Andy, i think there is more to it than that. Sometimes it works fine sometimes it doesn't :confused:

rocky79
Sep 01, 2007, 02:01 AM
Why, I can't tell you exactly. I have been playing with PICs for years and they do funny, unexpected things. Sometimes the output loading can affect the operation even though it appears to be well within the specs of the PIC. The resistor in series simply limits the maximum loading of the output pin. Also, the "pull up" resistors don't seem to always do their job. I had one PIC that would go crazy whenever it was near a fluorescent light fixture. The solution that worked for me was an external "pull up" resistor on 4th output pin on the 12F675's. Even though the 4th output didn't go to anything, leaving it floating with the software pull up didn't work.

Some of these things simply take some experimentation to get them working as desired.

Gene

A 60 ohms resistor worked very well. Thanks Gene!

GeneSS
Sep 01, 2007, 03:35 PM
See, what did I tell you about experimenting. If you want, you can spend many more hours and eventually determine why the 60 ohm resistor worked. Or, you can just accept your empirical solution and move on to the next problem.

Gene

Malc C
Sep 01, 2007, 04:30 PM
I never rely on the internal pull ups in a PIC, and always use 10K external pull-ups or tie un-used pins to ground.

rocky79
Sep 05, 2007, 03:53 PM
How is the pic weak internal pull up useful? Page 34 of the pic12f683 talks about weak pull ups but it doesn't talk about why they are used. One thing it mentions is that :
" Each weak pull-up is automatically turned off when the
port pin is configured as an output."

My guess is: If i use the pin as input i can enable the weak pull up. So that the pin has a defined state.
but by default the GPIO global pull up is disabled when it's an input.So you still need to enable it. I can get away from using external resistor but not sure how well it works.

did i answer my own question? let me know if there is more to it.

Thanks

Malc C
Sep 05, 2007, 04:36 PM
IMO they are what they say they are... weak pull ups. Maybe if they were "strong" pull ups it may remove the need for external resistors. If I'm experiencing problems I either use external resistors as I've stated, or make un-used pins outputs.

The only pin I make sure has external 10k resistor to +ve is MCLR

xorcise
Sep 05, 2007, 06:07 PM
You use the internal pullups when you have a "floating" input, that is, when there is no certain or known logic level on the input pin. Normally-open switches and open-collector optos, for instance, will leave an input pin in an ambiguous logic state when they're not active. It is important when reading the PIC's input that you do so with some level of certainty about the pin's logic state. So it's important to avoid ambiguous logic states on the pin, thus the reason for input pin anchoring.

Pullups and pulldowns are not necessary when the input pin is connected to another device that holds the logic at a definite high or low state.

The internal pullups in a PIC are not resistors but FET's that trickle about 250uA. At 5V that's equivalent to a 20K pullup resistor. Typically, you will see anything from 1K to 10K anchoring resistors used in designs. I've successfully used the internal pullups in designs and 10K where anchoring resistors are required.