Need testers for SoftPWMServo library

cobra18t
Posts: 24
Joined: Wed Dec 21, 2011 2:23 am
Contact:

Re: Need testers for SoftPWMServo library

Post by cobra18t » Thu Aug 22, 2013 7:17 pm

I upgraded to MPIDE 20130715 hoping that would solve the issue, but no good.

If I am actively driving the motor when 107 seconds passes, PWM continues to work until I disable the PWM pins. When I try to reenable them seconds later, they will not work.

I am controlling the motor PWM via joystick position. If the joystick is near centered, the PWM is disabled. When it goes outside a software defined dead zone, the PWM is reenabled. Maybe the issue is in the Initialize or Disable routines of the library.

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Need testers for SoftPWMServo library

Post by EmbeddedMan » Thu Aug 22, 2013 9:18 pm

I'm not completely surprised by this. The 107s value is when the 32bit Core Timer overflows (at 40MHz). I need to test this out, and figure out the bug in the code when the overflow happens.

Can you create the simplest project you can that exhibits this effect and send it to me or post it to this thread?

Thanks so much for your help-

*Brian

cobra18t
Posts: 24
Joined: Wed Dec 21, 2011 2:23 am
Contact:

Re: Need testers for SoftPWMServo library

Post by cobra18t » Thu Aug 22, 2013 10:42 pm

Here is some code that fails after 107s, recovers briefly before failing again after 214s, and so on...

Code: Select all

#include <SoftPWMServo.h>

const int LEDPin = 21;

#define PWM_FREQUENCY           (75)
// Number of 40MHz CoreTimer ticks of the default frame time
#define SOFTPWMSERVO_NEW_FRAME_TIME     (F_CPU / 2 / PWM_FREQUENCY)

void setup()
{  
  //outputs
  pinMode(LEDPin, OUTPUT); 
  
  SoftPWMServoPWMWrite(LEDPin,0);
  
  //redefine PWM parameters
  SoftPWMServoSetFrameTime(SOFTPWMSERVO_NEW_FRAME_TIME);
}

void loop()
{
  delay(500);     
  SoftPWMServoPWMWrite(LEDPin,127);
  delay(500); 
  SoftPWMServoPWMWrite(LEDPin,0);
}

cobra18t
Posts: 24
Joined: Wed Dec 21, 2011 2:23 am
Contact:

Re: Need testers for SoftPWMServo library

Post by cobra18t » Thu Sep 26, 2013 11:40 pm

Any word on the overflow issue mitigation?


-Thomas

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Need testers for SoftPWMServo library

Post by EmbeddedMan » Wed Oct 02, 2013 2:57 pm

Thomas,

My apologies. I have not had any time to work on this issue. I have the sample code, and I'm sure I can reproduce the problem. I'm just on the tail end of moving to a new location, and am setting up my lab again, which will take a little while. Once that's done, I hope to resume some chipKIT work.

*Brian

illegalbean
Posts: 5
Joined: Thu Oct 10, 2013 5:11 pm

Re: Need testers for SoftPWMServo library

Post by illegalbean » Wed Oct 16, 2013 6:48 pm

Hi Brian,

I was just double checking to see if you had any new information on this issue.

Thanks

Edgard

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Need testers for SoftPWMServo library

Post by EmbeddedMan » Sat Dec 21, 2013 9:33 pm

I believe that the 107s bug is now fixed. If you want to test it out with your system before a new version of MPIDE comes out, simply replace your SoftPWMServo.cpp file with the new one here : https://github.com/chipKIT32/chipKIT32- ... MServo.cpp

cobra18t - I've also confirmed that with this new version, your example above works properly (at least I can't see any incorrect edges in about 300s of sampling).

*Brian

cobra18t
Posts: 24
Joined: Wed Dec 21, 2011 2:23 am
Contact:

Re: Need testers for SoftPWMServo library

Post by cobra18t » Mon Dec 23, 2013 4:56 pm

Outstanding!

I will check this out.


-Thomas

rasmadrak
Posts: 218
Joined: Mon Aug 15, 2011 9:21 pm
Location: Sweden
Contact:

Re: Need testers for SoftPWMServo library

Post by rasmadrak » Sun Sep 06, 2015 12:23 pm

Hello!
Resurrecting an old thread... :)

I've implemented SoftPWMServo and am wondering if there's a way to do the updates manually instead of letting the library use interrupts? This as I need control over my interrupts and the current version interferes with the rendering routine. :) I don't need 100% control for the servos just "good enough", so I figure I could update them on the machine's "spare time" instead of automatically.

There's some really nice code in the library, but I haven't had time to go through it myself.
Is there a built in method for this in the library, or need it be custom created? :)

Edit:

Just in case there's nothing built in for manual control, I found this on the interwebs.
"Manual control of a servo" - http://blog.zipwhip.com/2012/03/28/manu ... so-machine

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Need testers for SoftPWMServo library

Post by majenko » Sun Sep 06, 2015 4:57 pm

Not really, no - not sure it's possible at all with SoftServoPWM.

The problem is that the waveform is generated using the C0 core timer interrupt. That's part of the chipKIT scheduler system. It's not "updating" the servos, it's actively generating the waveform to set the servo position.

It's not a regular "output this pulse width" event, it's an "is it time to raise or lower this IO line yet?" event.

You could theoretically disable C0 core timer interrupts while you are doing things with critical timing, but who knows what knock-on effect that would have on other things - the C0 core timer is used for millis(), micros(), delay() etc as well as the scheduler.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply