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.

Trouble triggering ADC with PWM



I am using the Tiva C launchpad and CCS v5.4.

I am trying to setup the ADC to sample periodically based on a pwm signal. I have verified using an oscilloscope that I have the pwm working. When I run my code it gets stuck at "while(!ADCIntStatus(ADC0_BASE, 0, false))" and nothing is loaded into memory. I am not sure why this happens. I have not been able to find a problem with my setup. Code is below:

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

unsigned int testValues[5] = {0,0,0,0,0};


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

int main(void)
{

SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);

SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, BLUE_LED|GREEN_LED);

PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 1024);
PWMPulseWidthSet(PWM0_BASE, PWM_GEN_0, 512);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PB6_M0PWM0);
PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);

GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);
ADCSequenceConfigure(ADC0_BASE,0,ADC_TRIGGER_PWM0,0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 0);
ADCIntClear(ADC0_BASE, 0);
//ADCIntEnable(ADC0_BASE,0);

while(1)
{

while(!ADCIntStatus(ADC0_BASE, 0, false))
{
} //wait for ADC to finish

ADCSequenceDataGet(ADC0_BASE, 0, testValues);

ADCIntClear(ADC0_BASE, 0);

// ADCSequenceEnable(ADC0_BASE, 0);


}
}

  • Might your code benefit from:

    PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0,      
                                      PWM_INT_CNT_ZERO | PWM_TR_CNT_LOAD);

    highlighted param. in particular?  (non-highlight - for when you engage PWM0 interrupt)

    Appears that you've properly, "ADCSequenceConfigure(ADC0_BASE,0,ADC_TRIGGER_PWM0,0);"

    Minus the mating, PWM Trigger (as shown) - your ADC Sequence is unlikely to complete...

    Do not like your, "PWMGenEnable(PWM0_BASE, PWM_GEN_0);" which occurs long prior to pinconfig/pintype et. al. 

    And, "PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);" provisions for, "PWM_OUT_1_BIT" - which my quick scan finds nowhere w/in your listing...

    You are almost there...