0 foreword
Some time ago, I was really busy writing papers and doing experiments in the laboratory, but I haven't updated them for a long time. Recently, some students often ask if there are any permanent magnet synchronous motor series experimental courses???
Considering that DSP programming is needed for motor control, it is very difficult for students who don't know DSP to control motor directly. Therefore, it was decided that a series of basic courses of DSP28335 should be done before that.
The new series of DSP28335 basic courses are divided into the following periods:
(1) GPIO output (flow lamp test)
(2) GPIO input (matrix key scan)
(3) System timer CPUTimer
(4) SCI serial port communication experiment (upper computer transceiver display)
(5) External interrupt control (key triggered)
(6) SPI communication experiment (LCD12864 display control)
(7) I2C communication experiment (OLED display control)
(8) DMA to ADC conversion (external voltage acquisition)
(9) EPWM experiment (breathing lamp control)
(10) ECAP experiment (ultrasonic ranging)
(11) EQEP experiment (DC motor speed detection)
(12) ECAN experiment (upper computer transceiver display control)
There are still quite a lot of contents. Understand these basic peripherals, and then combine the motor control with the previous theoretical simulation algorithm, which is basically no pressure.
In order to do these tutorials, I have designed a dsp28335 core board. Later, I will explain DSP code based on the core board and related peripherals, combined with the underlying hardware principles. (it's faster to see the core board first. You can search for "some treasure" by yourself if you need)
catalog
1. Hardware and control principle
2. DSP code introduction
3. Experimental results
4. Conclusion
1. Hardware and control principle
As shown in the figure, in the core board, the LED is co anode, and the cathode is respectively connected to GPIO0~GPIO4. When the corresponding IO port output low level, LED light, high level, led off. In order to make the LED work in the form of running water lamp, it is necessary to successively control the level inversion of IO port twice (add delay between the two reversals).
2 DSP code introduction
Before looking at the code, look at the workflow diagram. Because there are too many registers in 28335, you can refer to the register description in the data manual. There are also notes in the code part (Note: double click the code to see it, otherwise it will be incomplete).
/** * ******************************************************************************************** * @file main.c * @file SK Electronics * @version V1.0 * @date 2020-xx-xx * @brief LED Running water lamp test * ******************************************************************************************* * @attention * Experimental platform: SK-F28335Mini core board * CSDN Blog: https://blog.csdn.net/weixin_ forty-six million five hundred and fifty-six thousand six hundred and ninety-six * TaoBao: https://shop409670932.taobao.com */ #include "DSP28x_Project.h" #include "bsp_led.h" #define FLASH_RUN 1 #define SRAM_RUN 2 #define RUN_TYPE FLASH_RUN #if RUN_TYPE==FLASH_RUN extern Uint16 RamfuncsLoadStart; extern Uint16 RamfuncsLoadEnd; extern Uint16 RamfuncsRunStart; #endif void delay_1ms(Uint16 t); /** * @brief Main function * @parameter nothing * @return_value nothing */ void main(void) { /*Step 1: initialize system control:*/ InitSysCtrl(); /*Step 2: initialize GPIO port*/ InitGpio(); /* Step 3: clear all interrupt and initialize PIE vector table:*/ DINT;// Disable CPU interrupt InitPieCtrl();// Initialize the PIE control register to the default state where all PIE interrupts are disabled and flag bits are cleared IER = 0x0000;// Disable CPU interrupt and clear all CPU interrupt flags: IFR = 0x0000; InitPieVectTable();// Initialize PIE interrupt vector table // Interrupt remapping, register interrupt program entry (users add as required) // /*Program burning in 28335 (optional)*/ #if RUN_TYPE==FLASH_RUN MemCopy(&RamfuncsLoadStart,&RamfuncsLoadEnd,&RamfuncsRunStart); InitFlash(); #endif /* Step 4: initialize on-chip peripherals*/ // InitPeripherals(); / / initializes all peripherals (not required by this routine) /* Step 5: add user function specific code*/ LED_GPIO_Config();//LED port initialization /*Step 6: enter the main cycle*/ for(;;) { LED0(1); delay_1ms(1000); LED0(0); LED1(1); delay_1ms(1000); LED1(0); LED2(1); delay_1ms(1000); LED2(0); LED3(1); delay_1ms(1000); LED3(0); LED4(1); delay_1ms(1000); LED4(0); } } /** * @brief 1ms Delay function * @parameter t * @return_value nothing */ void delay_1ms(Uint16 t) { while(t--) { DELAY_US(1000); } }
/** * ******************************************************************************************** * @file bsp.led.c * @file SK Electronics * @version V1.0 * @date 2020-xx-xx * @brief LED Application function interface * ******************************************************************************************* * @attention * Experimental platform: SK-F28335Mini core board * CSDN Blog: https://blog.csdn.net/weixin_ forty-six million five hundred and fifty-six thousand six hundred and ninety-six * TaoBao: https://shop409670932.taobao.com */ #include "bsp_led.h" void LED_GPIO_Config(void) { EALLOW; GpioCtrlRegs.GPAMUX1.bit.GPIO0=0;//Normal IO mode GpioCtrlRegs.GPAPUD.bit.GPIO0=0;//Enable internal pull-up GpioCtrlRegs.GPADIR.bit.GPIO0=1;//Configure as output GpioCtrlRegs.GPAMUX1.bit.GPIO1=0;//Normal IO mode GpioCtrlRegs.GPAPUD.bit.GPIO1=0;//Enable internal pull-up GpioCtrlRegs.GPADIR.bit.GPIO1=1;//Configure as output GpioCtrlRegs.GPAMUX1.bit.GPIO2=0;//Normal IO mode GpioCtrlRegs.GPAPUD.bit.GPIO2=0;//Enable internal pull-up GpioCtrlRegs.GPADIR.bit.GPIO2=1;//Configure as output GpioCtrlRegs.GPAMUX1.bit.GPIO3=0;//Normal IO mode GpioCtrlRegs.GPAPUD.bit.GPIO3=0;//Enable internal pull-up GpioCtrlRegs.GPADIR.bit.GPIO3=1;//Configure as output GpioCtrlRegs.GPAMUX1.bit.GPIO4=0;//Normal IO mode GpioCtrlRegs.GPAPUD.bit.GPIO4=0;//Enable internal pull-up GpioCtrlRegs.GPADIR.bit.GPIO4=1;//Configure as output GpioDataRegs. GPASET.bit.GPIO0=1; GpioDataRegs. GPASET.bit.GPIO1=1; GpioDataRegs. GPASET.bit.GPIO2=1; GpioDataRegs. GPASET.bit.GPIO3=1; GpioDataRegs. GPASET.bit.GPIO4=1; EDIS; }
/** * ******************************************************************************************** * @file bsp_led.h * @file SK Electronics * @version V1.0 * @date 2020-xx-xx * @brief LED Application function interface header file * ******************************************************************************************* * @attention * Experimental platform: SK-F28335Mini core board * CSDN Blog: https://blog.csdn.net/weixin_ forty-six million five hundred and fifty-six thousand six hundred and ninety-six * TaoBao: https://shop409670932.taobao.com */ #ifndef _BSP_LED_H_ #define _BSP_LED_H_ #include "DSP28x_Project.h" /* Macro with parameter, can be used like inline function, low level light*/ #define LED0(a) if (a) \ GpioDataRegs. GPACLEAR.bit.GPIO0=1;\ else \ GpioDataRegs. GPASET.bit.GPIO0=1 #define LED1(a) if (a) \ GpioDataRegs. GPACLEAR.bit.GPIO1=1;\ else \ GpioDataRegs. GPASET.bit.GPIO1=1 #define LED2(a) if (a) \ GpioDataRegs. GPACLEAR.bit.GPIO2=1;\ else \ GpioDataRegs. GPASET.bit.GPIO2=1 #define LED3(a) if (a) \ GpioDataRegs. GPACLEAR.bit.GPIO3=1;\ else \ GpioDataRegs. GPASET.bit.GPIO3=1 #define LED4(a) if (a) \ GpioDataRegs. GPACLEAR.bit.GPIO4=1;\ else \ GpioDataRegs. GPASET.bit.GPIO4=1 /*Define macro of IO port*/ #define LED0_TOGGLE GpioDataRegs. GPATOGGLE.bit.GPIO0=1 #define LED0_OFF GpioDataRegs. GPASET.bit.GPIO0=1 #define LED0_ON GpioDataRegs. GPACLEAR.bit.GPIO0=1 #define LED1_TOGGLE GpioDataRegs. GPATOGGLE.bit.GPIO1=1 #define LED1_OFF GpioDataRegs. GPASET.bit.GPIO1=1 #define LED1_ON GpioDataRegs. GPACLEAR.bit.GPIO1=1 #define LED2_TOGGLE GpioDataRegs. GPATOGGLE.bit.GPIO2=1 #define LED2_OFF GpioDataRegs. GPASET.bit.GPIO2=1 #define LED2_ON GpioDataRegs. GPACLEAR.bit.GPIO2=1 #define LED3_TOGGLE GpioDataRegs. GPATOGGLE.bit.GPIO3=1 #define LED3_OFF GpioDataRegs. GPASET.bit.GPIO3=1 #define LED3_ON GpioDataRegs. GPACLEAR.bit.GPIO3=1 #define LED4_TOGGLE GpioDataRegs. GPATOGGLE.bit.GPIO4=1 #define LED4_OFF GpioDataRegs. GPASET.bit.GPIO4=1 #define LED4_ON GpioDataRegs. GPACLEAR.bit.GPIO4=1 void LED_GPIO_Config(void); #endif /*_BSP_LED_H_ */
3 experimental results
Experimental equipment: core board
Connect the XDS100V3 emulator to the JTAG interface, and configure and select the corresponding emulator in the project.
Click the burn button, you can see LED0~4 running water lamp phenomenon.
4 Conclusion
This issue focuses on the configuration of GPIO port output register, which is a very important and basic function, which will be used in the future basic tutorials.
You can refer to the code to try to see if you can make a pattern of running water lamp ha ~ welcome to leave a message if you have any questions!!