Hi!
First of all, I'm very new to the TI Stellaris boards. I'm trying to read out a produced PWM signal. I am using a EK-LM3S9B90 eva Board.
So, here is my code. As you can see, I have no idea how to get to the width of the PWM signal peak. I expect a peak of about 1ms width (which should be calculated in the code) and a period of 20ms const.
Is there a possibility to read out the point where the interrupts on both edges are called and write them into variables? So it should be easy to get the pulse width, as I think... This may sound dumb, but my programming skills are in their infant stadium.
Help is much appreciated!
void SetPins(void) // I/O Pins Konfigurieren { // GPIO Port D aktivieren SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // GPIO Port D, Pin 4 als CCP (Capture Compare PWM) genutzt GPIOPinConfigure(GPIO_PD4_CCP3); // GPIO Port D, Pin 3 als CCP für PWM-Auslesen mittel Capture GPIOPinConfigure(GPIO_PE3_CCP1); // Settings für CCP Pins. Nötig für Timer/PWM GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_4); GPIOPinTypeTimer(GPIO_PORTE_BASE, GPIO_PIN_3); // USR_LED ausschalten GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0); } void InitConsole(void) // UART Initialisieren { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); } /* void Timer0BIntHandler(void) // Timer0B Handler für Capture INTs { // Timer INT Flag löschen TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); //if() IntDisable(INT_TIMER0B); // INT deaktivieren TimerIntDisable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // INT verbieten TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // offene Flags löschen } */ int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Aktivierung Timer SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); SetPins(); InitConsole(); // Timerkonfigurierung TimerConfigure(TIMER0_BASE, TIMER_CFG_B_CAP_COUNT_UP); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM); // 5% Duty Cycle für PWM TimerLoadSet(TIMER1_BASE, TIMER_B, 64000); TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) - 3200); // bei Peak an CCP1 INT auslösen TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); // Timer einschalten TimerEnable(TIMER0_BASE, TIMER_B); TimerEnable(TIMER1_BASE, TIMER_B); // Clearen und Erlauben des TimerINT TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_CAPB_EVENT); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_CAPB_EVENT); // INTs erlauben (vgl. sei()) IntMasterEnable(); PeakTime = ???; UARTprintf("Breite Peak: %d\n", PeakTime); // Breite Peak als Zählerstand Timer PeakTime = 0; while(1) { } }