论坛元老
- 积分
- 10652
- 金钱
- 10652
- 注册时间
- 2017-4-14
- 在线时间
- 2780 小时
|
本帖最后由 nashui_sx 于 2019-8-5 13:26 编辑
0.stm32f103c8t6 PA6输出波形
1.正弦波序列自动生成- //产生正弦波函序列
- void TIM3_Spwm_Creat_Buf(void)
- {
- u32 i;
- float inc=2*PI/TIM3_Spwm_Buf_Size; //计算增量
- for(i=0;i<TIM3_Spwm_Buf_Size;i++)
- {
- TIM3_Spwm_Buf[i]=(u16)(TIM3_Spwm_Buf_Zhouqi/2*(1+sin(inc*i))+0.5); //得到一个0-TIM3_Spwm_Buf_Zhouqi的正弦波控制spwm +0.5是为了最大值能够达到TIM3_Spwm_Buf_Zhouqi 最小能到0
- printf("%d\r\n",TIM3_Spwm_Buf[i]);
- }
- }
复制代码
2.pwm周期+spwm点数控制spwm周期
- #define TIM3_Spwm_Buf_Size 100 //pwm周期*spwm点数=TIM3_Spwm_Buf_Zhouqi*TIM3_Spwm_Buf_Size=spwm周期
- //TIM3_Spwm_Init(TIM3_Spwm_Buf_Zhouqi-1,71);
- //spwm周期=1000*72/72000000*100=100ms
- #define TIM3_Spwm_Buf_Zhouqi 1000 //pwm周期控制 psc TIM_Prescaler =71时候代表1000us
复制代码
3.为了输出可控spwm周期数(整周期)开启了dma完成中断 中断内统计周期个数,个数到了关闭定时器输出pwm 需要一直输出的,可以删掉中断相关代码
4.测试如下- TIM3_Spwm_Out(TIM3_Spwm_Buf_Zhouqi-1,71,2);//spwm周期=1000*72/72000000*100=100ms 2个spwm周期
复制代码
5.源码(注意 例子是产生两个周期,测量的时候:下载完成--按住复位--开示波器或者逻辑分析仪+松复位抓数据;不然运行一会两个周期过了,肯定没波形 或者自己改输出多点周期)
spwm dma 可控pwm周期,SPWM周期及个数.rar
(286.6 KB, 下载次数: 1011)
|
|