This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Help!!! Triggering ADC0 Interrupts with PWM1.

Other Parts Discussed in Thread: TM4C1231H6PM, TM4C123GH6PM

I tried to configure an adc interrupt when the pwm1 generates the zero signal.  The trigger from the pwm never wakes the adc. It's strange, when I triggered the adc with adc trigger processor it works. I already modified my tm4c1231h6pm_startup_ccs.c file.  

This is my code. I tried everything

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"

#define PWM_FREQUENCY 60
uint32_t muestrasPot[4]={0,0,0,0};
int main(void)
{
volatile uint32_t ui32Load;
volatile uint32_t ui32PWMClock;
volatile uint8_t ui8Adjust;
ui8Adjust = 45;

ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);


ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 |GPIO_PIN_3);

ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinConfigure(GPIO_PD0_M1PWM0);

HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;


ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_INT);

ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0|ADC_TRIGGER_PWM_MOD1, 0);

ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH8);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH8);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH8);
ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH8|ADC_CTL_IE|ADC_CTL_END);
ROM_ADCSequenceEnable(ADC0_BASE, 1);

ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

ui32PWMClock = ROM_SysCtlClockGet() / 64;
ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);

ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
ROM_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);
ROM_PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_0, PWM_TR_CNT_ZERO);

ROM_ADCIntEnable(ADC0_BASE, 1);
ROM_IntEnable(INT_ADC0SS1);
ROM_ADCIntClear(ADC0_BASE, 1);
ROM_IntMasterEnable();

while(1)
{
}

}

void ADCSeq1IntHandler(void)
{
ADCIntClear(ADC0_BASE, 1);
ADCSequenceDataGet(ADC0_BASE, 1, muestrasPot);
}

  • You are so, so close.  Try adding parameter, "PWM_TR_CNT_LOAD" to function, "ROM_PWMGenIntTrigEnable()."

    While you've enabled the interrupt - parameter (above) triggers the ADC via the PWM module.

    (and do pass our regards to user 3907002...)

  • I tried to adding that parameter PWM_TR_CNT_LOAD and it still doesn't work.

    If you find some other trouble please tell me.

    Thank you.

  • Well - that's no good.

    Suggested that param. as we've used it successfully for past 4+ years w/one of our BLDC Motor Controllers.  (we employ up/down counting - not your down counting - this insures that ADC is triggered during the center of the PWM signal - improving measurement accuracy.)

    To guide you - here are the parameters available for PWM-based triggering:

    #define PWM_TR_CNT_ZERO      0x00000100  // Trig if COUNT = 0

    #define PWM_TR_CNT_LOAD      0x00000200  // Trig if COUNT = LOAD

    #define PWM_TR_CNT_AU           0x00000400  // Trig if COUNT = CMPA U

    #define PWM_TR_CNT_AD           0x00000800  // Trig if COUNT = CMPA D

    #define PWM_TR_CNT_BU           0x00001000  // Trig if COUNT = CMPA U

    #define PWM_TR_CNT_BD           0x00002000  // Trig if COUNT = CMPA D

    Perhaps your use of, "PWM_TR_CNT_ZERO" will better match your App - worth a try...

  • Hello user3907001,

    It seems that there is a bug in the ROM and Flash version of the API.

    I could get the interrupt to work by adding the line after the following API call

    ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0|ADC_TRIGGER_PWM_MOD1, 0);

    HWREG(ADC0_BASE+ADC_O_TSSEL) = 0x10;

    Regards

    Amit

  • @ Amit,

    Thanks for that - surely helps poster.

    Our Stellaris version 9453 evidences no such bug - our PWM Gen reliably/repeatedly generates the ADC trigger as our post indicated.  (there's no mention of any such, "TRIGGER_PWM_MOD1" anywhere w/in StellarisWare.)

    Gotchas flying fast/furious - rebrand exercise appears not as "automatic" as some thought/hoped...

  • Hello cb1

    This I believe was added in TivaWare 2.1.0 version, for both PWM0 and PWM1 mapping

    Regards

    Amit

  • I'm trying to use PWM running on 333usec to be a source on triggering ADC sequencer.

    Notice this thread about the issue mentioning a bug fixed on TIVEWARE 2,1 


    Is it possible to use this method on Tiva2.0.1?

    Is there s code example showing such configuration ?

    Thanks,

    Michael

  • Hello Michael

    Not on the older version of TivaWare. If the bug has been fixed (based on the last thread), then it must be 2.1.1.71 or 2.1.2.111 (the last be the latest)

    Regards
    Amit