Strange PWM

More
15 Jan 2014 18:04 #42813 by eslavko
Strange PWM was created by eslavko
Hello...

I found strange behaviour of PWM in my machine.
The PWM config is this:
loadrt pwmgen output_type=1
addf pwmgen.update servo-thread
addf pwmgen.make-pulses base-thread
setp pwmgen.0.pwm-freq 50.0
setp pwmgen.0.value 0.02
setp pwmgen.0.dither-pwm true
setp pwmgen.0.enable true
net spindle-pwm <= pwmgen.0.pwm

And I except that I got pulse every 20 msec.
But that's not true. I got 10 pulses every 20 msec, and then is silence around 250msec long!
I was thinking that dither does that but with setp pwmgen.0.dither-pwm false is same output.
I got correct output if I set setp pwmgen.0.value 0.05 or if I change base period from 25000 to 30000.
what happens there?!?

Here is screenshot and log file from hal.
Attachments:

Please Log in or Create an account to join the conversation.

More
15 Jan 2014 21:25 #42821 by andypugh
Replied by andypugh on topic Strange PWM

And I except that I got pulse every 20 msec.
But that's not true. I got 10 pulses every 20 msec, and then is silence around 250msec long!


It looks like you are running the Halscope in the servo thread and the PWM in the base-thread.
What you are seeing might well be "aliasing"
en.wikipedia.org/wiki/Aliasing
Try setting halscope to run in the base thread and see if it still looks the same.
(click the button that says "8000 samples at 1kHz" to change the sample rate and sampling thread.

Please Log in or Create an account to join the conversation.

More
15 Jan 2014 22:20 #42826 by eslavko
Replied by eslavko on topic Strange PWM
It's not aliased scope.
The exact same figure is seen on real osciloscope tighted to pin.

So the problem is real not just on hal figure.

The latency of computer is under 10us. With base period under 15us the computer hangs, with base period betwen 15 ... 18us is jerky (GUI response is slow) but over 18us all seems normal.

If I understand correctly nondithered pwm should output pulse of same length every (1/frequency) period. In my case every 20ms. But it's not true!
If i set value of 0.05 then pulses are ok (every 20ms). Why that? Or if I set base period to 30us the pulses are good too! This seems nonsense to me.

If I have pwm freq at 50Hz (20ms period) and Base thread at 25us then in theory I have 800 distinct pulse lenght possible. And 800*0.02=16. So for this setup the pulse of 0.02 should last 16 base periods. And I expect to get problems similar of this if I set value to 1/800=0.00125

Just don't get it...

HELP!

Please Log in or Create an account to join the conversation.

More
15 Jan 2014 22:36 #42829 by andypugh
Replied by andypugh on topic Strange PWM

It's not aliased scope.
The exact same figure is seen on real osciloscope tighted to pin.

If I have pwm freq at 50Hz (20ms period) and Base thread at 25us then in theory I have 800 distinct pulse lenght possible. And 800*0.02=16. So for this setup the pulse of 0.02 should last 16 base periods.

Yes, good point.
I really have no idea what is going on here. Especially with it being dependent on base-thread period.
Can you run a charge-pump component in the base thread to put a clock-tick on the trace (and run halscope in the base thread too) to check that it is a PWM problem and not a base thread problem?

Please Log in or Create an account to join the conversation.

More
15 Jan 2014 23:31 #42833 by eslavko
Replied by eslavko on topic Strange PWM
Charge pump signal seems ok. It's continous all the time no mater if it's on base or servo thread. (of course on base thread is much denser)

Please Log in or Create an account to join the conversation.

More
16 Jan 2014 01:13 #42838 by eslavko
Replied by eslavko on topic Strange PWM
I forget to say that base thread probably works ok.
As I have 'clicking' PWM, the same time stepgens work as should. Jogging motor is not harmed.

But there is another glitch and it's possible that is releated. When I start linuxcnc sometime I got rtapi error 'unexpected delay...' But if this hapens only sometime and only in startup!

If linuxcnc start without that error, I can't make it to happen! I can browse the web, run glxgears .,.. anithyng but can't trigger that! Also the latency over hard abuse and 24 hour poweron is under 10us!

Please Log in or Create an account to join the conversation.

More
16 Jan 2014 01:38 #42841 by eslavko
Replied by eslavko on topic Strange PWM
One more thing...

Just look that's parameters!
curr-dc is 0.019
min-dc is 0.02

the difference is just way too big to be rounding errors...

And for information the pwm works as should at base period of 18us. (but system is little slow then) seems that around 20 and 27us is some sweet spot where pwm does malfunct! :sick:
Attachments:

Please Log in or Create an account to join the conversation.

More
16 Jan 2014 01:57 #42844 by andypugh
Replied by andypugh on topic Strange PWM

Just look that's parameters!
curr-dc is 0.019
min-dc is 0.02
:


Odd, as you have pointed out 16 base-threads per cycle is exactly 0.02 DC.

Please Log in or Create an account to join the conversation.

More
16 Jan 2014 03:00 #42845 by eslavko
Replied by eslavko on topic Strange PWM
And pwm freq is something I NOT set... I set exact 50 but there is 50.01291 Hz. Where that come....

Looking at the source I can't spot the problem. As all other thing works (at least I know) I don't get it why base thread time had that influence to PWM. Realy don't know what to do.. but keeping dc limited at 0.05 is not option.

will try tomorow another computer with same setup to see if works there...

Please Log in or Create an account to join the conversation.

More
16 Jan 2014 16:44 #42868 by eslavko
Replied by eslavko on topic Strange PWM
Today I change computer and got same result. :ohmy:
After long examination I discovered that it's not linuxcnc problem but my.
After pwmgen I have OR gate to force PWM high if I want to override speed controll. and this seems like this
loadrt or2 count=2
addf or2.0 servo-thread
net spindle-pwm => or2.0.in0
net spindle-full => or2.0.in1
net spindle-pwmx <= or2.0.out => parport.0.pin-01-out

And in halscope indeed I see alliased result as Andy suspect! But close match I see in real scope tied on pin too so I was think is not alliased.!
But alliasing in halscope is caused as I sample at servo period (I can't sample long enought in base period to see that), but real scope on pin get's alliased result as I run OR2 gate in wrong thread (servo) instead (base). So aliasing ocour in OR2 gate. (works like mixer)
After moving OR2 to base thread all thing works normal...

...fell so stupid... :evil:

Slavko


p.s.
At least I learn how to use comp. (I added some testpoints in pwmgen to be able to check what happens.)

Please Log in or Create an account to join the conversation.

Time to create page: 0.084 seconds
Powered by Kunena Forum