Need testers for SoftPWMServo 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 » Wed Nov 30, 2011 10:31 pm

Where is the fade example code? I'm not familiar with it.

Our SoftPWMServo library outputs PWM pulses at the same rate as analogWrite(), which is 490Hz.

*Brian

edanielreyes
Posts: 1
Joined: Fri Feb 17, 2012 8:28 pm

Re: Need testers for SoftPWMServo library

Post by edanielreyes » Fri Feb 17, 2012 8:33 pm

Hello

I'm new using ChipKit32 and I'm having some problems.

I'd be happy if you answer this question.
Can I use this library with ChipKit uno32?

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 Feb 18, 2012 3:37 am

Yes, it works great on the Uno32, Max32, UBW32, CUI32, etc.

What types of problems are you seeing?

*Brian

davidESPCI
Posts: 3
Joined: Thu Oct 25, 2012 5:59 pm

Re: Need testers for SoftPWMServo library

Post by davidESPCI » Thu Oct 25, 2012 6:05 pm

Hi EmbeddedMan,

I will need to use a PWM output on a Max32. Before seeing your post, I was thinking to use a digital output an to do a PWM signal with the functions digitalWrite(), micros() and/or delayMicroseconds().

What is better between using your library or the previous method ?

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 » Thu Oct 25, 2012 10:01 pm

Pros for the software method: you can use any I/O pin, you can use all of them at the same time (i.e. lots more simultaneous servos), and doesn't use any hardware resources.

Pros for the standard hardware method: less jitter in servo output (not normally a concern), is the standard way to do servos (so code is already written for it).

*Brian

davidESPCI
Posts: 3
Joined: Thu Oct 25, 2012 5:59 pm

Re: Need testers for SoftPWMServo library

Post by davidESPCI » Sat Oct 27, 2012 12:00 pm

In my application, I am just permitted to use one output of the max32 in the same time. Indeed, the output will excite a transistor used in commutation in order to commute 4 darlington in order to inject 8A distributed in 4 different circuits.

Because of the high amount of current in the external circuit and because I don't want to buy a one thousand power supply (!), I just can use one output at each time.

But I will need to generate typically the square signal on the max32 output at a frequency between 1 to 1000 Hz with pulse width of 100µs (will change after certainly).

I think that the software solution is the best one, just in order to keep the flexibility in the change of the value.

Do you think that is a good idea ?

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 Oct 27, 2012 2:29 pm

David, I think you should use a hardware PWM. Since only only need one channel output (I think) you can control a single PWM pin with more accuracy than with software PWM.

*Brian

davidESPCI
Posts: 3
Joined: Thu Oct 25, 2012 5:59 pm

Re: Need testers for SoftPWMServo library

Post by davidESPCI » Sat Oct 27, 2012 2:53 pm

Thanks Brian for your answer.

Can I change easily the frequency of the PWM with analogWrite() ?
I need to use 5 different signals. Four are mono frequency signals from 1Hz to 1kHz. But I have a complex signal that is composed by a train of pulse at 1kHz and just after by a train of pulse at 500Hz (just after means 1ms after). Will it be doable ?

David

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 Oct 27, 2012 7:54 pm

No. You will need to read the PIC32 datasheet and write to the PWM (they're called Output Compare) registers directly.

* Brian

domoarigato
Posts: 2
Joined: Thu Nov 22, 2012 4:51 pm

Re: Need testers for SoftPWMServo library

Post by domoarigato » Thu Nov 22, 2012 4:59 pm

I found a small bug in the SoftPWMServoRawWrite function:

Code: Select all

    // And if this pin already has this PWM Value, then don't do anything.
    if (Value == Chan[InactiveBuffer][Pin].PWMValue)
    {
        return SOFTPWMSERVO_OK;
    }
should be:

Code: Select all

    // And if this pin already has this PWM Value, then don't do anything.
    if (Value == Chan[ActiveBuffer][Pin].PWMValue)
    {
        return SOFTPWMSERVO_OK;
    }

You should be checking for a duplicate of the Active value, not the Inactive value.

This bug prevents the application from switching between 2 different PWM values alternately.

- Garrett

Post Reply