//*****************************************************************************
//
// The interrupt handler for the SysTick timer.  This handler will increment a
// seconds counter whenever the appropriate number of ticks has occurred.  It
// will also call the CPU usage tick function to find the CPU usage percent.
//
//*****************************************************************************
void
SysTickHandler(void)
{
    static unsigned long ulTickCount = 0;

    //
    // Increment the tick counter.
    //
    ulTickCount++;

    //
    // If the number of ticks per second has occurred, then increment the
    // seconds counter.
    //
    if(!(ulTickCount % SYSTICKS_PER_SECOND))
    {
        g_ulSeconds++;
    }

    //
    // Call the CPU usage tick function.  This function will compute the amount
    // of cycles used by the CPU since the last call and return the result in
    // percent in fixed point 16.16 format.
    //
    g_ulCPUUsage = CPUUsageTick();
}
Exemple #2
0
//Esto se ejecuta cada Tick del sistema. LLeva la estadistica de uso de la CPU (tiempo que la CPU ha estado funcionando)
void vApplicationTickHook( void )
{
	static unsigned char count = 0;

	if (++count == 10)
	{
		g_ui32CPUUsage = CPUUsageTick();
		count = 0;
	}
	//return;
}
Exemple #3
0
//*****************************************************************************
//
//! Handles the SysTick interrupt.
//!
//! This function is called when SysTick asserts its interrupt. It is
//! responsible for handling the on-board user interface elements (push button
//! and potentiometer) if enabled, and the processor usage computation.
//!
//! \return None.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
    static unsigned int uDataUpdate = UI_INT_RATE / 10;
    static unsigned long ulLastPotPosition = 0;
    static unsigned long ulLastBlink = 0;
    static long lLastPotDelta = 0;
    static unsigned short usLastBusVoltage = 0;
    static unsigned char bFaultBlink = 0;
    unsigned long ulBlink;
    unsigned long ulADCCounts[8]; // 0-pot, 1-busV, 2-temperature
    long lSamples;
    long lPotDelta;

    //
    // Get the motor status. This will update the fields in the
    // stepper status structure.
    //
    pStepperStatus = StepperGetMotorStatus();

    //
    // Compute the average current, which is what gets reported through
    // the UI.
    //
    g_usMotorCurrent = (pStepperStatus->usCurrent[0] +
                       pStepperStatus->usCurrent[1] + 1) / 2;

    //
    // Get the previous ADC samples, and start a new acquisition
    //
    lSamples = ADCSequenceDataGet(ADC0_BASE, UI_ADC_SEQUENCER, ulADCCounts);
    ADCProcessorTrigger(ADC0_BASE, UI_ADC_SEQUENCER);

    //
    // Read the bus voltage and convert to millivolts,
    // and the CPU temperature and convert to C
    //
    if(lSamples == 3)
    {
        g_usBusVoltage = (unsigned short)((ulADCCounts[1] * 81300) / 1023);
        g_sAmbientTemp = (59960 - (ulADCCounts[2] * 100)) / 356;
    }

    //
    // If the bus voltage has changed more than 0.5 volts, then call
    // the UISetMotorParms() function, which will force an update of
    // the PWM duty cycle calculation. This will insure that the PWM
    // duty cycle is correct if the bus voltage changes.
    //
    if(ABS((int)g_usBusVoltage - (int)usLastBusVoltage) > 500)
    {
        UISetMotorParms();
        usLastBusVoltage = g_usBusVoltage;
    }

    //
    // Periodically send real time data
    //
    if(!uDataUpdate--)
    {
        uDataUpdate = UI_INT_RATE / 20;
        UISerialSendRealTimeData();
    }

    //
    // If a fault just occurred, then start the status LED blinking
    // at a rapid rate.
    //
    if(pStepperStatus->ucFaultFlags && !bFaultBlink)
    {
        BlinkStart(STATUS_LED, 4, 4, INT_MAX);
        bFaultBlink = 1;
    }

    //
    // Else, if a fault was just cleared, then stop the status LED blinking.
    //
    else if(!pStepperStatus->ucFaultFlags && bFaultBlink)
    {
        BlinkStart(STATUS_LED, 1, 1, 1);
        bFaultBlink = 0;
    }

    //
    // Otherwise, as normal, blink the status LED according to the number
    // of steps moved.
    //
    else
    {
        //
        // Blink the status LED every so many steps.
        //
        ulBlink = pStepperStatus->lPosition / ((2000 * 256) / 8);
        if(ulBlink != ulLastBlink)
        {
            BlinkStart(STATUS_LED, UI_INT_RATE / 32, 1, 1);
            ulLastBlink = ulBlink;
        }
    }

    //
    // Periodically call the blinker state machine.
    //
    BlinkHandler();

    //
    // Compute the new value for the processor usage.
    //
    g_ucCPUUsage = (CPUUsageTick() + 32768) / 65536;

    //
    // Do the following only if the on-board UI is enabled.
    //
    if(g_bUIUseOnboard == 1)
    {
        //
        // Filter the potentiometer value. Make sure there is valid
        // ADC data.
        //
        if(lSamples == 3)
        {
            ulPotPosition = UIOnboardPotentiometerFilter(ulADCCounts[0]);
        }
        else
        {
            //
            // If ADC reading is suspect, then just use the last previous
            // reading.
            //
            ulPotPosition = ulLastPotPosition;
        }

        //
        // Set the minimum value to be use as 10. This sets the minimum
        // speed for speed mode to 10.
        //
        if(ulPotPosition < 10)
        {
            ulPotPosition = 10;
        }

        //
        // Read the on-board switch and pass its value to the switch
        // debouncer. This will drive the button press functions
        // UIButtonPress() and UIButtonHold() which will be called
        // back if the button press or hold occurred.
        //
        UIOnboardSwitchDebouncer(GPIOPinRead(USER_BUTTON_PORT,
                                             USER_BUTTON_PIN));

        //
        // Find the difference from the last pot measurement.
        //
        lPotDelta = ulPotPosition - ulLastPotPosition;

        //
        // Check if the direction is reversed. The following is used
        // to ensure that the pot reading does not actually cause
        // a change in direction (in position mode) due just to jitter
        // in the potentiometer reading. Only a change above a certain
        // value will be accepted. If the direction is not changed,
        // then no filtering is done.
        //
        if((lPotDelta != 0) && ((lPotDelta * lLastPotDelta) < 0))
        {
            //
            // If the direction is reversed, but the change is less than a
            // certain amount, then don't accept the new potentiometer reading,
            // and set it back to its previous value.
            //
            if(ABS(lPotDelta) < 20)
            {
                ulPotPosition = ulLastPotPosition;
            }

            //
            // else, if the direction is reversed and changed more than a
            // certain amount, then just leave the new pot reading as is,
            // and remember the difference.
            //
            else
            {
                lLastPotDelta = lPotDelta;
            }
        }

        //
        // Else, the direction of the pot move was not reversed. Remember
        // the (signed) difference. The new pot value will be used below.
        //
        else
        {
            lLastPotDelta = lPotDelta;
        }

        //
        // Check to see if the potentiometer has moved.
        //
        if(ulPotPosition != ulLastPotPosition)
        {
            ulLastPotPosition = ulPotPosition;

            //
            // In position mode, the pot indicates the motor target
            // position, so update the target position and command the
            // motor to move.
            //
            if(eUIMode == UI_MODE_POSITION)
            {
                //
                // Make sure that after conversion to steps, the target
                // position actually changed, before sending a new motion
                // command.
                // The pot position is adjusted so that one revolution
                // of the pot matches 200 steps, the number of steps in
                // the motor. This gives the position mode a 1-1 feel,
                // as the pot is turned, the motor turns a corresponding
                // amount.
                //
                if(((ulPotPosition * 256 * 100) / 507) != g_lTargetPos)
                {
                    g_lTargetPos = (ulPotPosition * 256 * 100) / 507;
                    UISetMotion();
                }
            }

            //
            // In speed mode, the pot indicates the motor speed, so
            // command the motor to move using the new speed.
            //
            else if(eUIMode == UI_MODE_SPEED)
            {
                StepperSetMotion(g_lTargetPos, ulPotPosition,
                     g_sParameters.usAccel, g_sParameters.usDecel);
            }
        }

    }
}