Need testers for SoftPWMServo library

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

Need testers for SoftPWMServo library

Post by EmbeddedMan » Thu Aug 18, 2011 4:46 am

I just got done writing a PWM and Servo output library for MPIDE/PIC32. It allows one to do analogWrite() style output, as well as RC Servo output, on all pins simultaneously (up to 85 at once). It is pretty easy to use, and hopefully will be useful to some people.

It does not us any timers, but runs completely in the background by hooking into the CoreTimer interrupt. It is double buffered for glitchless transitions. The internal resolution of the PWM and Servo pulses is 25ns, although (obviously) this is not an accuracy and can't be guaranteed because this is just a software implementation. However, you should be able to get your pulses to within about 500ns of where you want them worst case.

I think. That's where the testing comes in. <grin> I need some help testing it out before making it final.

Here's a little movie of it running 10 RC servos at the same time (all pins are actually outputting RC servo pulses, but I only had 10 working servos) : http://www.youtube.com/watch?v=q2GlwfWwr3w

If you'd like, you can download it from here : http://www.schmalzhaus.com/UBW32/SoftPWMServo_v1_0.zip To install, you need to do two things:

1) Take the wiring.c and wiring.h files and copy them into your /mpide-022-win-20110809-test/hardware/pic32/cores/pic32/ folder (copy over the existing files that are there).

2) Then copy the SoftPWMServo folder from the zip file into /mpide-022-win-20110809-test/hardware/pic32/libraries/ and then re-start MPIDE.

(Obviously modify the paths for your own installation of MPIDE)

Let me know if you find any problems, or have any questions. Also, read the README.TXT file. It explains a lot about how the library works, and what the timing restrictions are, and the jitter too.

There are five examples that you can load up and start running too.

*Brian

Addidis
Posts: 48
Joined: Fri May 27, 2011 7:24 pm

Re: Need testers for SoftPWMServo library

Post by Addidis » Fri Aug 19, 2011 8:06 pm

I am noticing some undesired movement every few minutes. Still playing around with it , over all nice work. But every 3-5 mins it moves 20 degrees and back.

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

Re: Need testers for SoftPWMServo library

Post by EmbeddedMan » Fri Aug 19, 2011 8:22 pm

Ok, good. That's the kind of feedback I'm looking for.

Can you post the simplest sketch that exhibits the problem? Does it change if you have more or less pins enabled? Does it only happen with certain servo pulse durations?

Thanks!!

*Brian

Addidis
Posts: 48
Joined: Fri May 27, 2011 7:24 pm

Re: Need testers for SoftPWMServo library

Post by Addidis » Fri Aug 19, 2011 9:45 pm

Just the simple servo example. I switched to pin 2. It does it regardless of possition , but im only really using 2 , full open full closed. I was going to hot glue a servo to the door lock.

my goal was to get it to work asap, quick and dirty.... Im pretty sure the serial is overflowing but w/e. It works twice then needs a reset. Quick and dirty,


#include <SoftPWMServo.h>

int pos = 0; // variable to store the servo position, in microseconds
const int pin = 2; // Choose _any_ pin number on your board
int inByte = 0; // incoming serial byte

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);


}

void loop()
{
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();

switch (inByte){
case 'u':
SoftPWMServoServoWrite(pin, 1000);
break;
case 'l':
SoftPWMServoServoWrite(pin, 2000);
break;
delay(35);
}
inByte =0;
}
}


UPDATE
Works flawlessly with HW pwm.

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

Re: Need testers for SoftPWMServo library

Post by EmbeddedMan » Sun Aug 21, 2011 4:54 pm

OK, I've reproduced the bug. I think it happens every 107 seconds when the Core Timer oveflows from 0xFFFFFFFF to 0x00000000.

I'm now adding code to handle this situation, and will provide an updated library shortly.

*Brian

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

Re: Need testers for SoftPWMServo library

Post by EmbeddedMan » Mon Aug 22, 2011 3:44 pm

New version ready:

I've released version 1.1 of the SoftPWMServo library. The main change was the fixing of the bug reported above.

You can download the new library from here : http://www.schmalzhaus.com/UBW32/SoftPWMServo_v1_1.zip

If you are just updating the library, you only need to copy the new SoftPWMServo.cpp and SoftPWMServo.h files over.

Please let me know if you find any bugs with this new version.

*Brian

Addidis
Posts: 48
Joined: Fri May 27, 2011 7:24 pm

Re: Need testers for SoftPWMServo library

Post by Addidis » Mon Aug 22, 2011 4:24 pm

Nice, I will Give it another go shortly.

Dre4mPT
Posts: 1
Joined: Mon Nov 28, 2011 10:41 am

Re: Need testers for SoftPWMServo library

Post by Dre4mPT » Tue Nov 29, 2011 7:54 pm

Hi!

It's good if you update always the first post with newer version!

I'm getting the hold version and then when I continue reading the post view v1.1!

Thanks!

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 Nov 30, 2011 4:53 am

Well, all of the latest releases of MPIDE have the latest version of this library already included, so there isn't really a need to download it separately anymore I guess.

*Brian

slayer1991
Posts: 73
Joined: Sun Nov 27, 2011 5:11 am

Re: Need testers for SoftPWMServo library

Post by slayer1991 » Wed Nov 30, 2011 4:17 pm

Take a look at my last post here http://www.chipkit.org/forum/viewtopic. ... 0&start=10.
What is your pwm pulse frequency compared to the led fade one?

Post Reply