Other Parts Discussed in Thread: DRV8803, EK-TM4C1294XL, , DRV8804EVM
Tool/software: Code Composer Studio
Hello,
I am trying to write code on the EK-TM4C1294XL that will produce a PWM wave that controls the DRV8803 on the DRV8803EVM board.
What I want to do is use the EK-TM4C1294XL to turn on and off a solenoid using the DRV8803EVM board, according to the DRV8803 datasheets I need to have a PWM to trigger the motor drive function of the DRV8803. On the DRV8803EVM board, I don't want to use the microcontroller because I am applying external signals from the EK-TM4C1294XL. From my understanding of the DRV8803 timing diagram, I need to have a PWM that will stay high until the solenoid needs to be turned on and then the PWM will go low, am I correct in this thinking?
Based on my understanding I have written the code below. However, when I connect the EK-TM4C1294XL to the DRV8803EVM board (which I believe I have set up correctly according to the diagram) I don't get anything from the outputs of the board. I have pasted the code I am using below.
////***************************************************************************** #include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/adc.h" #include "driverlib/pin_map.h" #include "driverlib/pwm.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" //////***************************************************************************** ////// ////// This function sets up UART0 to be used for a console to display information ////// as the example is running. ////// void GetADC(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif uint32_t pui32ADC0Value[1]; #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 20000000); #else SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif UARTprintf("ADC ->\n"); // UARTprintf(" Type: Single Ended\n"); // UARTprintf(" Samples: One\n"); // UARTprintf(" Update Rate: 250ms\n"); UARTprintf(" Input Pin: AIN0/PE3\n\n"); // // The ADC0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // // For this example ADC0 is used with AIN0 on port E7. // The actual port and pins used may be different on your part, consult // the data sheet for more information. GPIO port E needs to be enabled // so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Select the analog ADC function for these pins. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // // Enable sample sequence 3 with a processor signal trigger. Sequence 3 // will do a single sample when the processor sends a signal to start the // conversion. Each ADC module has 4 programmable sequences, sequence 0 // to sequence 3. This example is arbitrarily using sequence 3. // ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); // // Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in // single-ended mode (default) and configure the interrupt flag // (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic // that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence // 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and // sequence 0 has 8 programmable steps. Since we are only doing a single // conversion using sequence 3 we will only configure step 0. For more // information on the ADC sequences and steps, reference the datasheet. // ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); // // Since sample sequence 3 is now configured, it must be enabled. // ADCSequenceEnable(ADC0_BASE, 3); // // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. // ADCIntClear(ADC0_BASE, 3); // // Sample AIN0 forever. Display the value on the console. // int y; y=0; while(y<5) { // // Trigger the ADC conversion. // ADCProcessorTrigger(ADC0_BASE, 3); // // Wait for conversion to be completed. // while(!ADCIntStatus(ADC0_BASE, 3, false)) { } // // Clear the ADC interrupt flag. // ADCIntClear(ADC0_BASE, 3); // // Read ADC Value. // ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); // // Display the AIN0 (PE3) digital value on the console. // UARTprintf("AIN0 = %4d\r", pui32ADC0Value[0]); UARTprintf("\n"); // // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 250ms arbitrarily. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) SysCtlDelay(ui32SysClock / 12); #else SysCtlDelay(SysCtlClockGet() / 12); #endif y++; } } //////***************************************************************************** void InitConsole(void) { //////// // //////Enable GPIO port A which is used for UART0 pins. //////// // TODO: change this to whichever GPIO port you are using. //////// // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //////// //////// // //////// // Configure the pin muxing for UART0 functions on port A0 and A1. //////// // This step is not necessary if your part does not support pin muxing. //////// // TODO: change this to select the port/pin you are using. //////// // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); //////// //////// // //////// // Enable UART0 so that we can configure the clock. //////// // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //////// //////// // //////// // Use the internal 16MHz oscillator as the UART clock source. //////// // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); //////// //////// // //////// // Select the alternate (UART) function for these pins. //////// // TODO: change this to select the port/pin you are using. //////// // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); //////// //////// // //////// // Initialize the UART for console I/O. //////// // UARTStdioConfig(0, 115200, 16000000); } //////***************************************************************************** #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t g_ui32SysClock; #endif ////////// //////// // ////// // Set the clocking to run directly from the external crystal/oscillator. ////// // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the ////// // crystal on your board. ////// // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) // g_ui32SysClock = SysCtlClockSet((SYSCTL_XTAL_25MHZ| SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 1200000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif //// uint32_t sysclock; //// void main() { float PWM_FREQ; float CPU_FREQ; float pwm_word; int t; int i; InitConsole(); // GetADC(); //// PWM_FREQ = 64000; //31.250kHz CPU_FREQ = 1000000; pwm_word = (1/PWM_FREQ)*CPU_FREQ; sysclock = SysCtlClockFreqSet((SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), CPU_FREQ); // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED); i=0; while(i<20) { SysCtlPWMClockSet(SYSCTL_PWMDIV_1);//Set the clock speed SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); //Enable the correct port SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);//Enable the GPIO port GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);//Define the pine GPIOPinConfigure(GPIO_PG1_M0PWM5); //Comfigure the pin based on the datasheet PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);//Set the modes // UARTprintf("Gen config successful\n"); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 300); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5,PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2)/128); PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true); PWMGenEnable(PWM0_BASE, PWM_GEN_2); UARTprintf("Running1\n"); // GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED); // SysCtlDelay(20000000); i++; GetADC(); } t=0; while(t<20) { SysCtlPWMClockSet(SYSCTL_PWMDIV_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_2); GPIOPinConfigure(GPIO_PG0_M0PWM4); PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_DB_NO_SYNC); UARTprintf("Gen config successful\n"); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, pwm_word); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2)/128); PWMOutputState(PWM0_BASE, PWM_OUT_4_BIT, true); PWMGenEnable(PWM0_BASE, PWM_GEN_2); UARTprintf("Running2\n"); // SysCtlDelay(20000000); t++; GetADC(); } //// }
Any help with this would be much appreciated.
Thank you