3, 软件实现
由于PSoC3的强大可编程硬件资源,软件工作就变得相当简单,因此主程序的软件工作只需要启动片上各个模块的即可。所以在软件实现中只要做好步进电机的细分控制即可。在本方案中,细分控制采用的是预先建立好正弦波形数组,再通过CPU将该数组分时写进PSoC3的DAC中以输出正弦波形。基数设置为16,则产生的阶梯波形如图5所示,我们称之为8微步实现。
static unsigned char SinTable[] = {
255,255,255,255,255,254,254,254,253,253,
253,252,252,251,251,250,249,249,248,247,
247,246,245,244,243,242,241,240,239,238,
237,236,234,233,232,231,229,228,226,225,
223,222,220,219,217,215,214,212,210,208,
207,205,203,201,199,197,195,193,191,189,
187,185,183,180,178,176,174,171,169,167,
164,162,159,157,154,152,149,147,144,142,
139,136,134,131,128,126,123,120,117,115,
112,109,106,103,100,98,95,92,89,86,
83,80,77,74,71,68,65,62,59,56,
53,50,47,44,41,37,34,31,28,25,
22,19,16,13,9,6,3,0
};
|