pic32/libraries/SoftPWMServo/SoftPWMServo.cpp
// Set a new PWM value for a given pin
// Primarily this consists of updating the PWMValue and then 
// re-sorting the list of active pins by removing and then adding
// the pin to the linked list.
Set a new PWM value for a given pin
Primarily this consists of updating the PWMValue and then
re-sorting the list of active pins by removing and then adding
the pin to the linked list.
Set a new PWM value for a given pin Primarily this consists of updating the PWMValue and then re - sorting the list of active pins by removing and then adding the pin to the linked list .
int32_t SoftPWMServoRawWrite(uint32_t Pin, uint32_t Value, bool PinType)
{
    int32_t intr;
    if (Pin >= SOFTPWMSERVO_MAX_PINS)
    {
        return SOFTPWMSERVO_ERROR;
    }
    if (!Initalized)
    {
        SoftPWMServoInit();
    }
    if (Value > FrameTime)
    {
        Value = FrameTime;
    }
    intr = disableInterrupts();
    CopyBuffers();
    SoftPWMServoPinEnable(Pin, PinType);
    Chan[InactiveBuffer][Pin].PWMValue = Value;
    Chan[InactiveBuffer][Pin].IsServo = PinType;
    Remove(Pin);
    Add(Pin);    
    restoreInterrupts(intr);  
    return SOFTPWMSERVO_OK;
}
int32_t SoftPWMServoRawWrite ( uint32_t Pin , uint32_t Value , bool PinType ) { int32_t intr ; if ( Pin >= SOFTPWMSERVO_MAX_PINS ) { return SOFTPWMSERVO_ERROR ; } if ( ! Initalized ) { SoftPWMServoInit ( ) ; } if ( Value > FrameTime ) { Value = FrameTime ; } intr = disableInterrupts ( ) ; CopyBuffers ( ) ; SoftPWMServoPinEnable ( Pin , PinType ) ; Chan [ InactiveBuffer ] [ Pin ] . PWMValue = Value ; Chan [ InactiveBuffer ] [ Pin ] . IsServo = PinType ; Remove ( Pin ) ; Add ( Pin ) ; restoreInterrupts ( intr ) ; return SOFTPWMSERVO_OK ; }
Set a new PWM value for a given pin
Primarily this consists of updating the PWMValue and then
re-sorting the list of active pins by removing and then adding
the pin to the linked list.
Set a new PWM value for a given pin Primarily this consists of updating the PWMValue and then re - sorting the list of active pins by removing and then adding the pin to the linked list .
// Insert our ISR handler, if it's not already there // Limit check the inputs // The easy way to prevent the ISR from doing a buffer swap while // we're in the middle of this is to disable interrupts during  // the time that we're mucking with the list. // TODO: Switch to using 3 buffers - one 'active' that the ISR // is currently using, one 'primed' that the mainline code doesn't // touch but has updates and is ready to be swapped before the // next rising edge, and then 'inactive' which is the one we modify // with here. Maybe we wouldn't need to disable interrupts then. // If needed, copy the values from the previously active buffer // into the inactive buffer before we begin work on it. // Always make sure this pin's enabled // Update the PWM value for this pin // Remove it from the list // And add it back in the list, in the right place (in time)