int main(void) { Config_Puertos(); Interrupciones(); SysTick_Config(ticks); Config_Eintx(eint2, puerto_eint2); Config_Uart(); Config_ADC(); config_timer(timer1, match1, prescaler1); while(1) { if ((botonPanic==1) | (tempSen > tempTemp)) Cooler_ON(); else if (tempSen < (tempTemp-2)) Cooler_OFF(); } return 0; }
main() { phase=0; w=2*3.1415927*100; // Frequencia fundamental do sinal gerado = 100Hz Ts=1/10000.0; // Interrupção do ePWM1 =10kHz -> taxa de amostragem offset=7500; j=0; segundos_count=0; // Step 1. InitSysCtrl(); // Step 2. Initialize GPIO: // This example function is found in the DSP2833x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // Step 3. DINT; // Initialize the PIE control registers to their default state. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected register PieVectTable.ADCINT = &adc_isr; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; //desabilita clk para ePWMx EDIS; InitEPwm1Example(); //Configura ePWM1 EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//habilita clk para ePWMx EDIS; InitAdc(); // For this example, init the ADC Config_ADC(); // For this example, config the ADC // Step 5. User specific code, enable interrupts: EALLOW; GpioDataRegs.GPACLEAR.bit.GPIO31 = 1; // Reset output latch - Turn on LED1 GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0; // GPIO31 = GPIO31 GpioCtrlRegs.GPADIR.bit.GPIO31 = 1; // GPIO31 = output GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // Reset output latch - Turn on LED2 GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO34 = GPIO34 GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // GPIO34 = output //Configure ePWM-1 pins using GPIO regs //Enable internal pull-up for the selected pins */ GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; // Enable pull-up on GPIO0 (EPWM1A) GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; // Enable pull-up on GPIO1 (EPWM1B) GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B EDIS; // Enable ADCINT in PIE PieCtrlRegs.PIEIER1.bit.INTx6 = 1; IER |= M_INT1; // Enable CPU Interrupt 1 EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // Wait for ADC interrupt ConversionCount = 0; while(1) //loop infinito { asm(" NOP"); if(segundos_count >=2) { segundos_count=0; //Zera contador de segundos ConversionCount = 0; // habilita gravação da aquisição nos vetores a cada 2 segundos A3=A3+200; //Incrementa amplitude do terceiro harmônico - sinal de controle PWM if (A3>=2000) A3=0; } } }