在脈沖模式下,步進電機啟動器的脈沖頻率與速度成正比,函數(shù)void CalculateSModelLine(float fre[], unsigned short period[], float len, float fre_max, float fre_min, float flexible)主要目的就是生成每一個細分步加速的速度。芯片用的是stm32f103c8t6,驅(qū)動器用的是2DM420。
程序流程如下:
- STM32硬件基本初始化,主要是針對定時器
- 調(diào)用函數(shù)CalculateSModelLine()生 成每一個細分步定時器的自動重裝載值(實際就是改變脈沖的周期)
- 打開定時器
- 更新中斷發(fā)生,將數(shù)組中的數(shù)據(jù)賦值給定時器的自動重裝載寄存器
- 跳出中斷后脈沖頻頻率就變化了
- 下一次更新中斷產(chǎn)生
對應(yīng)的計算接口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
-
驅(qū)動
+關(guān)注
關(guān)注
12文章
1942瀏覽量
88491 -
STM32
+關(guān)注
關(guān)注
2308文章
11160瀏覽量
373208 -
步進電機
+關(guān)注
關(guān)注
153文章
3237瀏覽量
152210
發(fā)布評論請先 登錄
DRV8825步進電機控制器IC:設(shè)計與應(yīng)用詳解
DRV8884步進電機驅(qū)動器:特性、應(yīng)用與設(shè)計要點
德州儀器DRV8436步進電機驅(qū)動器:特性、應(yīng)用與設(shè)計深度解析
DRV8424/25步進驅(qū)動器:創(chuàng)新科技助力電機控制
DRV8434步進電機驅(qū)動器:高效集成與智能控制的完美結(jié)合
德州儀器DRV8428步進電機驅(qū)動器:功能特點與應(yīng)用指南
深入剖析DRV8424/25步進電機驅(qū)動器:特性、應(yīng)用與設(shè)計指南
EVL6470步進電機驅(qū)動評估板技術(shù)解析與應(yīng)用指南
關(guān)于TMC2208與TMC2209的區(qū)別及基于STM32F103控制TMC2209模塊驅(qū)動2相4線步進電機
Analog Devices / Maxim Integrated MAX22204步進電機驅(qū)動器數(shù)據(jù)手冊
Analog Devices / Maxim Integrated MAX22210步進電機驅(qū)動器數(shù)據(jù)手冊
STM32步進電機驅(qū)動的算法
評論