//-------------------------------- void pwm_stepper::Initialize() { g_pTheStepper = this; SysCtlPWMClockSet(SYSCTL_PWMDIV_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA6_M1PWM2); GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6); PWMGenConfigure(Base, Generator, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // Set the PWM period to 250Hz. 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 / 250Hz) * 16MHz = 64000 cycles. Note that // the maximum period you can set is 2^16. PWMGenPeriodSet(Base, Generator, Default_StartSpeed); PWMPulseWidthSet(Base, PWM_OUT_2, 64); // Allow PWM1 generated interrupts. This configuration is done to // differentiate fault interrupts from other PWM1 related interrupts. PWMIntEnable(Base, PWM_INT_GEN_1); // Enable the PWM1 LOAD interrupt on PWM1. PWMGenIntTrigEnable(Base, Generator, PWM_INT_CNT_LOAD); // Enable the PWM1 interrupts on the processor (NVIC). IntEnable(INT_PWM1_1); // Enable the PWM1 output signal (PA6). // PWMOutputInvert(Base, PWM_OUT_2_BIT, true); PWMOutputState(Base, PWM_OUT_2_BIT, true); }
void InitGPIO (void) { // GPIO test initialisation SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0 | SYSCTL_PERIPH_PWM); SysCtlPWMClockSet(SYSCTL_PWMDIV_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // airspeed output SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // transponder output SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // airspeed response pin SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // transponder response pin // Configure airspeed input GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, UUT_AIRSPEED_RESPONSE_PIN_PE3); GPIOIntTypeSet(GPIO_PORTE_BASE, UUT_AIRSPEED_RESPONSE_PIN_PE3, GPIO_RISING_EDGE); GPIOPortIntRegister(GPIO_PORTE_BASE, &airspeed_response_isr); // Configure transponder input GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, UUT_TRANSPONDER_RESPONSE_PIN_PB3); GPIOIntTypeSet(GPIO_PORTB_BASE, UUT_TRANSPONDER_RESPONSE_PIN_PB3, GPIO_RISING_EDGE); GPIOPortIntRegister(GPIO_PORTB_BASE, &transponder_response_isr); // Configure airspeed pulse generation GPIOPinTypePWM(GPIO_PORTD_BASE, (1<<1)); // Airspeed output TODO: make pin macro PWMGenDisable(PWM0_BASE, PWM_GEN_0); PWMIntDisable(PWM0_BASE, PWM_GEN_0); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD); // configure pwm for end-of-cycle interrupt PWMGenIntRegister(PWM0_BASE, PWM_GEN_0, airspeed_pulse_isr); // Configure transponder pulse generation GPIOPinTypePWM(GPIO_PORTF_BASE, (1<<3)); // Transponder output TODO: make pin macro PWMGenDisable(PWM0_BASE, PWM_GEN_2); PWMIntDisable(PWM0_BASE, PWM_GEN_2); PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_LOAD); // configure pwm for end-of-cycle interrupt PWMGenIntRegister(PWM0_BASE, PWM_GEN_2, transponder_pulse_isr); // Configure UUT reset signal SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_4); GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4, GPIO_PIN_4); }
void camera_init() { Serial_puts(UART_DEBUG_MODULE, "inside \"camera_init\"\r\n", 100); // Calculate the PWM clock frequency camera_PWMClockFreq = SysCtlClockGet() / CAMERA_CLOCK_DIV; DEBUG_LINE("camera_init"); // Enable the PWM peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // Enable the GPIO port SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Configure PD0 as the PWM output for the drive motor GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7); GPIOPinConfigure(GPIO_PB7_M0PWM1); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); GPIOPinConfigure(GPIO_PB4_M0PWM2); // Set the camera clock pulse period PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, CAMERA_SAMPLE_PERIOD - 1); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, (CAMERA_SAMPLE_PERIOD / 2) - 1); // Set the camera enable pulse period PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, (CAMERA_SAMPLE_PERIOD * CAMERA_SAMPLES) - 1); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, ((CAMERA_SAMPLE_PERIOD / 2) * 2) - 1); DEBUG_LINE("camera_init"); // Enable the PWM output PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_2_BIT, true); PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMGenEnable(PWM0_BASE, PWM_GEN_1); PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0_BIT | PWM_GEN_1_BIT); // Enable PWM trigger on zero count on Generator 0 PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_TR_CNT_ZERO); // PWM_TR_CNT_ZERO/PWM_TR_CNT_LOAD // Trigger an interrupt on GEN1 load (to setup the uDMA transfer on a consistent time boundary) PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_1, PWM_INT_CNT_LOAD); DEBUG_LINE("camera_init"); /******************************************** * ADC CONFIGURATION * ******************************************** */ // Enable ADC0 module SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); DEBUG_LINE("camera_init"); ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1); DEBUG_LINE("camera_init"); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Camera Far GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Camera Near GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); DEBUG_LINE("camera_init"); // Configure and enable the ADC sequence; single sample ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PWM0, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); DEBUG_LINE("camera_init"); ADCSequenceDMAEnable(ADC0_BASE, 3); DEBUG_LINE("camera_init"); // Start writing into the first buffer camera_DBSelected = 0; current_Camera = FAR; // Expose the other buffer camera_buffer = camera_DoubleBuffer[1]; /******************************************** * uDMA CONFIGURATION * ******************************************** */ // Enable the uDMA for normal and sleep operation SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); uDMAEnable(); DEBUG_LINE("camera_init"); // Set the position of the uDMA control table uDMAControlBaseSet(uDMAControlTable); // Put the uDMA table entry for ADC3 into a known state uDMAChannelAttributeDisable(UDMA_CHANNEL_ADC3, UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // Configure the primary and alternate uDMA channel structures uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); // Configure the primary and alternate transfers for ping-pong operation uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, (void*) (ADC0_BASE + ADC_O_SSFIFO3), camera_DoubleBuffer[0], CAMERA_SAMPLES); uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, (void*) (ADC0_BASE + ADC_O_SSFIFO3), camera_DoubleBuffer[1], CAMERA_SAMPLES); DEBUG_LINE("camera_init"); // Enable the ADC3 uDMA channel uDMAChannelEnable(UDMA_CHANNEL_ADC3); // Enable interrupts // IntEnable(INT_ADC0SS3); // ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS3); IntEnable(INT_PWM0_1); PWMIntEnable(PWM0_BASE, PWM_INT_GEN_1); DEBUG_LINE("camera_init"); }
void hardware_init(void) { //Set PWM clock at the same frequency as system clock SysCtlPWMClockSet(SYSCTL_PWMDIV_1); /* * Inverter system setup * period : Switching Frequency : 20Khz * cycle : Duty Cycle SPWM * deadband : Deadband */ inv.period = SysCtlClockGet()/20000; inv.deadband = 25*inv.period/100; inv.cycle = inv.period*500/1000; /* * Boost converter system setup * period: Switching frequency: 20kHz * cycle: Duty cycle * deadband: Deadband */ conv.period = inv.period; conv.deadband = inv.deadband; conv.cycle = conv.period*500/1000; /* * Setup SPWM on PWM0 GEN0 and GEN1 * PB6 : PWM0 GEN0 * PB7: PWM0 GEN1 */ SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralReset(SYSCTL_PERIPH_PWM0); SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB6_M0PWM0); GPIOPinConfigure(GPIO_PB7_M0PWM1); GPIOPinTypePWM(GPIO_PORTB_BASE, (GPIO_PIN_6 | GPIO_PIN_7)); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_SYNC_LOCAL | PWM_GEN_MODE_FAULT_UNLATCHED | PWM_GEN_MODE_DB_NO_SYNC)); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, inv.period-1); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, inv.cycle); PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, 13, 0); PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true); PWMSyncUpdate(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT); /* * Setup boost converter pwm on PWM1 * PA6: PWM1 GEN1 */ SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralReset(SYSCTL_PERIPH_PWM1); SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA6_M1PWM2); //Map PWM1, P1 OP2 to PA6 GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6); //Configure PA6 as PWM PWMGenConfigure(PWM1_BASE, PWM_GEN_1, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_NO_SYNC| PWM_GEN_MODE_DB_NO_SYNC)); //Configure PWM1, G1 as Down counter with no sync of updates PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, conv.period-1); //Set Period of PWM1, G1 PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, conv.cycle); //Set phase shift PWMIntEnable(PWM1_BASE, PWM_INT_GEN_1); PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_1, PWM_TR_CNT_LOAD|PWM_INT_CNT_LOAD); IntPrioritySet(INT_PWM1_1, 0x02); PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT, true); PWMGenEnable(PWM1_BASE, PWM_GEN_1); /* * Setup ISR for updating SPWM duty cycle */ uint32_t ui32TimIntSine = SysCtlClockGet()/200000; SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER2); TimerConfigure(TIMER2_BASE, TIMER_CFG_A_PERIODIC); TimerLoadSet(TIMER2_BASE, TIMER_A, ui32TimIntSine-1); TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); IntPrioritySet(INT_TIMER2A, 0x03); TimerEnable(TIMER2_BASE, TIMER_A); uint32_t ui32TimIntIcontrol = SysCtlClockGet()/40000; SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_A_PERIODIC); TimerLoadSet(TIMER1_BASE, TIMER_A, ui32TimIntIcontrol-1); TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); IntPrioritySet(INT_TIMER1A, 0x01); TimerEnable(TIMER1_BASE, TIMER_A); /* * Setup PF1 as debug pin */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOF); HWREG(0x40005520) = 0x4C4F434B; HWREG(0x40005524) |= 0x01; HWREG(0x40005520) = 0x00; GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4); GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE); IntPrioritySet(INT_GPIOF,0x00); GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); /* * Setup ADC * Configuration currently in discussion * Interrupt at end might not be necessary */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0); ADCHardwareOversampleConfigure(ADC0_BASE, 2); ADCSequenceDisable(ADC0_BASE, 2); ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PWM1, 0x00); HWREG(0x4003801C) |= 0x1000; //Sec 13.4.2 Pt 3 ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH2); ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH3|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 2); }
//***************************************************************************** // // Configure PWM0 for a load interrupt. This interrupt will trigger everytime // the PWM0 counter gets reloaded. In the interrupt, 0.1% will be added to // the current duty cycle. This will continue until a duty cycle of 75% is // received, then the duty cycle will get reset to 0.1%. // //***************************************************************************** int main(void) { // // 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. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the PWM clock to the system clock. // SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for PWM0 operation. // InitConsole(); // // Display the setup on the console. // UARTprintf("PWM ->\n"); UARTprintf(" Module: PWM0\n"); UARTprintf(" Pin: PD0\n"); UARTprintf(" Duty Cycle: Variable -> "); UARTprintf("0.1%% to 75%% in 0.1%% increments.\n"); UARTprintf(" Features: "); UARTprintf("Variable pulse-width done using a reload interrupt.\n\n"); UARTprintf("Generating PWM on PWM0 (PD0) -> "); // // The PWM peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); // // For this example PWM0 is used with PortD Pin0. The actual port and pins // used may be different on your part, consult the data sheet for more // information. GPIO port D needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // 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. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PD0_PWM0); // // Configure the PWM function for this pin. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); // // Configure the PWM0 to count down without synchronization. // PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // // Set the PWM period to 250Hz. 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 / 250Hz) * 16MHz = 64000 cycles. Note that // the maximum period you can set is 2^16. // PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 64000); // // For this example the PWM0 duty cycle will be variable. The duty cycle // will start at 0.1% (0.01 * 64000 cycles = 640 cycles) and will increase // to 75% (0.5 * 64000 cycles = 32000 cycles). After a duty cycle of 75% // is reached, it is reset to 0.1%. This dynamic adjustment of the pulse // width is done in the PWM0 load interrupt, which increases the duty // cycle by 0.1% everytime the reload interrupt is received. // PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, 64); // // Enable processor interrupts. // IntMasterEnable(); // // Allow PWM0 generated interrupts. This configuration is done to // differentiate fault interrupts from other PWM0 related interrupts. // PWMIntEnable(PWM_BASE, PWM_INT_GEN_0); // // Enable the PWM0 LOAD interrupt on PWM0. // PWMGenIntTrigEnable(PWM_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD); // // Enable the PWM0 interrupts on the processor (NVIC). // IntEnable(INT_PWM0); // // Enable the PWM0 output signal (PD0). // PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true); // // Enables the PWM generator block. // PWMGenEnable(PWM_BASE, PWM_GEN_0); // // Loop forever while the PWM signals are generated and PWM0 interrupts // get received. // while(1) { // // Print out indication on the console that the program is running. // PrintRunningDots(); } }
//***************************************************************************** // //! Initializes the PWM control routines. //! //! This function initializes the PWM module and the control routines, //! preparing them to produce PWM waveforms to drive the power module. //! //! \return None. // //***************************************************************************** void PWMInit(void) { // // Make the PWM pins be peripheral function. // GPIOPinTypePWM(PIN_PHASEA_LOW_PORT, PIN_PHASEA_LOW_PIN | PIN_PHASEA_HIGH_PIN); GPIOPinTypePWM(PIN_PHASEB_LOW_PORT, PIN_PHASEB_LOW_PIN | PIN_PHASEB_HIGH_PIN); GPIOPinTypePWM(PIN_PHASEC_LOW_PORT, PIN_PHASEC_LOW_PIN | PIN_PHASEC_HIGH_PIN); // // Configure the three PWM generators for up/down counting mode, // synchronous updates, and to stop at zero on debug events. // PWMGenConfigure(PWM0_BASE, PWM_GEN_0, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_STOP)); PWMGenConfigure(PWM0_BASE, PWM_GEN_1, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_STOP)); PWMGenConfigure(PWM0_BASE, PWM_GEN_2, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_STOP)); // // Set the initial duty cycles to 50%. // g_ulPWMDutyCycleA = 32768; g_ulPWMDutyCycleB = 32768; g_ulPWMDutyCycleC = 32768; // // Configure the PWM period, duty cycle, and dead band. The initial period // is 1 KHz (for triggering the ADC), which will be increased when the // motor starts running. // PWMClearDeadBand(); PWMSetFrequency(); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PWM_CLOCK / 1000); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, PWM_CLOCK / 1000); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, PWM_CLOCK / 1000); PWMUpdateDutyCycle(); // // Enable the PWM generators. // PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMGenEnable(PWM0_BASE, PWM_GEN_1); PWMGenEnable(PWM0_BASE, PWM_GEN_2); // // Synchronize the time base of the generators. // PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT); // // Configure an interrupt on the zero event of the first generator, and an // ADC trigger on the load event of the first generator. // PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_ZERO); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_ZERO | PWM_TR_CNT_LOAD); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_1, 0); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_2, 0); PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0); IntEnable(INT_PWM0_0); IntEnable(INT_PWM0_1); IntEnable(INT_PWM0_2); // // Set all six PWM outputs to go to the inactive state when a fault event // occurs (which includes debug events). // PWMOutputFault(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT), true); // // Disable all six PWM outputs. // PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT), false); // // Ensure that all outputs are not-inverted. // PWMOutputInvert(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT), false); }