//C595 GPIO11
//SI GPIO12
//SO GPIO13
//SCK GPIO14
//CS GPIO15
//C165 GPIO19
//SO164 GPIO30
//CLK164 GPIO31
//1.0pu=360degree
#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File
#include "IQmathLib.h"
#include <math.h>
#include "park.h" // Include header for the PARK object
#include "ipark.h" // Include header for the IPARK object
#include "pid_reg3.h" // Include header for the PIDREG3 object
#include "clarke.h" // Include header for the CLARKE object
#include "svgen_dq.h" // Include header for the SVGENDQ object
#include "rampgen.h" // Include header for the RAMPGEN object
#include "rmp_cntl.h" // Include header for the RMPCNTL object
#include "speed_fr.h" // Include header for the SPEED_MEAS_QEP object
#include "f280x_en.h" // Include header for the DRIVE object
#include "f280xqep.h" // Include header for the QEP object
#include "f280xileg_vdc.h" // Include header for the ILEG2DCBUSMEAS object
#include "f280xpwm.h" // Include header for the PWMGEN object
#include "f280xpwmdac.h" // Include header for the PWMDAC object
// Maximum Dead Band values
#define EPWM1_MAX_DB 0x03FF
#define EPWM2_MAX_DB 0x03FF
#define EPWM3_MAX_DB 0x03FF
#define EPWM1_MIN_DB 0
#define EPWM2_MIN_DB 0
#define EPWM3_MIN_DB 0
// To keep track of which way the Dead Band is moving
#define DB_UP 1
#define DB_DOWN 0
#define BUF_SIZE 16 // Sample buffer size
#define PI 3.14159265358979
#define SYSTEM_FREQUENCY 100
#define ISR_FREQUENCY 20
Uint16 LEDTable[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7c,0x39,0x5e,0x7b,0x71};
Uint16 DISTable[6];
struct SPIDATA_BITS { // bits description
Uint16 SBIT0:1; // 4:0 Interrupt level
Uint16 SBIT1:1; // 5 Interrupt enable
Uint16 SBIT2:1; // 6 Clear INT flag
Uint16 SBIT3:1; // 7 INT flag
Uint16 SBIT4:1; // 12:8 FIFO status
Uint16 SBIT5:1; // 13 FIFO reset
Uint16 SBIT6:1; // 14 Clear overflow
Uint16 SBIT7:1; // 15 FIFO overflow
Uint16 rsvd:8; //Reserved
};
union SPIDATA_REG {
Uint16 all;
struct SPIDATA_BITS bit;
};
struct SPIDATA_REGS {
union SPIDATA_REG SDREG;
Uint32 rsvd1;
};
struct SPIDATA_REGS S595DataRegs;
struct SPIDATA_REGS S164DataRegs;
struct SPIDATA_REGS S165AlertData;
struct SPIDATA_REGS S165KeyData;
struct SPIDATA_REGS CONTROL1;
// Prototype statements for functions found within this file.
void Gpio_setup(void);
interrupt void cpu_timer0_isr(void);
interrupt void cpu_timer1_isr(void);
interrupt void cpu_timer2_isr(void);
interrupt void MainISR(void);
// Global variables used in this example
float32 T = 0.001/ISR_FREQUENCY; // Samping period (sec), see parameter.h
int COUNT;
int DISCOUNT;
int SPIDATA;
int KEYWAIT;
int wid = 0;
int16 ImeasA = 0;
int16 ImeasB = 0;
Uint16 IsrTicker = 0;
Uint16 IsrTicker1 = 0;
int angleid = 0;
float32 VdTesting = 0; // Vd testing (pu)
float32 VqTesting = 0.25; // Vq testing (pu)
float32 IdRef = 0; // Id reference (pu)
float32 IqRef = 0.2; // Iq reference (pu)
float32 angle1 =0;
float32 angle2 =0;
float a[8]= { -0.9, 1.45, -0.576,.5184,-1.18,.81,0.,0. };
// Instance a PWM driver instance
PWMGEN pwm1 = PWMGEN_DEFAULTS;
// Instance a Space Vector PWM modulator. This modulator generates a, b and c
// phases based on the d and q stationery reference frame inputs
SVGENDQ svgen_dq1 = SVGENDQ_DEFAULTS;
// Instance a few transform objects
CLARKE clarke1 = CLARKE_DEFAULTS;
PARK park1 = PARK_DEFAULTS;
IPARK ipark1 = IPARK_DEFAULTS;
// Instance PID regulators to regulate the d and q synchronous axis currents,
// and speed
PIDREG3 pid1_id = PIDREG3_DEFAULTS;
PIDREG3 pid1_iq = PIDREG3_DEFAULTS;
void main(void)
{
//struct SPIDATA_REGS SPIDATA1;
//Uint16 i;
//Uint16 SPIDATA;
KEYWAIT = 0;
CONTROL1.SDREG.all = 0;
wid=0;
DISTable[0] = LEDTable[0];
DISTable[1] = LEDTable[1];
DISTable[2] = LEDTable[2];
DISTable[3] = LEDTable[3];
DISTable[4] = LEDTable[4];
DISTable[5] = LEDTable[5];
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP280x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
Gpio_setup();
GpioDataRegs.GPADAT.all =0x00000000;
GpioDataRegs.GPBDAT.all =0x00000000;
// 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 DSP280x_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 DSP280x_DefaultIsr.c.
// This function is found in DSP280x_PieVect.c.
InitPieVectTable();
// Enable CNT_zero interrupt using EPWM1 Time-base
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation
EPwm1Regs.ETSEL.bit.INTSEL = 1; // Enable interrupt CNT_zero event
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event
EPwm1Regs.ETCLR.bit.INT = 1; // Enable more interrupts
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
EALLOW; // This is needed to write to EALLOW protected registers
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
// HISPCP prescale register settings, normally it will be set to default values
SysCtrlRegs.HISPCP.all = 0x0000; // SYSCLKOUT/1
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP280x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0 to interrupt every second:
// 100MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 100, 1000);
StartCpuTimer0();
// Configure CPU-Timer 1 to interrupt every second:
// 100MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer1, 100, 0.033333);
StartCpuTimer1();
// Configure CPU-Timer 2 to interrupt every second:
// 100MHz CPU Freq, 1 m second Period (in uSeconds)
// ConfigCpuTimer(&CpuTimer2, 100, 1000);
// StartCpuTimer2();
// Step 5. User specific code, enable interrupts:
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.XINT13 = &cpu_timer1_isr;
PieVectTable.TINT2 = &cpu_timer2_isr;
PieVectTable.EPWM1_INT = &MainISR;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable CPU INT1 which is connected to CPU-Timer 0:
// Enable CPU INT13 which is connected to CPU-Timer 1:
// Enable CPU INT14 which is connected to CPU-Timer 2:
// Enable CPU INT3 for EPWM1_INT:
// IER |= (M_INT1 | M_INT3 | M_INT13 );
IER |= (M_INT1 | M_INT13);
// Enable TINT0 in the PIE: Group 1 interrupt 7
Test_SPI1.rar_spi 74ls165_spi 8_软SPI
版权申诉
192 浏览量
2022-09-23
11:06:34
上传
评论
收藏 5KB RAR 举报
小贝德罗
- 粉丝: 71
- 资源: 1万+
最新资源
- navicat开发教程.docx
- 基于图像的机器人视觉伺服系统研究
- CAD实验报告:制药车间动力控制系统图、烘烤车间电气控制图、JSJ型晶体管式时间继电器原理图、液位控制器电路图
- IMG_9692.PNG
- 基于SpringBoot+Vue 的网上书城项目源码+数据库脚本(毕业设计)
- 基于springboot+vue的网上书店系统源码+数据库+使用文档(高分毕设)
- 前端学习路线推荐+自己做的一个前端项目(旅游线路推广)+通过购买腾讯云服务器上传的个人经历(附带部分关键源码)
- 制造业IT规划咨询汇报方案
- 开车不犯困100首.之1~10,DJ
- Keil 找不到编译器 Missing:Complier Version5 的解决方法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈