Dear All
I am trying to configure the ADC trigger using PWM i am trying to get RGB values from a color sensor i have configured my PWM to operate at 633Khz i want to trigger the ADC for sensing the analoge voltage and the same rate for that i need to configure the ADC trigger from PWM
here with i am attaching the code for the same i am unable to get the ADC interrupt , i have assigned the proper interrupt in tm4c123gh6pm_startup_ccs.c
pls let me know what is the mistake i have done in this code
i ma trying to switch on the RGB led based on the pulse generated in the PWM interrupt itself .
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/adc.h"
int Count;
uint32_t ui32ADC0Value[4];
//*****************************************************************************
//
// The interrupt handler for the for PWM0 interrupts.
//
//*****************************************************************************
void
PWM0IntHandler(void)
{
//
// Clear the PWM0 LOAD interrupt flag. This flag gets set when the PWM
// counter gets reloaded.
//
PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD);
Count++;
if(Count==2)GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0);
////RED LED ON
if(Count==83)GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,GPIO_PIN_4);
if(Count==253)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,GPIO_PIN_2);
}
if(Count==254)GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0);
if(Count==336)GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,GPIO_PIN_5);
if(Count==506)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,GPIO_PIN_2);
}
if(Count==507)GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0);
if(Count==589)GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,GPIO_PIN_6);
if(Count==759)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,GPIO_PIN_2);
Count=0;
}
if(Count>=85)
{
}
}
void ADCIntHandler(void)
{
ADCIntClear(ADC0_BASE, 0);
ADCSequenceDataGet(ADC0_BASE, 0, ui32ADC0Value);
}
//*****************************************************************************
//
// Configure PWM0 for a load interrupt. This interrupt will trigger everytime
// the PWM0 counter gets reloaded. In the interrupt, 0.1% will be added to
// the current duty cycle. This will continue until a duty cycle of 75% is
// received, then the duty cycle will get reset to 0.1%.
//
//*****************************************************************************
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_2 | SYSCTL_USE_PLL| SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);//FOR Blue Led
GPIOPinConfigure(GPIO_PB6_M0PWM0);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2);
//////////ADC Configuration
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PWM0 , 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 1,ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 3, 2, ADC_CTL_CH2| ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);
ADCIntEnable(ADC0_BASE, 3);
////PWM COnfiguration
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 100);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 50);
IntMasterEnable();
PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0);
PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD);
IntEnable(INT_PWM0_0);
IntEnable(INT_ADC0SS3);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,GPIO_PIN_2);
while(1)
{
}
}