《基于dsp的磁悬浮小灯控制系统本科学位论文.doc》由会员分享,可在线阅读,更多相关《基于dsp的磁悬浮小灯控制系统本科学位论文.doc(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、基于DSP的磁悬浮小灯控制系统摘 要我们组设计的磁悬浮小灯控制系统是基于TMS320F28377s DSP芯片。本设计采用了上下两个霍尔元件作为感应器,通过DSP中的AD模块去采集这两路信号,然后经过PID控制后把输出通过DSP的DA模块将数据发送到驱动器控制线圈电流大小,以改变磁场来控制灯的位置使其保持悬浮,整个系统够成了一个闭环控制系统,抗干扰能力强,新颖且可广泛于教育领域,增加学生的学习兴趣。Abstract关键词:TMS320F28337S PID控制 闭环控制系统基于DSP的磁悬浮小灯控制系统目 录摘要Abstract引言1第一章 磁悬浮小灯控制系统的结构 11.1 电源部分 21.
2、2 AD转换部分 21.3 PID部分 31.4 DA转换部分 41.5 驱动器部分 5第二章 程序流程图6结论6致谢6参考文献7附录8引言目前在现实生活中,磁悬浮技术得到了广泛的应用,本设计采用把磁悬浮技术使得小灯并发亮保持悬浮,改变了传统的照明技术,其中也用到了PID闭环控制。非常新颖,且系统比较稳定,能够很好的应用于教育领域,增加学生的学习兴趣。对其他领域也有广泛的启发意义。第一章 磁悬浮小灯控制系统的结构分析仪使用DSP28377S开发平台作为基础。整个系统可以分成5个部分:(1) 开关电源部分:给系统提供24V电源。(2) AD采集部分:使用TMS320X28377S内部的AD外设,
3、对待测的的霍尔元件两端进行模数转换。得到数字量表示的电压值。 (3) PID部分:在DSP中,使用AD模块采集到的外部信号,并转化为数字信号作为PID控制器的反馈信号,然后设定期望值,在DSP中经过数字PID计算后通过DA模块传送给驱动器,从而使得驱动模块能够调整电流的大小,一控制磁场的强度,是灯保持悬浮。(4) 驱动模块部分:根据DA传送过来的信号输出相应大小电流给线圈。(5) DA输出部分:使用TMS320F28377S内部的DA外设,把经过PID计算的输出量传送给外部的驱动器。磁悬浮小灯控制系统整体结构图,如图1所示。图1 磁悬浮小灯控制系统整体结构图1.1 开关电源部分设备的电源部分的
4、目的是为了给整个系统体提供24v的电源。图 2 系统的电源部分1.2 AD转换部分1.2.1 AD转换本设计采用TMS320F28377S内部的A/D转换器来采集外部霍尔元件的信号。TMS320F28377S内部的A/D转换器的特性如下1. 12位或16位的转换精度2. 最高25MHz 的转换速度、3. 16路独立通道。由于控制系统的整体工作频率比这芯片内部25MHz的最高转换速度慢。为了得到更加精确的转换值,可以采用采集10次数据,讲采集到的数据就行快速排序,去掉采集到系统的最高和最低的值,然后将这8次数据求其平均值。把这样处理后的结果再当做一次采集的数据。1.2.2 AD转化的实现1. 配
5、置AD转换的时钟信号ADCCLK,系统预分频。2. 配置AD转换的采样模式,本设计才用12位通道,单端模式。3. 配置AD转换的通道以及转换完成后中断标志清零。1.3 PID控制部分1.3.1 PID控制原理 PID 控制器是一个在工业控制应用中常见的反馈回路部件。这个控制器把收集到的数据和一个参考值进行比较,然后把这个差别用于计算新的输入值,这个新的输入值的目的是可以让系统的数据达到或者保持在参考值。和其他简单的控制运算不同,PID控制器可以根据历史数据和差别的出现率来调整输入值,这样可以使系统更加准确,更加稳定。可以通过数学的方法证明,在其他控制方法导致系统有稳定误差或过程反复的情况下,一
6、个PID反馈回路却可以保持系统的稳定。图 3 PID控制原理图1.3.2 PID控制的实现 在DSP中,使用AD模块采集到的外部信号,并转化为数字信号作为PID控制器的反馈信号,然后设定期望值,在DSP中经过数字PID计算后通过DA模块传送给驱动器,从而使得驱动模块能够调整电流的大小,一控制磁场的强度,是灯保持悬浮。 1.定义变量 float ek1 = 0; /偏差ek-1 float Kp = -2.2; /定义比例系数 float Ki = 0; /定义积分常数 float Kd = -0.03; /定义微分常数 float delta = 0; /定义误差 float uk = 0;
7、/uk 2.采用PD控制实现程序float PID(float ek)delta = ek-ek1;uk = Kp*ek+Kd/T*delta;ek1 = ek;return uk;1.4 DA部分1.4.1 DA转换1.4.2 DA转换实现1.5 驱动器部分PID转换结束后,输出的数据就被存放DA_value中,传送给驱动器,图 4 驱动器图第二章 程序流程图磁悬浮小灯系统程序流程图如下:图5 C程序流程图结论本设计实现了基于TMS320F28337S的磁悬浮小灯控制系统。使用了TMS320F28377S内部的ADC、DAC资源,整个实验设计首先通过AD采集外部的信号,然后经过PID计算处理
8、后,再通过DA将数据发送到驱动器控制线圈电流大小,以改变磁场来控制灯的位置使其保持悬浮。致谢感参考文献1 Texas Instrument TMS320F2837xS Delfino MicrocontrollersM.Literature Number: SPRUHX5C,2015 2 Texas Instruments. Using PWM Output as a Digital-to-Analog Converter on a TMS320F28377 Digital Signal Controller M. Application Report: SPRAA88A,20083 Texa
9、s Instruments.附 录主程序清单: #include F28x_Project.h / Device Headerfile and Examples Include Filevoid ConfigureADC(void);void SetupADCSoftware(void);void error(void);unsigned long AD_UP10,AD_DOWN10;float offset=1;/ /设置补偿float Exp=-1.2;/ /定义期望int AD_value;float Real; /当前实际电压unsigned long AD_UP_AVE,AD_DOW
10、N_AVE;float ek1 = 0; /偏差ek-1float Kp = -2.2; /定义比例系数float Ki = 0; /定义积分常数float Kd = -0.03; /定义微分常数float T = 0.001; /定义周期float sum = 0;float delta = 0;float uk = 0; /ukfloat abso(float ek)if ( ek = 65535)i = 65535;else if ( i = 0)i = 0;return i;void DAC_send(unsigned char Passage, unsigned int dat)un
11、signed char i, mode;unsigned int j;switch(Passage)/0x20:通道A0x22: 通道B0x24:通道C0x26:通道D.设置软件自动更新case 0:mode = 0x20;break;case 1:mode = 0x22;break;case 2:mode = 0x24;break;case 3:mode = 0x26;break;default :break;for(i=0;i8;i+)/DA8534_DIN(mode&0x80);j = mode&0x80;if (j=0)GpioDataRegs.GPADAT.bit.GPIO16 =
12、0;/ioport_set_pin_level(PIO_PB8_IDX,IOPORT_PIN_LEVEL_LOW); /data=0elseGpioDataRegs.GPADAT.bit.GPIO16 = 1;/ioport_set_pin_level(PIO_PB8_IDX,IOPORT_PIN_LEVEL_HIGH); /data=1DELAY_US(2);GpioDataRegs.GPADAT.bit.GPIO18 = 1;/ioport_set_pin_level(PIO_PB10_IDX,IOPORT_PIN_LEVEL_HIGH); /clk=1DELAY_US(2);mode =
13、 1;DELAY_US(2);GpioDataRegs.GPADAT.bit.GPIO18 = 0;/ioport_set_pin_level(PIO_PB10_IDX,IOPORT_PIN_LEVEL_LOW); /clk=0DELAY_US(2);for(i=0;i16;i+)/DA8534_DIN(dat&0x8000);j = dat&0x8000;if (j=0)GpioDataRegs.GPADAT.bit.GPIO16 = 0;/ioport_set_pin_level(PIO_PB8_IDX,IOPORT_PIN_LEVEL_LOW); /data=0elseGpioDataR
14、egs.GPADAT.bit.GPIO16 = 1;/ioport_set_pin_level(PIO_PB8_IDX,IOPORT_PIN_LEVEL_HIGH); /data=1DELAY_US(2);GpioDataRegs.GPADAT.bit.GPIO18 = 1;/ioport_set_pin_level(PIO_PB10_IDX,IOPORT_PIN_LEVEL_HIGH); /clk=1DELAY_US(2);dat = 1;DELAY_US(2);GpioDataRegs.GPADAT.bit.GPIO18 = 0;/ioport_set_pin_level(PIO_PB10
15、_IDX,IOPORT_PIN_LEVEL_LOW); /clk=0DELAY_US(2);GpioDataRegs.GPADAT.bit.GPIO19 = 1;/ioport_set_pin_level(PIO_PB11_IDX,IOPORT_PIN_LEVEL_HIGH); /cs=1void quick(unsigned long *a,int i,int j)int m,n,temp;int k;m=i;n=j;k=a(i+j)/2;do while(amk&mk&ni) n-;if(m=n) temp=am;am=an;an=temp;m+;n-;while(m=n);if(mi)
16、quick(a,i,n);_interrupt void cpu_timer0_isr(void)unsigned long i;float ek=0;float Output; /变化unsigned long DA_value;CpuTimer0.InterruptCount+;GpioDataRegs.GPADAT.bit.GPIO12 = 1; /turn on ledAD_UP_AVE=0;AD_DOWN_AVE=0;for (i=0;i10;i+) /AD sample 10 times /convert, wait for completion, and store result
17、s/start conversions immediately via software, ADCAAdcaRegs.ADCSOCFRC1.all = 0x0003; /SOC0 and SOC1/start conversions immediately via software, ADCB/wait for ADCA to complete, then acknowledge flagwhile(AdcaRegs.ADCINTFLG.bit.ADCINT1 = 0);AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;AD_UPi = AdcaResultRegs.
18、ADCRESULT0;AD_DOWNi = AdcaResultRegs.ADCRESULT1;quick(AD_UP,0,9); /sortquick(AD_DOWN,0,9);AD_UP0=0; /delete maximun & minimunAD_UP9=0;AD_DOWN0=0;AD_DOWN9=0;for (i=0;i10;i+)AD_UP_AVE+=AD_UPi;AD_DOWN_AVE+=AD_DOWNi;AD_value = (int)(float)(AD_DOWN_AVE)-(AD_UP_AVE)/8.0);Real = AD_value/1000.0 ; /calculat
19、e Real as suspension position of the plantek = Exp - Real; /ek is suspension position errorOutput = PID(ek)+offset;DA_value = (unsigned long)(Output*65535/5.0); /convert Output to DA_value for DAC moduleDA_value = saturation(DA_value); /output saturationDAC_send(0,DA_value); /using DA to send DA_val
20、ue to DAC moduleGpioDataRegs.GPADAT.bit.GPIO12 = 0; /turn off led/ Acknowledge this interrupt to receive more interrupts from group 1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;/variables to store conversion resultsUint16 AdcaResult0;Uint16 AdcaResult1;Uint16 sdata = 0x0000; / send dataUint16 rdata; / re
21、ceived datavoid 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 G
22、PIO to its default state. InitGpio();/ InitSpiaGpio();/ 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. InitPieCtrl();/
23、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.
24、EALLOW; / This is needed to write to EALLOW protected registersPieVectTable.TIMER0_INT = &cpu_timer0_isr;EDIS; / This is needed to disable write to EALLOW protected registers / Step 4. Initialize the Device Peripheral. This function can be / found in F2837xS_CpuTimers.cInitCpuTimers(); / For this ex
25、ample, only initialize the Cpu Timers ConfigCpuTimer(&CpuTimer0, 200, 500); CpuTimer0Regs.TCR.all = 0x4000; / Use write-only instruction to set TSS bit / Step 5. User specific code, enable interrupts: / Enable TINT0 in the PIE: Group 1 interrupt 7 PieCtrlRegs.PIEIER1.bit.INTx7 = 1; /Configure the AD
26、Cs and power them upConfigureADC(); /Setup the ADCs for software conversionsSetupADCSoftware();IER |= M_INT1; / 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 loo
27、p forever (optional): while(1) /Write ADC configurations and power up the ADC for both ADC A and ADC Bvoid ConfigureADC(void)EALLOW;/write configurationsAdcaRegs.ADCCTL2.bit.PRESCALE = 6; /set ADCCLK divider to /4/AdcbRegs.ADCCTL2.bit.PRESCALE = 6; /set ADCCLK divider to /4 AdcSetMode(ADC_ADCA, ADC_
28、RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); /AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);/Set pulse positions to lateAdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;/AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;/power up the ADCsAdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;/AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;/
29、delay for 1ms to allow ADC time to power upDELAY_US(1000);EDIS;void SetupADCSoftware(void)Uint16 acqps;/determine minimum acquisition window (in SYSCLKS) based on resolutionif(ADC_RESOLUTION_12BIT = AdcaRegs.ADCCTL2.bit.RESOLUTION)acqps = 14; /75nselse /resolution is 16-bitacqps = 63; /320ns/Select
30、the channels to convert and end of conversion flag /ADCA EALLOW; AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; /SOC0 will convert pin A0 AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; /sample window is acqps + 1 SYSCLK cycles AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; /SOC1 will convert pin A1 AdcaRegs.ADCSOC1CTL.bit.ACQPS =
31、acqps; /sample window is acqps + 1 SYSCLK cycles AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; /end of SOC1 will set INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; /enable INT1 flag AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; /make sure INT1 flag is clearedvoid error(void) asm( ESTOP0);/ Test failed! Stop! for (;);