在脉冲模式下,步进电机启动器的脉冲频率与速度成正比,函数void CalculateSModelLine(float fre[], unsigned short period[], float len, float fre_max, float fre_min, float flexible)主要目的就是生成每一个细分步加速的速度。芯片用的是stm32f103c8t6,驱动器用的是2DM420。
程序流程如下:
- STM32硬件基本初始化,主要是针对定时器
- 调用函数CalculateSModelLine()生 成每一个细分步定时器的自动重装载值(实际就是改变脉冲的周期)
- 打开定时器
- 更新中断发生,将数组中的数据赋值给定时器的自动重装载寄存器
- 跳出中断后脉冲频频率就变化了
- 下一次更新中断产生
对应的计算接口code:
/* calculate the Period and Freq array value, fill the Period value into the Period register during the timer interrupt.
*calculate the acceleration procedure , a totally 1000 elements array.
* parameter fre[]: point to the array that keeps the freq value.
* period[]: point to the array that keeps the timer period value.
* len: the procedure of acceleration length.it is best thing to set the float number, some compile software maybe transfer error if set it as a int
* fre_max: maximum speed, frequency vale.
* fre_min: start minimum speed, frequency vale. mind : 10000000/65535 = 152, so fre_min can't less than 152.
* flexible: flexible value. adjust the S curves
*/
void CalculateSModelLine(float fre[], unsigned short period[], float len, float fre_max, float fre_min, float flexible)
{
int i=0;
float deno ;
float melo ;
float delt = fre_max-fre_min;
for(; i
{
melo = flexible * (i-len/2) / (len/2);
deno = 1.0 / (1 + expf(-melo)); //expf is a library function of exponential(e)
fre[i] = delt * deno + fre_min;
period[i] = (unsigned short)(10000000.0 / fre[i]); // 10000000 is the timer driver frequency
}
return ;
}
文章整合自:CSDN
编辑:ymf
-
驱动器
+关注
关注
53文章
8302浏览量
147235 -
步进电机
+关注
关注
152文章
3121浏览量
147943 -
脉冲模式
+关注
关注
0文章
3浏览量
6462
发布评论请先 登录
相关推荐
基于STM32F405RGT6的TMC2660步进电机驱动器,附带原理图+PCB
![基于<b class='flag-5'>STM32</b>F405RGT6的TMC2660<b class='flag-5'>步进</b><b class='flag-5'>电机</b><b class='flag-5'>驱动</b>器,附带原理图+PCB](https://file1.elecfans.com//web3/M00/02/57/wKgZPGddaw6Af1tDAAP7MKoqhN0580.jpg)
步进电机驱动器的主要驱动方式有哪些?简单介绍
75FB003步进电机有几种方法
求助,关于STM32F030进行步进电机控制问题求解
步进电机如何让动起来?步进电机转动原理
![<b class='flag-5'>步进</b><b class='flag-5'>电机</b>如何让动起来?<b class='flag-5'>步进</b><b class='flag-5'>电机</b>转动原理](https://file1.elecfans.com/web2/M00/C7/61/wKgaomYKHzyAGfCSAABSVwV4ANw745.png)
评论