Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:03 06 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Synchronizing PWM Changes uMITE5.2

Author Message
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 04:42pm 25 Oct 2016
Copy link to clipboard 
Print this post

Hi All;
Here is a code snippet to show a problem with synchronizing the change
of a POW value.
' uMITE 5.2 28pin 40MHz
DO
PULSE 2,1 ' Strobe once per cycle Scope Trigger
FOR T = 20 TO 80 STEP 30
PULSE 5,1 ' Strobe when changing PWM
PWM 1, 200,T
PAUSE 30 + RND()*5 ' Used to move the timing around
NEXT T
LOOP
The problem I'm having is there isn't a clean transition
when changing the PWM. It appears that, depending on the exact time
the PWM change is asserted, the last output completes cleanly.
However, at other times the it looks like a full pulse is missing.

OK, this would not be noticed much if the PWM doesn't change very
fast. I wanted to rapidly change the PWM values and these blank
times would be unacceptable.

It looks like, but I'm not sure, if I assert the next PWM it works
OK when asserted while the output is high.
When asserted while the output is low the next pulse is aborted and
extends the low time.

Is there a way to only assert when the pulse is high?

I want to use this in a special light intensity to time AtoD converter.
Ya, its another LED based solar tracker. You can see the nexus of this
here: LED555
This 555 circuit directly generates variable PWM from the sensor.
I wanted to do it with the uMITE which would be more versatile.
I should say the actual sensor works fine it's just the PWM that is flaky.

Any examples or suggestions?

Thanks!
redrok

Edited by redrok 2016-10-27
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 06:08pm 25 Oct 2016
Copy link to clipboard 
Print this post

This is a difficult one as it is a "feature" of the way these outputs work on the PIC32.

In V5.2 I changed the SERVO command to prevent exactly this issue. The fix involved triggering a PIC32 hardware interrupt when the timer controlling the output had reached zero. This depended on the servo output having a relatively low frequency but with the high frequency that is possible on the PWM outputs the interrupts would swamp the PIC32's CPU.

If you only want a low frequency PWM output (between 20Hz and 1000Hz) you could run the outputs in SERVO mode as that will accept a very high rate of updates while still keeping a clean output. Alternatively, you could feed the PWM output into a JK Flip Flop which would at least fix any runt pulses.

Geoff
Geoff Graham - http://geoffg.net
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 04:00am 26 Oct 2016
Copy link to clipboard 
Print this post

Hi Geoff;

That was the ticket, run in SERVO mode.

I hadn't even considered using SERVO.
Yes, there are timing constraints, but that would be well within
the motor driving requirements.

That code snippet uses a useful technique.
It uses the RND() function to cause a changeable delay.
This helps find the timing problems by running pulse edges
over each other.

The SERVO still has a slight problem. The pulse will widen a bit
when the new SERVO function is asserted. I assume this is caused
by the 2 interrupts overlapping. This code snippet shows this.
' uMITE 5.2 28pin 40MHz
DO
PULSE 2,1 ' Strobe once per cycle
FOR T = 8 TO 2 STEP -3 ' Reducing pulse width
' FOR T = 2 TO 8 STEP 3 ' Increasing pulse width
PULSE 5,1 ' Strobe when changing SERVO
SERVO 1 , 100 , T
PAUSE 100 + RND()*20 ' Used to move the timing around
NEXT T
LOOP
However, in this application, this is MUCH more manageable
than with PWM.

Thanks for the help.
redrok
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025