Strange PWM Behavior

In my RC car project, I require that the PWM signal be changed often, but I seem to be having an issue when I try to set PWM pulse waves in quick succession. If, for example, I try to set PWM 8 with

Then, any faster than 50ms later…

…The resulting pulse wave will fluctuate then settle on the new timing. This “flutter” causes my electric speed controller to freak out.

Basically, I need to be able to change the signal faster than 50ms, but it doesn’t look like I can reliably do that with this approach.

Any ideas?

Do you think you are experienced enough to use register access to control the PWM registers directly?

I think the problem is that we change the PWM hardware immediately where we should wait till last pulse is finished?

Yep, I probably should be using register access to do this. I’ll have to look in the manual.

As for cutting the pulse immediately, that’s exactly what I expected after seeing the scope trace. IMO, I should wait until the last pulse. Cutting a pulse midpoint like that can cause a screwup with whatever you are trying to control. In my case, the ESC will freak out.

We will be looking into this soon.

Wow Gus, you’re fast. :o Thanks!

Were you able to measure this on your scope Chris? Can you explain “flutter” any further?

We looked at in scope, the signal looks fine and changes correctly,
If you are able to find something or solve it using register access, please let us know.

If I am recalling correctly the update rate for one servo channel is supposed to be about 50ms (or maybe it was 20ms?). This resulted in a fixed number of channels that could be controlled with one transmitter. Could it be that you might be ‘force feeding’ the ESC and causing it to ‘burp’.

I’ll see if I can look up my notes on using hobby servos but it has been several years sense I messed with them. I think the last time I messed around with them I was trying to see if I could control multiple servos with one timer channel on a Cypress PSoC. I had a timer that fired an interrupt like every 0.1ms it would check to see what state the pulse should be in for each servo at that time and update the outputs. It worked very well as I recall and always gave you synchronized movements. That would be a cool experiment to do on a Cobra with PLD.

Hi Gus,

I looked at the signal under the scope and it looks very strange. Shall I provide you with demo code?

@ Jeff: Duty cycle = 50% = 20ms per PPM frame

@ kurtnelle: Basically, the wave looked like the high time got interrupted. It may have been going from 1.5ms high to 2.0ms high, but the wave might have been something like 900us! I’ll take a video of it or something.

Hi Gus,

Please set your scope to 10ms/div on a rising repeat trigger, then run the code below. If your scope can, place a ruler at +1.4ms past the trigger. You will be probing digital pin 8.

Nothing will happen for the first few seconds, but when the throttle up command is given, watch as the PWM signal wildly fluctuates. With that code sample, that signal should never go much below 1.4ms, but it does. In fact, it goes as low as 700us!

http://files.chrisseto.com/k2s

Thanks!

How can we be 100% sure it is not a bug in your code?

Can you give me an example to repro that is small? I mean really small…10 lines of code :slight_smile:

Nothing in the code but obvious loop, variable and PWM.Set please

Ok, hold on a minute :slight_smile:

Yep, I’m still getting the issue even with the simplified code. Watch the scope trace as the signal gets cuts short, then returns to where it should be.
http://files.chrisseto.com/wJ2

Please try this and let us know:

esc = new PWM((PWM.Pin)FEZ_Pin.PWM.Di8);
Register r = new Register(0xE0018024);

for (double set = 911; set <= 2000; set += 5)
{
	// Set the pulse
	//esc.SetPulse(20000000, (uint)(set * 1000));
                
    r.Write((uint)(set * 18));
	Thread.Sleep(40);
}

Hi Mike,

Thanks for the code. I’ll try it tonight and let you know ;D

Hi Mike,

That code works flawlessly! :dance:

I looked at the signal under the scope and it looks clean as a whistle.

that was easy too fix :wink:

Thanks Chris for helping in finding the bug.

That’s great. We are glad it works.
We will send you an email with a USBizi firmware soon, so you can try the actual firmware.

Cool good to hear chris.

Thanks for the lightning fast response, GHI! :o