In the TM4C123GHPM datasheet, there's the following example shown in the picture.
I notice that there are no Tivaware methods that allow me to set the PWM0CMPA values. I want to utilize this example to create a varying duty cycle PWM that mimics a sine curve after filtering. The idea is having the triangle wave in PWM gen compare with an incoming, processed sinewave (so the value is an ADC reading that goes through some processing) and if the triangle >sine, I would output high on PWMA and low otherwise. Ideally, these would be at the same height, where both peaks are at 3300. Also, I want to have this switching happen at 10kHz. Would my code be as follows?
I'm assuming:
1) The Load value is the peak of the triangle waveform for the PWM Gen (based on what I understand of the datasheet)
2) I would use a timer interrupt to have the switching happen at every 100us (10kHz)
3) To have the comparison change, in the timer interrupt, I would change the PWM0_0_CMPA_R value to match my current sinewave sample.
4) To get the height of the triangle to be 3300, so if it's 80Mhz clock frequency, I want the reload to be at 3299 when setting the PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, SysCtlClockGet()/24250) method.
5) In the general setup, I should set PWM_O_0_CTL=x80 //GenA is locally synchronized and PWM0CMPA= 0x000000E0 // Drive pwmA Low when it's Comparator A Up and high when it's Comparator A down, while doing nothing when counter=0 and Load. How do I ensure the output is high while it's counting up to Compactor A?
// Setup SysCtlPWMClockSet(SYSCTL_PWMDIV_1); //set PWM clock to processor clock with multiplier of 1 SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB4_M0PWM2); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_DB_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, SysCtlClockGet()/24250); //I want the height of the triangle to be 3300, so if it's 80Mhz clock frequency, I want the reload to be PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 2500* 50/100); PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true); PWMDeadBandEnable(PWM0_BASE, PWM_GEN_1, 0xF, 0xF); GPIO_PORTB_DR8R_R |=0xC0; // 8mA output PWMGenEnable(PWM0_BASE, PWM_GEN_1);