int main(void)
{
    /* Halting WDT  */
    MAP_WDT_A_holdTimer();
    MAP_Interrupt_enableSleepOnIsrExit();
    resPos = 0;

    /* Setting up clocks
     * MCLK = MCLK = 3MHz
     * ACLK = REFO/4 = 32Khz */
    MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);

    /* Initializing ADC (MCLK/1/1) */
    MAP_ADC14_enableModule();
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
            0);

    /* Configuring GPIOs (5.5 A0) */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
    GPIO_TERTIARY_MODULE_FUNCTION);

    /* Configuring ADC Memory */
    MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
    MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
    ADC_INPUT_A0, false);

    /* Configuring Timer_A in continuous mode and sourced from ACLK */
    MAP_Timer_A_configureContinuousMode(TIMER_A0_MODULE, &continuousModeConfig);

    /* Configuring Timer_A0 in CCR1 to trigger at 16000 (0.5s) */
    MAP_Timer_A_initCompare(TIMER_A0_MODULE, &compareConfig);

    /* Configuring the sample trigger to be sourced from Timer_A0  and setting it
     * to automatic iteration after it is triggered*/
    MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false);

    /* Enabling the interrupt when a conversion on channel 1 is complete and
     * enabling conversions */
    MAP_ADC14_enableInterrupt(ADC_INT0);
    MAP_ADC14_enableConversion();

    /* Enabling Interrupts */
    MAP_Interrupt_enableInterrupt(INT_ADC14);
    MAP_Interrupt_enableMaster();

    /* Starting the Timer */
    MAP_Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_CONTINUOUS_MODE);

    /* Going to sleep */
    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}
int main(void)
{
    MAP_WDT_A_holdTimer();

    /* Remapping  TACCR0 to P2.0 */
    MAP_PMAP_configurePorts((const uint8_t *) port_mapping, P2MAP, 1,
            PMAP_DISABLE_RECONFIGURATION);

    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
            GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Initialize compare registers to generate PWM1 */
    MAP_Timer_A_initCompare(TIMER_A1_MODULE, &compareConfig_PWM1);

    /* Configuring Timer_A1 for UpDown Mode and starting */
    MAP_Timer_A_configureUpDownMode(TIMER_A1_MODULE, &upDownConfig);
    MAP_Timer_A_startCounter(TIMER_A1_MODULE, TIMER_A_UPDOWN_MODE);

    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}
/*
 *  ======== PWMTimerMSP432_open ========
 *  @pre    Function assumes that the handle is not NULL
 */
PWM_Handle PWMTimerMSP432_open(PWM_Handle handle, PWM_Params *params)
{
    uintptr_t                     key;
    bool                          timerIsRunning;
    uint8_t                       cyclesPerMicroSec;
    uint32_t                      clockFreq;
    uint32_t                      tempPeriod;
    Timer_A_PWMConfig             pwmConfig;
    PowerMSP432_Freqs             powerFreqs;
    PWMTimerMSP432_Object        *object = handle->object;
    PWMTimerMSP432_HWAttrs const *hwAttrs = handle->hwAttrs;

    if(params == NULL) {
        params = (PWM_Params *) &PWM_defaultParams;
    }

    key = HwiP_disable();

    /*
     * Before opening the PWM instance, we must verify that the Timer is not
     * already open or being used by another source (possibly the Kernel).
     * Additionally, the Timer peripheral could have already been initialized
     * by another PWM instance, so we must verify if any other PWM driver
     * (on the same Timer) is initialized.
     */
    timerIsRunning =
        (TIMER_A_CMSIS(hwAttrs->baseAddr)->rCTL.b.bMC != TIMER_A_STOP_MODE);
    if (object->isOpen ||
        (timerIsRunning && (object->pwmTimerStatus)->activeOutputsMask == 0)) {
        /* Timer already opened or used by source other than PWM driver */
        HwiP_restore(key);
        DebugP_log1("PWM:(%p) timer used by another source.",
            (uintptr_t) handle);
        return (NULL);
    }

    /*
     * Timer capture/compare register 0 is used as the period.  It cannot be
     * used to generate PWM output.
     */
    DebugP_assert(hwAttrs->compareRegister != TIMER_A_CAPTURECOMPARE_REGISTER_0);

    /*
     * Add power management support - PWM driver does not allow performance
     * level changes, low power modes or shutdown while open.
     */
    Power_setConstraint(PowerMSP432_DISALLOW_PERF_CHANGES);
    Power_setConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_0);
    Power_setConstraint(PowerMSP432_DISALLOW_SHUTDOWN_0);
    Power_setConstraint(PowerMSP432_DISALLOW_SHUTDOWN_1);

    PowerMSP432_getFreqs(Power_getPerformanceLevel(), &powerFreqs);
    clockFreq = powerFreqs.SMCLK;
    cyclesPerMicroSec = clockFreq / 1000000;

    /* Assert if period is too large for peripheral */
    tempPeriod = params->period * cyclesPerMicroSec;
    DebugP_assert(tempPeriod <= maxPrescalarValue * maxDutyValue);

    /*
     * Verify if timer has been initialized by another PWM instance.  If so,
     * make sure PWM periods are the same, do not open driver if otherwise.
     */
    if ((object->pwmTimerStatus)->period &&
        (object->pwmTimerStatus)->period != params->period) {
        HwiP_restore(key);
        DebugP_log1("PWM:(%p) differing PWM periods, cannot open driver.",
            (uintptr_t) handle);
        PWMTimerMSP432_close(handle);
        return (NULL);
    }
    else {
        /* PWM timer has not been initialized */
        (object->pwmTimerStatus)->cyclesPerMicroSec = cyclesPerMicroSec;
        (object->pwmTimerStatus)->prescalar =
            PWMTimerMSP432_calculatePrescalar(tempPeriod);
        (object->pwmTimerStatus)->period = params->period;
    }

    /* Mark driver as being used */
    object->isOpen = true;
    (object->pwmTimerStatus)->activeOutputsMask |= object->pwmCompareOutputBit;

    HwiP_restore(key);

    /* Store PWM instance parameters */
    object->dutyMode = params->dutyMode;

    /* Configure PWM output & start timer */
    pwmConfig.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
    pwmConfig.clockSourceDivider = (object->pwmTimerStatus)->prescalar;
    pwmConfig.timerPeriod = tempPeriod / (object->pwmTimerStatus)->prescalar;
    pwmConfig.compareRegister = hwAttrs->compareRegister;
    pwmConfig.compareOutputMode = outputPolarity[params->polarity];
    pwmConfig.dutyCycle = 0;
    MAP_Timer_A_generatePWM(hwAttrs->baseAddr, &pwmConfig);
    MAP_Timer_A_startCounter(hwAttrs->baseAddr, TIMER_A_UP_MODE);

    DebugP_log2("PWM:(%p) opened; period set to: %d", (uintptr_t) handle,
        params->period);

    return (handle);
}
Exemplo n.º 4
0
void StartTimerA0_0()
{
	MAP_Interrupt_enableInterrupt(INT_TA0_0);
	MAP_Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE);
}