基于ADuC7026的磁浮小球控制系统软件设计
0赞
发表于 6/7/2012 6:57:21 PM
阅读(3889)
本系统采用PID控制,利用C语言编写PID算法程序,借助ADuC7026模拟微控制器实现控制器的控制作用。



附录:
1-数据采集接口ADC
#include <ADuC7026.h> // Include ADuC7026 Header File
void IRQ_Handler(void) __irq; // IRQ Funtion Prototype
void ADCpoweron(int);
void delay(int);
int main (void) {
ADCpoweron(20000); // power on ADC
ADCCP = 0x00;
ADCCON = 0x6E2; // start conversion on timer 0
REFCON = 0x01; // connect internal 2.5V reference to VREF pin
GP1CON = 0x011; // Setup tx & rx pins on P1.0 and P1.1
// Setting up UART at 9600bps (CD=0)
COMCON0 = 0x80; // Setting DLAB
COMDIV0 = 0x88;
COMDIV1 = 0x00;
COMCON0 = 0x07; // Clearing DLAB
// for test purposes only
GP0CON = 0x10100000; // enable ECLK output on P0.7, and ADCbusy on P0.5
IRQEN = ADC_BIT; // Enable ADC IRQ ( 0x80 )
// timer0 configuration
T0LD = 1000; // 23.4us
T0CON = 0xC0; // count down
// periodic mode
GP4DAT = 0x04000000; // Configure P4.2 as output
while(1)
{
}
return 0 ;
}
/********************************************************************/
/* */
/* Interrupt Service Rountine */
/* */
/********************************************************************/
void IRQ_Handler() __irq
{
GP4DAT ^= 0x00040000; // Complement P4.2
ADCCP ^= 1; // change channel
senddata (ADCDAT >> 16);
return ;
}
2-驱动信号产生DAC
#include<ADuC7026.h>
int main (void) {
int i = 0;
// DAC configuration
DAC1CON = 0x13; // DAC configuration
// range AVdd/AGND
// DAC1 is updated with falling edge of core clock
DAC1DAT = 0x08000000; // start from midscale
while(1){
DAC1DAT = Rcmd;
}
return (0);
}
