void InitEQepGpio() { #if DSP28_EQEP1 InitEQep1Gpio(); #endif // endif DSP28_EQEP1 #if DSP28_EQEP2 InitEQep2Gpio(); #endif // endif DSP28_EQEP2 }
// // InitEQepGpio - This function initializes GPIO pins to function as eQEP pins // Each GPIO pin can be configured as a GPIO pin or up to 3 // different peripheral functional pins. By default all pins // come up as GPIO inputs after reset. // Caution: // For each eQEP peripheral // Only one GPIO pin should be enabled for EQEPxA operation. // Only one GPIO pin should be enabled for EQEPxB operation. // Only one GPIO pin should be enabled for EQEPxS operation. // Only one GPIO pin should be enabled for EQEPxI operation. // Comment out other unwanted lines. // void InitEQepGpio() { InitEQep1Gpio(); InitEQep2Gpio(); InitEQep3Gpio(); }
/** * Module initialization * @param void * @returns void */ void CONIN_vInit(void) { InitEQep1Gpio(); InitEQep2Gpio(); }
// // Main // void main(void) { // // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2837xS_SysCtrl.c file. // InitSysCtrl(); // // Step 2. Initialize GPIO: // This example function is found in the F2837xS_Gpio.c file and // illustrates how to set the GPIO to its default state. // // InitGpio(); // Skipped for this example // // Only init the GPIO for EQep1 and EPwm1 in this case // This function is found in F2837xS_EQep.c // InitEQep1Gpio(); InitEPwm1Gpio(); // // 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 F2837xS_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 F2837xS_DefaultIsr.c. // This function is found in F2837xS_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.EPWM1_INT= &prdTick; EDIS; // This is needed to disable write to EALLOW protected registers // // Step 4. Initialize all the Device Peripherals: // Example specific ePWM setup. This function is found // in Example_EPwmSetup.c // EPwmSetup(); // // Step 5. User specific code, enable __interrupts: // Enable CPU INT1 which is connected to CPU-Timer 0: // IER |= M_INT3; // // Enable TINT0 in the PIE: Group 3 __interrupt 1 // PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // // Enable global Interrupts and higher priority real-time debug events: // EINT; // Enable Global __interrupt INTM ERTM; // Enable Global realtime __interrupt DBGM // // Initializes eQEP for frequency calculation in // FREQCAL_Init(void)function in Example_EPwmSetup.c // freq.init(&freq); for(;;) { } }
void InitEQepGpio() { InitEQep1Gpio(); //InitEQep2Gpio(); }
void main(void) { // 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: // This example function is found in the DSP2803x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // For this case only init GPIO for eQEP1 and ePWM1 // This function is found in DSP2803x_EQep.c InitEQep1Gpio(); InitEPwm1Gpio(); EALLOW; GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // GPIO4 as output simulates Index signal GpioDataRegs.GPACLEAR.bit.GPIO4 = 1; // Normally low EDIS; // 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 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(); // 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.EPWM1_INT= &prdTick; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: initEpwm(); // This function exists in Example_EPwmSetup.c // Step 5. User specific code, enable interrupts: // Enable CPU INT1 which is connected to CPU-Timer 0: IER |= M_INT3; // Enable TINT0 in the PIE: Group 3 interrupt 1 PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM qep_posspeed.init(&qep_posspeed); for(;;) { } }
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; //} } }