|
本帖最后由 qaya 于 2018-4-24 08:44 编辑
在论坛学习了这么久,无以回报,把自己的一个雕虫小技发上来给大家参考,做成PDF方便下载。
补充一下,楼下有朋友问到S曲线,这里加上一段求S曲线的代码。代码是从其他地方拷贝来的,已经不记得来源了,这里对作者表示感谢。
/* 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<len; i++)
{
melo = flexible * (i-len/2) / (len/2);
deno = 1.0 / (1 + expf(-melo)); //expf is a library function of exponential(e)
fre = delt * deno + fre_min;
period = (unsigned short)(10000000.0 / fre); // 10000000 is the timer driver frequency
}
return ;
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|