Hello people.
I search a lot in the forum and in the internet, but I don't a solution to my problem. I need to trigger the ADC with the PWM, but the code that I developed to do this, don't work! Get stuck in the function while(!ROM_ADCIntStatus(ADC0_BASE, 0, false)). Could you guys help me? I'm using the Connected LaunchPad EK-TM4C1294XL.
#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/rom.h" #include "driverlib/rom_map.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_adc.h" #include "driverlib/debug.h" #include "driverlib/adc.h" #include "driverlib/fpu.h" uint32_t ui32PWM_Wi=0; uint32_t g_ui32SysClock = 0; uint32_t pui32ADC0Value[1]; #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif //***************************************************************************** // // 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); //set the value that the ADC convert PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ui32PWM_Wi); } //***************************************************************************** // // Configure PWM0 for a load interrupt. This interrupt will trigger everytime // the PWM0 counter gets reloaded. // //***************************************************************************** void ConfigureADC0(void) { // // Enable clock to ADC0. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); ROM_IntDisable(INT_ADC0SS0); ROM_ADCIntDisable(ADC0_BASE,0); ROM_ADCSequenceDisable(ADC0_BASE,0); // // Configure ADC0 Sample Sequencer 0 for processor trigger operation. // ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PWM0, 0); // // Configure ADC0 sequencer 0 for a single sample of the temperature // sensor. // ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); // // Enable the sequencer. // ROM_ADCSequenceEnable(ADC0_BASE, 0); ROM_ADCHardwareOversampleConfigure(ADC0_BASE,64); // // Clear the interrupt bit for sequencer 0 to make sure it is not set // before the first sample is taken. // ROM_ADCIntClear(ADC0_BASE, 0); ROM_ADCIntEnable(ADC0_BASE,0);//ativa interrupção do ADC ROM_IntEnable(INT_ADC0SS0); } void IntADC0Handler(void) { // // Read the analog voltage measurement. // ROM_ADCIntClear(ADC0_BASE, 0); ROM_ADCSequenceDataGet(ADC0_BASE, 0, pui32ADC0Value); } void Configure_PWM0(void) { // // Set the PWM clock to the system clock. // SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // // The PWM peripheral must be enabled for use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // // For this example PWM0 is used with PortF Pin1. The actual port and pins // used may be different on your part, consult the data sheet for more // information. GPIO port F needs to be enabled so these pins can be used. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Configure the GPIO pin muxing to select PWM00 functions for these pins. // This step selects which alternate function is available for these pins. // This is necessary if your part supports GPIO pin function muxing. // Consult the data sheet to see which functions are allocated per pin. // ROM_GPIOPinConfigure(GPIO_PF1_M0PWM1); // // Configure the PWM function for this pin. // Consult the data sheet to see which functions are allocated per pin. // ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1); // // Configure the PWM0 to count down without synchronization. // ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // // Set the PWM period to 6kHz. To calculate the appropriate parameter // use the following equation: N = (1 / f) * SysClk. Where N is the // function parameter, f is the desired frequency, and SysClk is the // system clock frequency. // In this case you get: (1 / 6kHz) * 120MHz = 20000 cycles. Note that // the maximum period you can set is 2^16. // ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 20000); // // For this example the PWM0 duty cycle will be variable. The duty cycle // will start at 0 (0 * 64000 cycles = 0 cycles) and will increase // with the value converted with the ADC (ADC_VALUE * 64000 cycles = X cycles). // The duty cycle varies with the converted value of the ADC. This dynamic adjustment of the pulse // width is done in the PWM0 load interrupt, which increases the duty // cycle everytime the reload interrupt is received. // ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 20); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Allow PWM0 generated interrupts. This configuration is done to // differentiate fault interrupts from other PWM0 related interrupts. // ROM_PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0); // // Enable the PWM0 LOAD interrupt on PWM0. // ROM_PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD); // // Enable the PWM0 interrupts on the processor (NVIC). // ROM_IntEnable(INT_PWM0_0); // // Enable the PWM0 output signal (PF1). // ROM_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true); // // Enables the PWM generator block. // ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0); } int main(void) { //Set clock to 120MHz g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); ROM_FPUEnable(); //Enable Hardware Floating Point Unit ROM_FPUStackingEnable(); //Enable floating point operation ins ISRs ConfigureADC0(); Configure_PWM0(); // // Loop forever while the PWM signals are generated and PWM0 interrupts // get received. // while(1) { // // Wait for the ADC to finish taking the sample // while(!ROM_ADCIntStatus(ADC0_BASE, 0, false)) { } // // Clear the interrupt // ROM_ADCIntClear(ADC0_BASE, 0); // // Set the new value cycle of the PWM - The value 4.884005 is because the max adc value //is 4095 by 20000 that is the value max cycles value of the PWM // ui32PWM_Wi = (int)pui32ADC0Value[0]*4.884005; } }
Thanks a Lot!!!