Hello
I am trying to have 4 PWM waveforms in 2 sets, each set has two complimentary signals with a deadband and the two sets are phase shifted. The duty cycle of both the PWM generators are 50% and I need to control the phase shift.
The way I am trying to achieve this is to have the first set with an up/down pwm counter with a period of switching frequency. For the second phase shifted I have a down counter with twice the switching frequency and I want to toggle the output at the compare value. I am trying to write to HWREG PWMGENA but it seems to have no effect. Code below.
/*
* main.c
*/
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_hibernate.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/hibernate.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/pwm.h"
#include "utils/uartstdio.h"
#include "utils/cmdline.h"
#include "drivers/rgb.h"
#include "drivers/buttons.h"
#include "dab_data.h"
duty_t duty;
int main(void) {
FPUEnable();
FPUStackingEnable();
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
duty.period1 = SysCtlClockGet()/100000;
duty.deadband1 = duty.period1 * 5/100;
duty.cycle1 = duty.period1 >> 1;
duty.period2 = duty.period1 >> 1;
duty.deadband2 = duty.period2 * 5/100;
duty.cycle2 = duty.period2 >> 1;
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB6_M0PWM0);
GPIOPinConfigure(GPIO_PB7_M0PWM1);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, duty.period1);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, duty.cycle1);
PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, duty.deadband1>>1,
duty.deadband1>>1);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT , true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA6_M1PWM2);
GPIOPinConfigure(GPIO_PA7_M1PWM3);
GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);
GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_7);
PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN |
PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, duty.period2);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, duty.cycle2);
PWMDeadBandEnable(PWM1_BASE, PWM_GEN_1, duty.deadband2 >> 1,
duty.deadband2 >> 1);
PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT , true);
HWREG(PWM1_BASE+PWM_GEN_1+0x064) = 0x440;
PWMGenEnable(PWM1_BASE, PWM_GEN_1);
while(1)
{
}
return 0;
}
Could someone please help me out here.
Thank you gain