void Init_Hard(void){ Init_CLK(); gpio_init(); externalInterrupt_CcCv_init(); InitDelTim(); delay_ms(100); Init_Beep(); Init_Timer4(); //FAN_PWM Init_Encoder(); InitAdc(); Init_DAC_CH1(); Init_DAC_CH2(); Init_DS18B20(); Init_PVD(); Init_EXTI1(); Init_SPI2(); uart_init(USART3, BR38400); lcd_init (); //Глючная инициализация lcd_init (); lcd_init (); lcd_init (); timMeasInit(); //DEBUG }
/*! Configure the pins used for reading the battery state and * charging the battery. */ void InitBattery(void) { // enable the resistor on the interface pins to the battery charger BAT_CHARGE_REN |= BAT_CHARGE_OPEN_DRAIN_BITS; // Start with these as pull downs so we use less current BAT_CHARGE_OUT &= ~BAT_CHARGE_OPEN_DRAIN_BITS; // Set these bits as inputs BAT_CHARGE_DIR &= ~BAT_CHARGE_OPEN_DRAIN_BITS; // charge enable output BAT_CHARGE_DIR |= BAT_CHARGE_ENABLE_PIN; /* turn on the pullup in the MSP430 for the open drain bit of the charger * If the watch has 5V then we don't care about the current draw of the * of the pull down resistor. Otherwise, the charge chip will let * the pin go high */ BAT_CHARGE_OUT |= BAT_CHARGE_PWR_BIT; BATTERY_CHARGE_DISABLE(); InitAdc(); ChargeEnable = pdTRUE; ChargeStatus = CHARGE_STATUS_OFF; }
int16_t main(void) { // Initialize IO ports and peripherals. ConfigureOscillator(); InitApp(); InitAdc(); AtpInit(); odo_init(); // TODO motion_init(SendDone); SendBoardId(); __delay_ms(3000); SendBoardId(); while(1) { //SendBoardId(); if (odoBroadcast) { OnGetPos(); } __delay_ms(odoDelay); } }
void UserInit(void) { mInitAllLEDs(); mInitAllSwitches(); InitAdc(); old_sw2 = sw2; Pump1tris = 0; Pump2tris = 0; TRISVPP = 0; //output TRISVPP_RST=0; //output TRISPGD=0; TRISPGC=0; TRISVDD=0; TRISVPP_RUN=0; VPP_RUN=0; //run = off PGD_LOW=1; TRISPGD_LOW=1; //LV devices disabled, high impedance / input PGC_LOW=1; TRISPGC_LOW=1; //LV devices disabled, high impedance / input VPP = 1; //VPP is low (inverted) VPP_RST=0; //No hard reset (inverted PGD=0; PGC=0; INTCON2bits.RBPU=1; //disable Portb pullup resistors timer1Init(); timer0Init(); }//end UserInit
void bsp_init() { bsp_led_init(); bsp_pwm_config(); bsp_sw_init(); bsp_timer_config(); InitAdc(); }
void main(void) { InitSysCtrl(); // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: epwm1_timer_isr(), epwm2_timer_isr() // epwm3_timer_isr and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker. Refer to the F28335.cmd file. // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2833x_PieCtrl.c file. 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). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2833x_DefaultIsr.c. // This function is found in DSP2833x_PieVect.c. 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 registers PieVectTable.SEQ1INT = &PWM_AD_isr; PieVectTable.ECAN0INTA = &Skiip4_CAN_isr; EDIS; // This is needed to disable write to EALLOW protected registers InitFlash(); MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); MemCopy(&IQmathLoadStart, &IQmathLoadEnd, &IQmathRunStart); //ECan-A模块初始化 InitECan(); InitECan1(); InitGpio(); // Skipped for this example InitAdc(); // Initialize necessary ADC module, directly for SVPWM. InitEPwm(); IER |= M_INT1; // Enable SEQ1_INT which is connected to PIE1.1: IER |= M_INT9; // Enable eCAN0-A INT which is connected to PIE9.5: EINT; } // end of main()
void main(void) { //--- CPU Initialization InitSysCtrl(); // Initialize the CPU (FILE: SysCtrl.c) InitGpio(); // Initialize the shared GPIO pins (FILE: Gpio.c) InitPieCtrl(); // Initialize and enable the PIE (FILE: PieCtrl.c) InitWatchdog(); // Initialize the Watchdog Timer (FILE: WatchDog.c) //--- Peripheral Initialization InitAdc(); // Initialize the ADC (FILE: Adc.c) InitEPwm(); // Initialize the EPwm (FILE: EPwm.c) int d; for (d = 0; d < SIN_DEFINITION; d++) { sinValues[d] = (int)(fabs(sin(d * 180.f / SIN_DEFINITION * 2 * PI / 360)) * SIN_AMPLITUDE) + LOWER_HYSTERESIS_BAND; } // Variable Initialization asm (" ESTOP0"); // Emulator Halt instruction int i = 0; //--- Enable global interrupts // Enable global interrupts and realtime debug asm("DBGM"); asm(" CLRC INTM"); //--- Main Loop while(D) // endless loop - wait for an interrupt { i ++; if (i == 600) { EPwm1Regs.AQSFRC.bit.ACTSFA = 1; // What to do when One-Time Software Forced Event is invoked // 00 Does nothing (action disabled) // 01 Clear (low) // 10 Set (high) // 11 Toggle EPwm1Regs.AQSFRC.bit.OTSFA = 1; // Invoke One-Time Software Forced Event on Output A EPwm1Regs.AQSFRC.bit.ACTSFB = 2; // What to do when One-Time Software Forced Event is invoked // 00 Does nothing (action disabled) // 01 Clear (low) // 10 Set (high) // 11 Toggle EPwm1Regs.AQSFRC.bit.OTSFB = 1; // Invoke One-Time Software Forced Event on Output A i = 0; } } //--- Main Loop while(1) // endless loop - wait for an interrupt { asm(" NOP"); } } //end of main()
void CmdAdc(void) { static bool init = true; uart_cmd_t *cmdPtr = GetCmdPointer(); adc_info_t *adc = GetAdcPointer(); int8_t ch = -1; // Initialize device on first run if (init){ InitAdc(adc); UARTprintf(ADC_INIT_COMPLETE); init = false; } // Handle parameters if (cmdPtr->argsNum) { switch(*cmdPtr->currentArgs){ case 'h': CmdAdcHelp(); break; case 'a': ch = GetAdcValue(adc, cmdPtr); PrintSingleChannel(adc, ch); break; case 'd': GetAdcValues(); PrintAllChannels(); break; case 'c': ToggleTriggerEnable(adc, cmdPtr); break; case 't': SetTriggerValue(adc, cmdPtr); break; case 's': WaitForTrigger(adc, cmdPtr); break; case 'p': WriteToPool(); break; case 'i': PrintAdcInformation(adc, cmdPtr); break; } } else { UARTprintf(CMD_ZERO_ARGS); } }
static void InitDisplay(void) { __disable_interrupt(); ENABLE_LCD_LED(); DISABLE_LCD_POWER(); /* clear shipping mode, if set to allow configuration */ PMMCTL0_H = PMMPW_H; PM5CTL0 &= ~LOCKLPM5; PMMCTL0_H = 0x00; /* disable DMA during read-modify-write cycles */ DMACTL4 = DMARMWDIS; #if BOOTLOADER /* * enable RAM alternate interrupt vectors * these are defined in AltVect.s43 and copied to RAM by cstartup */ SYSCTL |= SYSRIVECT; ClearBootloaderSignature(); #endif SetupClockAndPowerManagementModule(); CheckClip(); // enable debuguart __enable_interrupt(); PrintF("\r\n*** %s:%c%c%c ***", (niResetType == NORMAL_RESET ? "NORMAL" : "MASTER"), BUILD[0], BUILD[1], BUILD[2]); if (niResetType != NORMAL_RESET) InitStateLog(); SaveStateLog(); WhoAmI(); ShowStateInfo(); InitAdc(); /* timer for battery checking at a regular frequency. */ StartTimer(BatteryTimer); InitVibration(); InitRealTimeClock(); // enable rtc interrupt LcdPeripheralInit(); DrawSplashScreen(); InitSerialRam(); /* turn the radio on; initialize the serial port profile or BLE/GATT */ SendMessage(TurnRadioOnMsg, MSG_OPT_NONE); DISABLE_LCD_LED(); }
void UserInit(void) { //mInitAllLEDs(); //mInitAllSwitches(); InitAdc(); //old_sw2 = sw2; //Pump1tris = 0; //Pump2tris = 0; //CS and AUX to output, ground (MCLR and VPP) BP_AUX=0; //PWM BP_AUX_DIR=0; BP_CS=0; //MCLR BP_CS_DIR=0; BP_LEDMODE_DIR=0; BP_MISO_DIR=0; //VPPEN BP_MISO=1; //PWM setup (leave off for now) //cleanup timers T2CON=0; // clear settings T4CON=0; OC5CON =0; T2CONbits.TCKPS1=1; T2CONbits.TCKPS0=0; //assign pin with PPS BP_AUX_RPOUT = OC5_IO; OC5R = PWM_D; OC5RS = PWM_D; OC5CON = 0x6; PR2 = PWM_P; TRISVPP = 0; //output TRISVPP_RST=0; //output TRISPGD=0; TRISPGC=0; //TRISVDD=0; //TRISVPP_RUN=0; // VPP_RUN=0; //run = off PGD_LOW=1; TRISPGD_LOW=1; //LV devices disabled, high impedance / input PGC_LOW=1; TRISPGC_LOW=1; //LV devices disabled, high impedance / input VPP = 1; //VPP is low (inverted) VPP_RST=0; //No hard reset (inverted PGD=0; PGC=0; //INTCON2bits.RBPU=1; //disable Portb pullup resistors //timer1Init(); //timer0Init(); }//end UserInit
void InitSystem(void) { InitLed(); InitUart(); BluetoothInit(); InitAdc(); InitSensor(); InitFan(); InitRtc(); InitSecondTimer(); }
void main(void) { InitSysCtrl(); InitSpiaGpio(); Gpio_select(); /* EALLOW; SysCtrlRegs.WDCR = 0x00AF; // re-enable the watchdog EDIS; */ DINT; IER = 0x0000; IFR = 0x0000; InitPieCtrl(); InitPieVectTable(); InitAdc(); spi_fifo_init(); Setup_ePWM(); // ePWM Setup_ADC(); // ADC setup EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.SPIRXINTA = &spiRxFifoIsr; PieVectTable.SPITXINTA = &spiTxFifoIsr; PieVectTable.SEQ1INT = &adc1_isr; PieVectTable.EPWM1_INT = &ePWM1A_compare_isr; EDIS; // This is needed to disable write to EALLOW protected registers PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block PieCtrlRegs.PIEIER6.bit.INTx1 = 1; // Enable PIE Group 6, INT 1 PieCtrlRegs.PIEIER6.bit.INTx2 = 1; // Enable PIE Group 6, INT 2 PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // adc1 (seq1 - pwm) PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // epwm1 IER |= 25; // Enable CPU INT6 EINT; // Enable Global Interrupts ERTM; while (1) { if (AdcRegs.ADCST.bit.INT_SEQ1 == 1) // ADC seq1 interrupt for pwm (at prd) { flag1 = 1; AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; } if (EPwm1Regs.ETFLG.bit.INT == 1) // epwm interrupt for pwm of second converter (at prd) { flag2 = 1; EPwm1Regs.ETCLR.bit.INT = 1; } } }
void main() { initVariables(); DINT; ms_delay(1); InitAdc(); SetupAdc(); InitSysCtrl(); InitPieCtrl(); IER = 0x0000; IFR = 0x0000; MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); InitPieVectTable(); easyDSP_SCI_Init(); InitEPwm3(); InitEPwm4(); pwm_setup(); initialize_mppt_timer(); EALLOW; PieVectTable.TINT2 = &mppt_int; PieVectTable.EPWM3_INT = &pwm_int; PieCtrlRegs.PIEIER3.bit.INTx3 = 0x1; EDIS; IER |= M_INT3; IER |= M_INT14; EINT; ms_delay(1); InitEPwm3Gpio(); //InitEPwm4Gpio(); // EALLOW; // GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // GpioCtrlRegs.GPADIR.bit.GPIO5 = 1; // GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; // GpioCtrlRegs.GPADIR.bit.GPIO7 = 1; // // GpioDataRegs.GPASET.bit.GPIO4 = 1; // GpioDataRegs.GPASET.bit.GPIO5 = 1; // GpioDataRegs.GPACLEAR.bit.GPIO6 = 1; // GpioDataRegs.GPACLEAR.bit.GPIO7 = 1; // EDIS; ERTM; for(;;) { //// Bus_Voltage_Q15 = ((long int) AdcResult.ADCRESULT1*VBUS_SCALE); if(delay_flag) { ms_delay(10000); delay_flag = 0; } } }
int main() { unsigned char Lcd_LINE1[6] = {'\0'}; unsigned char Lcd_LINE2[16] = {'\0'}; unsigned int i; InitCan(); InitQEI(); InitPwm(); // InitInt(); InitAdc(); // InitUart(); //pid unsigned int *pwmOUT; pid_t mypid; float degPOT = 0.0; float degMTR = 0.0; while (1) { if(InData0[1] > 0){ // if(InData0[2] == 1){ // PDC2 = (unsigned int)(InData0[1]* 2 *.5914); // PDC1 = 0; // } // else{ // PDC1 = (unsigned int)(InData0[1]* 2* .5914); // PDC2 = 0; // } pwmOUT = CalcPid(&mypid, degPOT, degMTR); PDC1 = *(pwmOUT + 0); // 16-bit register PDC2 = *(pwmOUT + 1); // 16-bit register } if (InData0[3] == 1) { C1TX0B4 = 2; C1TX0B1 = POSCNT; C1TX0B2 = C1RX0B2; C1TX0B3 = C1RX0B3; C1TX0CONbits.TXREQ = 1; while (C1TX0CONbits.TXREQ != 0); } msDelay(10); } //while } // main
int Sensor_Temperature_Init() { InitAdc(); EALLOW; AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1; //Enable non-overlap mode AdcRegs.ADCCTL1.bit.TEMPCONV = 1; //Connect channel A5 internally to the temperature sensor AdcRegs.ADCSOC0CTL.bit.CHSEL = 5; //Set SOC0 channel select to ADCINA5 AdcRegs.ADCSOC0CTL.bit.ACQPS = 63; //Set SOC0 acquisition period to 26 ADCCLK AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //enable ADC-interrupts PieVectTable.ADCINT1 = &Sensor_Temperature_ISR; // Enable ADCINT1 in PIE IER |= M_INT1; // Enable CPU Interrupt 1 EDIS; }
int main() { unsigned char Lcd_LINE1[6] = {'\0'}; unsigned char Lcd_LINE2[16] = {'\0'}; unsigned int i; InitCan(); InitQEI(); InitPwm(); // InitInt(); InitAdc(); // InitUart(); while (1) { if(InData0[1] > 0){ if(InData0[2] == 1){ PDC2 = (unsigned int)(InData0[1]* 2 *.5914); PDC1 = 0; } else{ PDC1 = (unsigned int)(InData0[1]* 2* .5914); PDC2 = 0; } } if (InData0[3] == 1) { C1TX0B4 = 2; C1TX0B1 = POSCNT; C1TX0B2 = C1RX0B2; C1TX0B3 = C1RX0B3; C1TX0CONbits.TXREQ = 1; while (C1TX0CONbits.TXREQ != 0); } msDelay(10); } //while } // main
main() { int16 i; int16 j; int16 test[100]; //一、 system initialize: pll clock:150M;hispcp=1 100m/2; lospcp=2 100m/4;eWM,ADC,cpu Timer clock enabled InitSysCtrl(); //修改了默认时钟到150MHz,关闭了无关外设时钟 // DELAY_US(1000000); //二、initialize GPIO:set the GPIO to it's default state: 普通GPIO状态,均为输入,输入采样方式为第一种,均为上拉使能. //epwm disable pull up InitGpio(); //全部引脚初始化 //用户自定义IO初始化(主要包括:逻辑输入输出引脚) InitLogicIO(); //串口初始化 InitScicGpio(); InitSci(); //初始化触摸屏变量 initvar(); // MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); //EPwm初始化 // InitEPwmGpio(); //PWM IO初始化 //InitEPwm1Gpio(); //InitEPwm2Gpio(); //所有PWM模块都需要开启 //InitEPwm3Gpio(); //InitEPwm4Gpio(); //InitEPwm5Gpio(); //InitEPwm6Gpio(); //三、initialize interrupts:disable cpu interrupt; disabel all pie interrupts and clear all pie interrupt flags DINT; InitPieCtrl(); IER=0x0000; IFR=0x0000; //initialize Pie interrupts and enable pie InitPieVectTable(); //用户自定义的中断初始化 EALLOW; PieVectTable.TINT0 = &cpu_timer0_isr; //Cpu timer0 interrupt PieVectTable.XINT1 = &xint1_isr; EDIS; //四、initialize peripherials and setup peripherials InitFlash(); InitXintf(); //ADC initialize InitAdc(); //ADC setup SetupAdc(); // Adc_Inquire(); //Epwm Setup // SetupEPwm(); //pwm开始产生 //CPU timer0 initialize InitCpuTimers(); // Configure CPU-Timer 0 to interrupt every msecond: // 150MHz CPU Freq, 3m second Period (in uSeconds) ConfigCpuTimer(&CpuTimer0, 150, 3000); StartCpuTimer0(); //五、User specific code, enable interrupts: //在开始中断之前先进行测试循环。此时进行单步运行 //1. I/O test //测试程序,GPIOA的低18位为通用I/O输入 //测试程序,GPIOA的24,25,26,27为通用I/O输入,GPIOB的48-61为通用I/O输入 //由于I/o口均有上拉,所以只要测试输入0时是否正确即可。这样最大限度保护芯片。 for(i=0;i<100;i++) { j=i; } // EALLOW; // GpioCtrlRegs.GPADIR.all = 0x0003FFFF; // GPIO functionality GPIO0-GPIO15 // EDIS; // GpioDataRegs.GPACLEAR.all = 0x0003FFFF; // GpioDataRegs.GPASET.all = 0x0001AAAA; // GpioDataRegs.GPATOGGLE.all = 0x0003FFFF; //2. Communication Test: //具体通讯是否成功还需要更多程序 //测试RS485通讯芯片 GpioDataRegs.GPASET.bit.GPIO21=1; GpioDataRegs.GPATOGGLE.bit.GPIO22=1; //测试CAN通讯芯片 GpioDataRegs.GPATOGGLE.bit.GPIO19=1; for(i=0;i<100;i++) { j=i; } //测试RS485通讯芯片 GpioDataRegs.GPASET.bit.GPIO21=1; GpioDataRegs.GPATOGGLE.bit.GPIO22=1; //测试CAN通讯芯片 GpioDataRegs.GPATOGGLE.bit.GPIO19=1; for(i=0;i<100;i++) { j=i; } // 3. A/D Test //软件启动adc转换 for(i=0;i<100;i++) { AdcRegs.ADCTRL2.bit.SOC_SEQ1=1; Adc_Inquire(); } // 4. PWM Test //每次测一个单相,这样子发现错误及时下电 for(i=0;i<100;i++) { j=i; } *FPGA_PWMA_Wait1=1000; *FPGA_PWMA_Duty1=1000; *FPGA_PWMA_Wait2=2000; *FPGA_PWMA_Duty2=2000; *FPGA_PWMA_Wait3=3000; *FPGA_PWMA_Duty3=3000; *FPGA_PWMA_Wait4=4000; *FPGA_PWMA_Duty4=4000; *FPGA_PWMA_Wait5=5000; *FPGA_PWMA_Duty5=5000; *FPGA_PWMA_Wait6=6000; *FPGA_PWMA_Duty6=6000; *FPGA_PWMA_Wait7=1000; *FPGA_PWMA_Duty7=1000; *FPGA_PWMA_Wait8=2000; *FPGA_PWMA_Duty8=2000; *FPGA_PWMA_Wait9=3000; *FPGA_PWMA_Duty9=3000; *FPGA_PWMA_Wait10=4000; *FPGA_PWMA_Duty10=4000; *FPGA_PWMA_Wait11=5000; *FPGA_PWMA_Duty11=5000; *FPGA_PWMA_Wait12=6000; *FPGA_PWMA_Duty12=6000; for(i=0;i<100;i++) { j=i; } *FPGA_PWMB_Wait1=1000; *FPGA_PWMB_Duty1=1000; *FPGA_PWMB_Wait2=2000; *FPGA_PWMB_Duty2=2000; *FPGA_PWMB_Wait3=3000; *FPGA_PWMB_Duty3=3000; *FPGA_PWMB_Wait4=4000; *FPGA_PWMB_Duty4=4000; *FPGA_PWMB_Wait5=5000; *FPGA_PWMB_Duty5=5000; *FPGA_PWMB_Wait6=6000; *FPGA_PWMB_Duty6=6000; *FPGA_PWMB_Wait7=1000; *FPGA_PWMB_Duty7=1000; *FPGA_PWMB_Wait8=2000; *FPGA_PWMB_Duty8=2000; *FPGA_PWMB_Wait9=3000; *FPGA_PWMB_Duty9=3000; *FPGA_PWMB_Wait10=4000; *FPGA_PWMB_Duty10=4000; *FPGA_PWMB_Wait11=5000; *FPGA_PWMB_Duty11=5000; *FPGA_PWMB_Wait12=6000; *FPGA_PWMB_Duty12=6000; for(i=0;i<100;i++) { j=i; } *FPGA_PWMC_Wait1=1000; *FPGA_PWMC_Duty1=1000; *FPGA_PWMC_Wait2=2000; *FPGA_PWMC_Duty2=2000; *FPGA_PWMC_Wait3=3000; *FPGA_PWMC_Duty3=3000; *FPGA_PWMC_Wait4=4000; *FPGA_PWMC_Duty4=4000; *FPGA_PWMC_Wait5=5000; *FPGA_PWMC_Duty5=5000; *FPGA_PWMC_Wait6=6000; *FPGA_PWMC_Duty6=6000; *FPGA_PWMC_Wait7=1000; *FPGA_PWMC_Duty7=1000; *FPGA_PWMC_Wait8=2000; *FPGA_PWMC_Duty8=2000; *FPGA_PWMC_Wait9=3000; *FPGA_PWMC_Duty9=3000; *FPGA_PWMC_Wait10=4000; *FPGA_PWMC_Duty10=4000; *FPGA_PWMC_Wait11=5000; *FPGA_PWMC_Duty11=5000; *FPGA_PWMC_Wait12=6000; *FPGA_PWMC_Duty12=6000; for(i=0;i<100;i++) { j=i; } *FPGA_PWMD_Wait1=1000; *FPGA_PWMD_Duty1=1000; *FPGA_PWMD_Wait2=2000; *FPGA_PWMD_Duty2=2000; *FPGA_PWMD_Wait3=3000; *FPGA_PWMD_Duty3=3000; *FPGA_PWMD_Wait4=4000; *FPGA_PWMD_Duty4=4000; *FPGA_PWMD_Wait5=5000; *FPGA_PWMD_Duty5=5000; *FPGA_PWMD_Wait6=6000; *FPGA_PWMD_Duty6=6000; *FPGA_PWMD_Wait7=1000; *FPGA_PWMD_Duty7=1000; *FPGA_PWMD_Wait8=2000; *FPGA_PWMD_Duty8=2000; *FPGA_PWMD_Wait9=3000; *FPGA_PWMD_Duty9=3000; *FPGA_PWMD_Wait10=4000; *FPGA_PWMD_Duty10=4000; *FPGA_PWMD_Wait11=5000; *FPGA_PWMD_Duty11=5000; *FPGA_PWMD_Wait12=6000; *FPGA_PWMD_Duty12=6000; for(i=0;i<100;i++) { j=i; } *FPGA_PWME_Wait1=1000; *FPGA_PWME_Duty1=1000; *FPGA_PWME_Wait2=2000; *FPGA_PWME_Duty2=2000; *FPGA_PWME_Wait3=3000; *FPGA_PWME_Duty3=3000; *FPGA_PWME_Wait4=4000; *FPGA_PWME_Duty4=4000; *FPGA_PWME_Wait5=5000; *FPGA_PWME_Duty5=5000; *FPGA_PWME_Wait6=6000; *FPGA_PWME_Duty6=6000; *FPGA_PWME_Wait7=1000; *FPGA_PWME_Duty7=1000; *FPGA_PWME_Wait8=2000; *FPGA_PWME_Duty8=2000; *FPGA_PWME_Wait9=3000; *FPGA_PWME_Duty9=3000; *FPGA_PWME_Wait10=4000; *FPGA_PWME_Duty10=4000; *FPGA_PWME_Wait11=5000; *FPGA_PWME_Duty11=5000; *FPGA_PWME_Wait12=6000; *FPGA_PWME_Duty12=6000; //PWM复位功能演示,复位以后,所有PWM为零。 GpioDataRegs.GPACLEAR.bit.GPIO31=1; DELAY_US(1); GpioDataRegs.GPASET.bit.GPIO31=1; // 5. D/A Test *DAC1=1024; *DAC2=2048; *DAC3=3072; *DAC4=4095; // 6.测试FPGA的I/O // 首先测试是否结果为1 for(j=0;j<10;j++) { for(i=0; i<24; i++) test[i]=*(FPGA_IO1_DATA+i); i=0; } //再测试是否结果为0 for(j=0;j<100;j++) { for(i=0; i<24; i++) test[i]=*(FPGA_IO1_DATA+i); i=0; } //输出功能演示,只有输出使能的IO pin才能输出0 *FPGA_IODIR_LOW=0xFFFF; *FPGA_IODIR_HIGH=0x00FF; j=0; for(i=0; i<24; i++) { *(FPGA_IO1_DATA+i)=j; j=~j; } j=0; for(i=0; i<24; i++) { j=~j; *(FPGA_IO1_DATA+i)=j; } //复位功能演示,复位以后,所有IO上拉。且输出不使能 GpioDataRegs.GPACLEAR.bit.GPIO30=1; DELAY_US(1); GpioDataRegs.GPASET.bit.GPIO30=1; j=*FPGA_IODIR_LOW; j=*FPGA_IODIR_HIGH; j=0; for(i=0; i<24; i++) *(FPGA_IO1_DATA+i)=j; //开用到的中断,最后开中断。测试SCI 通讯以及DSP 和FPGA的通讯 EnableInterrupts(); //cpu timer0 中断 i=0; // 六. 主循环IDLE loop. Just sit and loop forever (optional): for(;;) { // ScicRegs.SCITXBUF=i; DELAY_US(1000); /* if(GpioDataRegs.GPADAT.bit.GPIO27==0) GpioDataRegs.GPBCLEAR.bit.GPIO50=1; else GpioDataRegs.GPBSET.bit.GPIO50=1; if(GpioDataRegs.GPBDAT.bit.GPIO48==0) GpioDataRegs.GPBCLEAR.bit.GPIO51=1; else GpioDataRegs.GPBSET.bit.GPIO51=1; // ModebusRegsDataBuff[0]=i; // GpioDataRegs.GPBTOGGLE.bit.GPIO60=1; // GpioDataRegs.GPBTOGGLE.bit.GPIO61=1; // GpioDataRegs.GPBTOGGLE.bit.GPIO58=1; // GpioDataRegs.GPBTOGGLE.bit.GPIO59=1; GpioDataRegs.GPBCLEAR.bit.GPIO53= 1; GpioDataRegs.GPBCLEAR.bit.GPIO52= 1; i++; // if(i==2000) if(i==FPGA_DATA_Test_length) i=0; // TestState=~TestState; */ slavecomm(); } }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int main(void) { MamInit(); // Init clock InitClock(); // Init GPIO GpioInit(); // Init VIC init_VIC(); // Enable TIM0 clocks PCONP_bit.PCTIM0 = 1; // enable clock PCLKSEL0_bit.PCLK_TIMER0 = 1; //timer clock = pclk // Init Time0 T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 18-1; T0MR0 = (TIMER0_IN_FREQ)/(18 * TIMER0_TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable __enable_interrupt(); LcdInitPio(); BoardInit(); SysSpiInitPio(); DacInitPio(); AdcInitPio(); InitAdc(); LcdInitModule(); LcdClear(); // LcdLine(10,32,130, 32); // LcdLine(60,10,60, 60); // LcdLine(70,10,70, 60); // LcdRect(10,20,40, 50); // LcdRect(10,1,80, 7); /* SetFont(BIG_FONT); LcdLine(10, 28, 120, 28); LcdLine(10, 45, 120, 45); // LcdRect(10, 30, 50, 43); LcdText(50, 20, 200, 36, "-123456789.0"); */ /* LcdBmp(10, 20, BMP_HN_WIDTH, BMP_HN_HEIGHT, bmp_hn); LcdBmp(10, 35, BMP_O2_WIDTH, BMP_O2_HEIGHT, bmp_o2); DrawCheckBox(8, 8, 0, 1); DrawCheckBox(20, 8, 1, 1);*/ // DrawMainScreen(); DrawParamScreen(); LcdClear(); //DrawMenuScreen(); DrawDOutTestScreen(); LcdDraw(); OutputSet(LCD_LED); InitMessages(); InitKeyb(); InitCursor(); InitAdc(); // SetCursorPos(100, 32); SendMessage(MSG_EDITOR_SCREEN_ACTIVATE); int debug = 0, debug2 = 0; char s[4]; /* LcdClear(); for(char i = 0; i < 16; i++) LcdLine(i * 8, 0, i * 8, 63); LcdDraw(); */ // debug = ReadTemp() / 32; debug = 3855.0 + 20.0 * ((402.0 - 3855.0) / 20.0); unsigned int dac_codes[4] = {0, 0, 0, 0}; dac_codes[0] = debug; // unsigned int dac_codes[4] = {0, 0, 0, 4095}; WriteToDac(dac_codes); // char adc_codes[4] = {0x58, 0, 0, 0}; // char adc_codes2[4] = {0, 0, 0, 0,}; char state = 0; while(1) { /* WriteIntToFram(0, 100); ReadIntFromFram(0, &debug); */ /* WriteToDac(dac_codes); */ /* switch(state) { case 0: //if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_R_ENCODER_PRESSED)) { OutputSet(LED11); OutputClr(LED12); OutputClr(LED13); OutputSet(LED15); ResetTimer(KEYB_TIMER); SendMessage(MSG_CUR_DEACTIVATE); state = 1; }; break; case 1: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_R_ENCODER_PRESSED)) { OutputClr(LED11); OutputSet(LED12); OutputClr(LED13); OutputClr(LED15); ResetTimer(KEYB_TIMER); SendMessage(MSG_CUR_ACTIVATE); state = 0; }; break; case 2: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_KEY_PRESSED)) { OutputClr(LED11); OutputClr(LED12); OutputSet(LED13); OutputClr(LED15); ResetTimer(KEYB_TIMER); state = 3; }; break; case 3: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_KEY_PRESSED)) { OutputClr(LED11); OutputClr(LED12); OutputClr(LED13); OutputSet(LED15); ResetTimer(KEYB_TIMER); state = 0; }; break; }; if (GetMessage(MSG_L_ENCODER_CW)) { debug++; sprintf(s, "%d", debug); // LcdClear(); LcdText(0, 0, 63, 9, s); LcdDraw(); }; if (GetMessage(MSG_L_ENCODER_CCW)) { debug--; sprintf(s, "%d", debug); // LcdClear(); LcdText(0, 0, 63, 9, s); LcdDraw(); }; if (GetMessage(MSG_R_ENCODER_CW)) { debug2++; sprintf(s, "%d", debug2); // LcdClear(); LcdText(100, 0, 127, 9, s); LcdDraw(); }; if (GetMessage(MSG_R_ENCODER_CCW)) { debug2--; sprintf(s, "%d", debug2); // LcdClear(); LcdText(100, 0, 127, 9, s); LcdDraw(); }; */ // ProcessEditorScreen(); // ProcessEditor(); ProcessAdc(); ProcessCursor(); ProcessKeyb(); ProcessMessages(); } }
/********************************************************************** * Function: main() * * Description: Main function for C2833x Real-time RFFT **********************************************************************/ void main(void) { Uint16 i,j; float32 freq; // Frequency of single-frequency-component signal //--- CPU Initialization InitSysCtrl(); // Initialize the CPU (FILE: SysCtrl.c) InitGpio(); // Initialize the shared GPIO pins (FILE: Gpio.c) InitPieCtrl(); // Initialize and enable the PIE (FILE: PieCtrl.c) //--- Peripheral Initialization InitAdc(); // Initialize the ADC (FILE: Adc.c) // 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 rfft_adc.Tail = &rfft.OutBuf; //Link the RFFT_ADC_F32_STRUCT to //RFFT_F32_STRUCT. Tail pointer of //RFFT_ADC_F32_STRUCT is passed to //the OutBuf pointer of RFFT_F32_STRUCT rfft.FFTSize = RFFT_SIZE; //Real FFT size rfft.FFTStages = RFFT_STAGES; //Real FFT stages rfft_adc.InBuf = &AdcBuf[0]; //Input buffer rfft.OutBuf = &RFFToutBuff[0]; //Output buffer rfft.CosSinBuf = &RFFTF32Coef[0]; //Twiddle factor rfft.MagBuf = &RFFTmagBuff[0]; //Magnitude output buffer RFFT_f32_sincostable(&rfft); //Calculate twiddle factor //Clean up output buffer for (i=0; i < RFFT_SIZE; i++) { RFFToutBuff[i] = 0; } //Clean up magnitude buffer for (i=0; i < RFFT_SIZE/2; i++) { RFFTmagBuff[i] = 0; } //--- Enable global interrupts asm(" CLRC INTM, DBGM"); // Enable global interrupts and realtime debug //--- Main Loop while(1) // endless loop - wait for an interrupt { if(FFTStartFlag) // If one frame data ready, then do FFT { RFFT_adc_f32u(&rfft_adc); // This version of FFT doesn't need buffer alignment RFFT_f32_mag(&rfft); // Calculate spectrum amplitude j = 1; freq = RFFTmagBuff[1]; for(i=2;i<RFFT_SIZE/2+1;i++) { //Looking for the maximum valude of spectrum magnitude if(RFFTmagBuff[i] > freq) { j = i; freq = RFFTmagBuff[i]; } } freq = F_PER_SAMPLE * (float)j; //Convert normalized digital frequency to analog frequency FFTStartFlag = 0; //Start collecting the next frame of data } asm(" NOP"); } } //end of main()
void adcinit() { InitAdc(); // Init the ADC EALLOW; // Comment out other unwanted lines. GpioCtrlRegs.AIODIR.all = 0x0000; GpioCtrlRegs.AIOMUX1.bit.AIO2 = 2; // Configure AIO2 for A2 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2; // Configure AIO4 for A4 (analog input) operation //GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2; // Configure AIO6 for A6 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO10 = 2; // Configure AIO10 for B2 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO12 = 2; // Configure AIO12 for B4 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO14 = 2; // Configure AIO14 for B6 (analog input) operation //solve first conversion problem: AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1; AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1; AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; // SOC0 TO A0 AdcRegs.ADCSOC1CTL.bit.CHSEL = 1; // SOC1 TO A1 AdcRegs.ADCSOC2CTL.bit.CHSEL = 2; // SOC2 TO A2 AdcRegs.ADCSOC3CTL.bit.CHSEL = 3; // SOC3 TO A3 AdcRegs.ADCSOC4CTL.bit.CHSEL = 4; // SOC4 TO A4 AdcRegs.ADCSOC5CTL.bit.CHSEL = 5; // SOC5 TO A5 AdcRegs.ADCSOC6CTL.bit.CHSEL = 6; // SOC6 TO A6 AdcRegs.ADCSOC7CTL.bit.CHSEL = 7; // SOC7 TO A7 AdcRegs.ADCSOC8CTL.bit.CHSEL = 8; // SOC8 TO B0 AdcRegs.ADCSOC9CTL.bit.CHSEL = 9; // SOC9 TO B1 AdcRegs.ADCSOC10CTL.bit.CHSEL = 10; // SOC10 TO B2 AdcRegs.ADCSOC11CTL.bit.CHSEL = 11; // SOC11 TO B3 AdcRegs.ADCSOC12CTL.bit.CHSEL = 12; // SOC12 TO B4 AdcRegs.ADCSOC13CTL.bit.CHSEL = 13; // SOC13 TO B5 AdcRegs.ADCSOC14CTL.bit.CHSEL = 14; // SOC14 TO B6 AdcRegs.ADCSOC15CTL.bit.CHSEL = 15; // SOC15 TO B7 AdcRegs.ADCSOC0CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC0 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC1CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC1 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC2CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC2 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC3CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC3 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC4CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC4 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC5CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC5 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC6CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC6 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC7CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC7 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC8CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC8 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC9CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC9 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC10CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC10 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC11CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC11 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC12CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC12 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC13CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC13 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC14CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC14 acquisition period to DEFINED PERIOD AdcRegs.ADCSOC15CTL.bit.ACQPS = ACQPS_VALUE; //Set SOC15 acquisition period to DEFINED PERIOD AdcRegs.INTSEL1N2.bit.INT1SEL = 15; //Connect ADCINT1 to SOC15 (last conversion) AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enable ADCINT1 EDIS; }
main() { // Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2806x_SysCtrl.c file. InitSysCtrl(); // Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the F2806x_PieCtrl.c file. 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). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2806x_DefaultIsr.c. // This function is found in F2806x_PieVect.c. 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.ADCINT1 = &adc_isr; EDIS; // This is needed to disable write to EALLOW protected registers // Initialize all the Device Peripherals: // This function is found in F2806x_InitPeripherals.c // InitPeripherals(); // Not required for this example InitAdc(); // For this example, init the ADC AdcOffsetSelfCal(); // User specific code, enable interrupts: // Enable ADCINT1 in PIE PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE IER |= M_INT1; // Enable CPU Interrupt 1 EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM LoopCount = 0; ConversionCount = 0; // Configure ADC EALLOW; AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1; // Enable non-overlap mode AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; // ADCINT1 trips after AdcResults latch AdcRegs.INTSEL1N2.bit.INT1E = 1; // Enabled ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; // Disable ADCINT1 Continuous mode AdcRegs.INTSEL1N2.bit.INT1SEL = 1; // setup EOC1 to trigger ADCINT1 to fire AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; // set SOC0 channel select to ADCINA4 AdcRegs.ADCSOC1CTL.bit.CHSEL = 2; // set SOC1 channel select to ADCINA2 AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5; // set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; // set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; // set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) EDIS; // Assumes ePWM1 clock is already enabled in InitSysCtrl(); EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1 EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start // Wait for ADC interrupt for(;;) { LoopCount++; } }
void main(void) { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2806x_SysCtrl.c file. char * rto1 = (char *)0x8000; for (rn1 = 0; rn1 < nn1; rn1++) *rto1++ = rfrom1; memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize); InitSysCtrl(); // Step 2. Initalize GPIO: // This example function is found in the F2806x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the F2806x_PieCtrl.c file. 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). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2806x_DefaultIsr.c. // This function is found in F2806x_PieVect.c. 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 registers PieVectTable.EPWM5_INT = &epwm5_timer_isr; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in F2806x_InitPeripherals.c // InitPeripherals(); // Not required for this example InitAdc(); // For this example, init the ADC //InitAdcAio(); // Function that sets analog input pins ConfigADC(); //AdcOffsetSelfCal(); InitEPwm(); // Function initializes ePWM 1 - 5 // Step 5. User specific code, enable interrupts: // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: epwm1_timer_isr(), epwm2_timer_isr() // epwm3_timer_isr and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart // symbols are created by the linker. Refer to the F2808.cmd file. // Call Flash Initialization to setup flash waitstates // This function must reside in RAM InitFlash(); IER |= M_INT3; // Enable CPU INT3 which is connected to EPWM1-8 INT: page 175 in documentation IER |= M_INT10; // Enable CPU Interrupt 10 // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3 PieCtrlRegs.PIEIER3.bit.INTx5 = PWM5_INT_ENABLE; // Enable ADCINT1 in PIE /*PieCtrlRegs.PIEIER10.bit.INTx1 = 1; // Enable INT 10.1 in the PIE PieCtrlRegs.PIEIER10.bit.INTx2 = 1; // Enable INT 10.2 in the PIE PieCtrlRegs.PIEIER10.bit.INTx3 = 1; // Enable INT 10.3 in the PIE PieCtrlRegs.PIEIER10.bit.INTx4 = 1; // Enable INT 10.4 in the PIE PieCtrlRegs.PIEIER10.bit.INTx5 = 1; // Enable INT 10.5 in the PIE PieCtrlRegs.PIEIER10.bit.INTx6 = 1; // Enable INT 10.6 in the PIE PieCtrlRegs.PIEIER10.bit.INTx7 = 1; // Enable INT 10.7 in the PIE PieCtrlRegs.PIEIER10.bit.INTx8 = 1; // Enable INT 10.8 in the PIE*/ // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // Step 6. IDLE loop. Just sit and loop forever (optional): EALLOW; GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 0; GpioCtrlRegs.GPBDIR.bit.GPIO54 = 1; GpioDataRegs.GPBCLEAR.bit.GPIO54 = 1; EDIS; for(;;) { // This loop will be interrupted, so the overall // delay between pin toggles will be longer. DELAY_US(DELAY); LoopCount++; //GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; } }
void main(void) { memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks InitSysCtrl(); SysCtrlRegs.PCLKCR1.bit.EQEP2ENCLK = 0; // eQEP2 SysCtrlRegs.PCLKCR0.bit.SPIBENCLK = 0; // SPI-B InitFlash(); // Step 2. Initalize GPIO: // InitGpio(); // Skipped; not needed InitEQep1Gpio(); //InitEPwm1Gpio(); //InitEPwm2Gpio(); //InitEPwm3Gpio(); InitECap1Gpio(); InitECap2Gpio(); InitECap3Gpio(); EALLOW; GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 0; GpioCtrlRegs.GPBMUX2.bit.GPIO51 = 0; GpioCtrlRegs.GPBDIR.bit.GPIO50 = 1; setupDrv8301(); setupSpiA(); //DRV8301_setupSpi(); EDIS; DINT; InitPieCtrl(); // The default state is all PIE interrupts disabled and flags are cleared. // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell ISRs. // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2806x_DefaultIsr.c. InitPieVectTable(); // Interrupts that are used in this example are re-mapped to our ISR functions EALLOW; PieVectTable.ECAP1_INT = &ecap1_isr; // Group 4 PIE Peripheral Vectors PieVectTable.ECAP2_INT = &ecap2_isr; // '' PieVectTable.ECAP3_INT = &ecap3_isr; // '' PieVectTable.ADCINT1 = &adc_isr; // //PieVectTable.SCIRXINTA = &scia_isr; EDIS; // Step 4. Initialize all the Device Peripherals: InitECapRegs(); scia_init(); epwmInit(1,2,0); //10kHz, 50% duty, no chop InitAdc(); AdcOffsetSelfCal(); // Step 5. Enable interrupts: IER |= M_INT1; // Enable CPU Interrupt 1 (connected to ADC) IER |= M_INT4; // Enable CPU INT4 which is connected to ECAP1-4 INT IER |= M_INT3; // Enable CPU INT1 which is connected to CPU-Timer 0: PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // INT1.1 for ADC PieCtrlRegs.PIEIER4.bit.INTx1 = 1; // INT4.1 for ecap1 PieCtrlRegs.PIEIER4.bit.INTx2 = 1; // INT4.2 for ecap2 PieCtrlRegs.PIEIER4.bit.INTx3 = 1; // INT4.3 for ecap3 // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM qep_data.init(&qep_data); int printData = 10001; readHallStateFlag = 1; char writeBuffer[80] = {0}; int lastPhase = 0; gogo = 1; DRV8301_enable(); DRV8301_setupSpi(); i = 0; while(1) { qep_data.calc(&qep_data); if (readHallStateFlag) updateHallState(); if ((lastPhase != Phase) && (printData)) { //\033[2J\033[0;0H\r sprintf(writeBuffer, "Hall State: %d\n\r", (int)Phase); scia_msg(writeBuffer); sprintf(writeBuffer, "Velocity: %d rpm\n\r", qep_data.SpeedRpm_fr); scia_msg(writeBuffer); //sprintf(writeBuffer, "Mechanical Angle: %f degrees\n\r", qep_data.theta_mech*360); //scia_msg(writeBuffer); //sprintf(writeBuffer, "Electrical Angle: %f\n\r", qep_data.theta_elec); //scia_msg(writeBuffer); lastPhase = Phase; } //DRV8301_readData(); //if (!Phase /*|| drv8301.fault || drv8301.OverTempShutdown || drv8301.OverTempWarning*/) { //while (!Phase || drv8301.fault || drv8301.OverTempShutdown || drv8301.OverTempWarning){ //GpioDataRegs.GPBCLEAR.bit.GPIO50 = 1; ///DELAY_US(32000); //DELAY_US(32000); //sprintf(writeBuffer, "\aERROR DECTECTED: \n\r Hall State: %d %d %d\n\r", CoilA, CoilB, CoilC); //scia_msg(writeBuffer); //sprintf(writeBuffer, "Fault Bit: %d\n\rOverTempShutdown: %d\n\rOverTempWarning%d\n\r", drv8301.fault, drv8301.OverTempShutdown, drv8301.OverTempWarning); //scia_msg(writeBuffer); //} //} //else { //GpioDataRegs.GPBSET.bit.GPIO50 = 1; //} } }
main() { InitSysCtrl(); // 初始化system DINT; // 初始化PIE InitPieCtrl(); // 初始化ADC InitPieVectTable(); MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); InitFlash(); //AdcOffsetSelfCal(); InitAdc(); IER = 0x0000; IFR = 0x0000; // 初始化中斷向量表 InitEPwm1Gpio(); GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // GPIO0 = PWM1A GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //GPIO0 = output EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; InitEPwm1Example(); InitCpuTimers(); ConfigCpuTimer(&CpuTimer0, 1, 3906); //必須先配置 再致能 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CpuTimer0Regs.TCR.all = 0x4000; // 致能CPUTIMER0 EDIS; // 設定中斷向量表位置 EALLOW; PieVectTable.XINT1 = &xint1_isr; PieVectTable.XINT2 = &xint2_isr; PieVectTable.ADCINT1 = &adc_isr; PieVectTable.TINT0 = &cputimer_isr; EDIS; // 設置外部中斷腳位及燈號腳位 EALLOW; GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO ADC開關 GpioCtrlRegs.GPADIR.bit.GPIO1 = 0; // input GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 0; // XINT1 Synch to SYSCLKOUT only GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 1; // XINT1 is GPIO1 GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0; // GPIO GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; // OUTput GpioDataRegs.GPACLEAR.bit.GPIO2 = 1; // 當ADC ON/OFF 標示燈 GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0; // GPIO ePWM開關 GpioCtrlRegs.GPADIR.bit.GPIO3 = 0; GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 0; // XINT2 Synch to SYSCLKOUT only GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 3; // XINT2 is GPIO3 GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0; // GPIO GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // OUTput GpioDataRegs.GPACLEAR.bit.GPIO4 = 1; // 當 ePWM ON/OFF 標示燈 GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; // GPIO GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; // OUTput 閃爍用 GpioDataRegs.GPACLEAR.bit.GPIO6 = 1; EDIS; IER |= M_INT1; // 開啟GROUP1中斷 EINT; ERTM; EALLOW; PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // 致能PIE(非必要) PieCtrlRegs.PIEIER1.bit.INTx1 = 0; PieCtrlRegs.PIEIER1.bit.INTx4 = 1; PieCtrlRegs.PIEIER1.bit.INTx5 = 1; //PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // !!!!!!!! 不能同時開啟 , 否則打架 !!!!!!!!! XIntruptRegs.XINT1CR.bit.POLARITY = 3; // interrupt occur on both falling and rising edge XIntruptRegs.XINT1CR.bit.ENABLE = 1; // Enable Xint1 XIntruptRegs.XINT2CR.bit.POLARITY = 3; // interrupt occur on both falling and rising edge XIntruptRegs.XINT2CR.bit.ENABLE = 1; // Enable Xint2 EDIS; LoopCount = 0; ConversionCount = 0; // Configure ADC // Note: Channel ADCINA4 will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata EALLOW; AdcRegs.ADCCTL1.bit.ADCENABLE = 0; // 不致能ADC (在initadc中已經致能) AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch AdcRegs.INTSEL1N2.bit.INT1E = 0; //disabled ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire AdcRegs.ADCSOC0CTL.bit.CHSEL = 1; //set SOC0 channel select to ADCINA1 AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 1; //set SOC0 start trigger on CPUtimer AdcRegs.ADCSOC0CTL.bit.ACQPS = 6;//set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) //AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; EDIS; //GpioCtrlRegs.AIOMUX1.bit. &= ~(0x08); // ADCINA1 // EALLOW; SysCtrlRegs.XCLK.bit.XCLKOUTDIV = 2; EDIS; for (;;) { //volatile long double n; //for (n = 0; n < 5000; n++) // ; //EALLOW; //GpioDataRegs.GPATOGGLE.bit.GPIO6 = 1; //EDIS; if (GpioDataRegs.GPADAT.bit.GPIO1 == 1) { Voltage1[array] = AdcResult.ADCRESULT0; if (Voltage1[array] > 5000) { EALLOW; SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 0; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; SysCtrlRegs.LPMCR0.bit.LPM = 3; // 全部休眠 EDIS; EALLOW; SysCtrlRegs.CLKCTL.bit.WDHALTI = 1; // 從休眠中開啟 , 全部重設!! EDIS; } v1 = 3031; v2 = (int)Voltage1[array]; k1 = 0.3; //0.0001; k2 = 0.000055; verr = v1 - v2; vk2 = verr + z1; z1 = verr; vko2 =(int) vk2 * k2; if (vko2 >= 1400) { vko2 = 1400; } else if (vko2 <= -1300) /////////////////////// { vko2 = -1300; } vou2 = vko2 + z2; z2 = vou2; vk1 = verr; vko1 =(int) vk1 * k1; vout =(int)( vou2 + vko1); if (vout >= 1400) { vout = 1400; } else if (vout <= 0) { vout = 0; } EALLOW; EPwm1Regs.CMPA.half.CMPA = 1500 - vout; // Set compare A value EDIS; if (array < 255) array++; else array = 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; } } }
void main() { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2803x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initialize GPIO: // Enable XCLOCKOUT to allow monitoring of oscillator 1 EALLOW; GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; //enable XCLOCKOUT through GPIO mux SysCtrlRegs.XCLK.bit.XCLKOUTDIV = 2; //XCLOCKOUT = SYSCLK // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2803x_PieCtrl.c file. 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). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2803x_DefaultIsr.c. // This function is found in DSP2803x_PieVect.c. InitPieVectTable(); // Step 4. Initialize all the Device Peripherals: // Configure and Initialize the ADC: InitAdc(); AdcOffsetSelfCal(); EALLOW; AdcRegs.ADCCTL1.bit.TEMPCONV = 1; //Connect channel A5 internally to the temperature sensor AdcRegs.ADCSOC0CTL.bit.CHSEL = 5; //Set SOC0 channel select to ADCINA5 AdcRegs.ADCSOC1CTL.bit.CHSEL = 5; //Set SOC1 channel select to ADCINA5 AdcRegs.ADCSOC0CTL.bit.ACQPS = 36; //Set SOC0 acquisition period to 37 ADCCLK AdcRegs.ADCSOC1CTL.bit.ACQPS = 36; //Set SOC1 acquisition period to 37 ADCCLK AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //Connect ADCINT1 to EOC1 AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enable ADCINT1 // Note: two channels have been connected to the temp sensor // so that the first sample can be discarded to avoid the // ADC first sample issue. See the device errata. // Set the flash OTP wait-states to minimum. This is important // for the performance of the temperature conversion function. FlashRegs.FOTPWAIT.bit.OTPWAIT = 1; //Main program loop - continually sample temperature for(;;) { //Sample the temp sensor... //Force start of conversion on SOC0 and SOC1 AdcRegs.ADCSOCFRC1.all = 0x03; //Wait for end of conversion. while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){} //Wait for ADCINT1 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 //Get temp sensor sample result from SOC1 temp = AdcResult.ADCRESULT1; //Convert the raw temperature sensor measurement into temperature degC = GetTemperatureC(temp); degK = GetTemperatureK(temp); } }
/** * initializes an ADC for further usage * @param pinPair the pin of the ADC(s). 0, 1, 2 or 4 are valid numbers * ADC0 = Pin19 (A) / Pin22 (B) * ADC1 = Pin18 (A) / Pin23 (B) * ADC2 = Pin17 (A) / Pin24 (B) * ADC4 = Pin16 (A) / Pin25 (B) * @param frequency the frequency (in Hz) at which the ADC operates (between 1,000 and 100,000) * @param buffer1 The initialized Utilities_SimpleBuffer struct the data from ADCxA is written into * @param buffer2 The Initialized Utilities_SimpleBuffer struct the data from ADCxB is written into (can be zero). * If no buffer2 is specified, ADCxB is not used. */ int Input_ADC_Init(int pinPair, long frequency, Utilities_SimpleBuffer *buffer1, Utilities_SimpleBuffer *buffer2, void (*isr)(float32*, float32*)) { if(pinPair < 0 || pinPair > 4 || pinPair == 3) { return INPUT_ADC_INVALID_PIN; } if(frequency > 100000 || frequency < 1000) { return INPUT_ADC_INVALID_FREQUENCY; } if(*isr == 0) { return INPUT_ADC_INVALID_ISR; } if(!buffer1) { return INPUT_ADC_INVALID_BUFFER; } if(buffer2) { if(buffer1->size != buffer2->size) { return INPUT_ADC_ILLEGAL_BUFFERSIZE; } } if(Input_ADC_isInitialized == 0) { InitAdc(); } Input_ADC_buffers[pinPair * 2] = buffer1; Input_ADC_buffers[pinPair * 2 + 1] = buffer2; EALLOW; AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //throw interrupt after conversion EDIS; Input_ADC_callbackFinish[pinPair] = isr; Input_ADC_epwms[pinPair]->TBCTL.bit.PHSEN = TB_ENABLE; Input_ADC_epwms[pinPair]->TBPRD = 40000000 / frequency; //period = 40M / frequency Input_ADC_epwms[pinPair]->TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //Count up and down Input_ADC_epwms[pinPair]->ETSEL.bit.SOCASEL = ET_CTR_PRDZERO; //Select INT on Zero and period Input_ADC_epwms[pinPair]->ETSEL.bit.SOCAEN = 1; //Enable SOCA Input_ADC_epwms[pinPair]->ETPS.bit.SOCAPRD = ET_1ST; //Generate INT on 1st event if(pinPair == 0) { IER |= M_INT1; EALLOW; AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0x11; //EPwm7 -> SOCA0/1 AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; //sample A0 and B0 AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //minimum window-size AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 1; //enable simultanious sampling AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //EOC1 triggers ADCINT1 AdcRegs.INTSEL1N2.bit.INT1E = 1; //enable interrupt AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //interrupt only if flag-bit is cleared PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //enable ADC-interrupts PieVectTable.ADCINT1 = &Input_ADC_A0B0_ISR; EDIS; } else if(pinPair == 1) { IER |= M_INT1; EALLOW; AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 0x11; //EPwm7 -> SOCA2/3 AdcRegs.ADCSOC2CTL.bit.CHSEL = 1; //sample A1 and B1 AdcRegs.ADCSOC2CTL.bit.ACQPS = 6; //minimum window-size AdcRegs.ADCSAMPLEMODE.bit.SIMULEN2 = 1; //enable simultaneous sampling AdcRegs.INTSEL1N2.bit.INT2SEL = 3; //EOC3 triggers ADCINT2 AdcRegs.INTSEL1N2.bit.INT2E = 1; //enable interrupt AdcRegs.INTSEL1N2.bit.INT2CONT = 0; //interrupt only if flag-bit is cleared PieCtrlRegs.PIEIER1.bit.INTx2 = 1; //enable ADC-interrupts PieVectTable.ADCINT2 = &Input_ADC_A1B1_ISR; EDIS; } else if(pinPair == 2) { IER |= M_INT10; EALLOW; AdcRegs.ADCSOC4CTL.bit.TRIGSEL = 0x11; //EPwm7 -> SOCA4/5 AdcRegs.ADCSOC4CTL.bit.CHSEL = 2; //sample A2 and B2 AdcRegs.ADCSOC4CTL.bit.ACQPS = 6; //minimum window-size AdcRegs.ADCSAMPLEMODE.bit.SIMULEN4 = 1; //enable simultaneous sampling AdcRegs.INTSEL3N4.bit.INT3SEL = 5; //---1 //EOC5 triggers ADCINT3 AdcRegs.INTSEL3N4.bit.INT3E = 1; //enable interrupt AdcRegs.INTSEL3N4.bit.INT3CONT = 0; //interrupt only if flag-bit is cleared PieCtrlRegs.PIEIER10.bit.INTx3 = 1; //enable ADC-interrupt3 in group 10 PieVectTable.ADCINT3 = &Input_ADC_A2B2_ISR; EDIS; } else if(pinPair == 4) { IER |= M_INT10; EALLOW; AdcRegs.ADCSOC6CTL.bit.TRIGSEL = 0x13; //EPwm8 -> SOCA6/7 AdcRegs.ADCSOC6CTL.bit.CHSEL = 4; //sample A4 and B4 AdcRegs.ADCSOC6CTL.bit.ACQPS = 6; //minimum window-size AdcRegs.ADCSAMPLEMODE.bit.SIMULEN6 = 1; //enable simultanious sampling AdcRegs.INTSEL3N4.bit.INT4SEL = 7; //EOC7 triggers ADCINT4 AdcRegs.INTSEL3N4.bit.INT4E = 1; //enable interrupt AdcRegs.INTSEL3N4.bit.INT4CONT = 0; //interrupt only if flag-bit is cleared PieCtrlRegs.PIEIER10.bit.INTx4 = 1; //enable ADC-interrupts PieVectTable.ADCINT4 = &Input_ADC_A4B4_ISR; EDIS; } Input_ADC_isInitialized = 1; return INPUT_ADC_SUCCESS; }