spwm单项并网的实现
并網(wǎng)問題,最近老師布置了一道并網(wǎng)的問題,博主之前也有嘗試過,不過之前做的不深。
至于這一個(gè)問題,解釋起來比較麻煩,相信做過或者了解過的人應(yīng)該知道,簡單來說,就是一個(gè)同步。
我們知道,220v 50hz的電網(wǎng)波動其實(shí)還是有的,一般認(rèn)為波動在49.5~50.5Hz左右變換,我們用變壓器變壓過來,通過一個(gè)比較器等可以整形成一個(gè)脈沖波,我們測脈沖波的頻率就可以知道此時(shí)電網(wǎng)的頻率。
提前說明
spwm說明
在實(shí)現(xiàn)spwm波形時(shí),將源建議的400個(gè)pwm改成672個(gè)pwm方便擴(kuò)展精度
當(dāng)頻率在49.5~50.5Hz變動時(shí),更改原因:
pwm初始化函數(shù)
TIM1_PWM_Out_Init(1000-1,5-1,48);TIM1時(shí)鐘為168M,對應(yīng)單個(gè)pwm頻率為168?1000000/1000/5=33.6khHz168?1000000/1000/5=33.6khHz
672個(gè)pwm波形濾波之后,可以對應(yīng)50hz正弦波波形
增加輸入頻率
增加輸入頻率,在不改變點(diǎn)數(shù)情況下
原理分析
輸入頻率增加,對應(yīng)輸入方波的周期變小,而672pwm輸出點(diǎn)數(shù)不變,勢必會造成 spwm波形被部分截取,具體是尾部截取現(xiàn)象分析
現(xiàn)象及過程·分析
隨著頻率的增加,即采樣進(jìn)來的方波信號周期變小,出現(xiàn)發(fā)波表過多,這時(shí)候,程序認(rèn)為:
- 波表數(shù)沒有發(fā)完,這時(shí)候,捕獲到上升沿標(biāo)志了,使能一次定時(shí)器溢出更新中斷(程序原設(shè)定要求)
- 當(dāng)剩余幾個(gè)波表發(fā)完成后,應(yīng)該清楚波表計(jì)數(shù),同時(shí)關(guān)閉定時(shí)器更新中斷,等待下一次捕獲到來使能更新斷
- 此時(shí),由于上升沿來之后,波表才發(fā)完,造成,下一次中斷更新在下一次上升沿來
即:下一個(gè)方波來,才會重新輸出,中間間隔段為定時(shí)器關(guān)閉情況
解決辦法:減少波表個(gè)數(shù),使上升沿來是波表剛好發(fā)完或者,在上升沿來之前把波表發(fā)完
減少輸入頻率,在不改變點(diǎn)數(shù)的情況下
原理分析
輸入頻率變小,即方波周期變大,出現(xiàn)發(fā)出672波點(diǎn)數(shù)不足的情況,會造成spwm波提早結(jié)束,具體spwm波結(jié)束有一段橫線(定時(shí)器提前關(guān)閉造成)
現(xiàn)象分析:
A:波表發(fā)送完畢,下一次捕獲還未來
B:定時(shí)器關(guān)閉,等待下一次捕獲來臨,定時(shí)器不輸出
C:下一次捕獲,上升沿到來,重新打開定時(shí)器
解決辦法:增加波表個(gè)數(shù),使波表發(fā)送完畢時(shí),下一次上升沿剛好到來
同步辦法
計(jì)算pwm個(gè)數(shù)
經(jīng)過驗(yàn)證,方便波表的選取,pwm個(gè)數(shù)為偶
ps:在一個(gè)誤差周期內(nèi),實(shí)際給出誤差以紅色為主。
程序?qū)崿F(xiàn)
void Frequency_take(void) {if(Frequency<49.5f){cnt_start=1;frequencyNum=339;}if(Frequency>=49.5f && Frequency<49.6f){cnt_start=1;frequencyNum=339;}//49.5+3補(bǔ)充if(Frequency>=49.6f && Frequency<49.7f){cnt_start=2;frequencyNum=338;}//49.6if(Frequency>=49.7f && Frequency<49.8f){cnt_start=2;frequencyNum=338;}//49.7if(Frequency>=49.8f && Frequency<49.9f){cnt_start=2;frequencyNum=337;}//49.8if(Frequency>=49.9f && Frequency<50.0f){cnt_start=3;frequencyNum=336;}//49.9if(Frequency>=50.0f && Frequency<50.1f){cnt_start=3;frequencyNum=336;}//50if(Frequency>=50.1f && Frequency<50.2f){cnt_start=4;frequencyNum=335;}//50.1if(Frequency>=50.2f && Frequency<50.3f){cnt_start=4;frequencyNum=334;}//50.2if(Frequency>=50.3f && Frequency<50.4f){cnt_start=4;frequencyNum=334;}//50.3if(Frequency>=50.4f && Frequency<50.5f){cnt_start=5;frequencyNum=333;}//50.4if(Frequency>=50.5f && Frequency<50.6f){cnt_start=4;frequencyNum=333;}//50.5if(Frequency>50.5f){cnt_start=5;frequencyNum=332;} }中斷處理部分
更改點(diǎn)數(shù)處理
void TIM1_UP_TIM10_IRQHandler(void) {if(TIM_GetITStatus(TIM1,TIM_IT_Update)==SET) {TIM3->CR1 &= (uint16_t)~TIM_CR1_CEN;if(dir_flag==1){//半波翻轉(zhuǎn)標(biāo)志位TIM1->CCR1 = arr*(0.5f+coefficient*sin_table[cnt++]);if(cnt>=frequencyNum){dir_flag=0;cnt=cnt_start;}}else{TIM1->CCR1 = arr*(0.5f-coefficient*sin_table[cnt++]);if(cnt>=frequencyNum){dir_flag=1;cnt=cnt_start;TIM_ITConfig(TIM1,TIM_IT_Update,DISABLE); GPIO_ResetBits(GPIOD,GPIO_Pin_1);}}TIM3->CR1 |= TIM_CR1_CEN; }TIM_ClearITPendingBit(TIM1,TIM_IT_Update); }程序說明
按計(jì)算,50hz對應(yīng)半波點(diǎn)數(shù)為336個(gè)點(diǎn)數(shù),人為在波表前面各加三個(gè)數(shù),將波表改成336+3+3=342個(gè)波表
double sin_table[342]={ -1.000, -1.000, -1.000, -1.000, -1.000, -1.000, -1.000, -0.999, -0.999, -0.998, -0.998, -0.997, -0.996, -0.996, -0.995, -0.994, -0.993, -0.991, -0.990, -0.989, -0.987, -0.986, -0.984, -0.983, -0.981, -0.979, -0.977, -0.975, -0.973, -0.971, -0.968, -0.966, -0.964, -0.961, -0.958, -0.956, -0.953, -0.950, -0.947, -0.944, -0.941, -0.938, -0.934, -0.931, -0.927, -0.924, -0.920, -0.917, -0.913, -0.909, -0.905, -0.901, -0.897, -0.893, -0.889, -0.884, -0.880, -0.875, -0.871, -0.866, -0.861, -0.857, -0.852, -0.847, -0.842, -0.837, -0.832, -0.826, -0.821, -0.816, -0.810, -0.805, -0.799, -0.793, -0.788, -0.782, -0.776, -0.770, -0.764, -0.758, -0.752, -0.746, -0.739, -0.733, -0.727, -0.720, -0.714, -0.707, -0.701, -0.694, -0.687, -0.680, -0.673, -0.666, -0.659, -0.652, -0.645, -0.638, -0.631, -0.624, -0.616, -0.609, -0.601, -0.594, -0.586, -0.579, -0.571, -0.563, -0.556, -0.548, -0.540, -0.532, -0.524, -0.516, -0.508, -0.500, -0.492, -0.484, -0.476, -0.467, -0.459, -0.451, -0.442, -0.434, -0.426, -0.417, -0.409, -0.400, -0.391, -0.383, -0.374, -0.365, -0.357, -0.348, -0.339, -0.330, -0.322, -0.313, -0.304, -0.295, -0.286, -0.277, -0.268, -0.259, -0.250, -0.241, -0.232, -0.223, -0.214, -0.204, -0.195, -0.186, -0.177, -0.168, -0.158, -0.149, -0.140, -0.131, -0.121, -0.112, -0.103, -0.094, -0.084, -0.075, -0.066, -0.056, -0.047, -0.038, -0.028, -0.019, -0.009, -0.000, 0.009, 0.019, 0.028, 0.037, 0.047, 0.056, 0.065, 0.075, 0.084, 0.093, 0.103, 0.112, 0.121, 0.130, 0.140, 0.149, 0.158, 0.167, 0.177, 0.186, 0.195, 0.204, 0.213, 0.222, 0.231, 0.241, 0.250, 0.259, 0.268, 0.277, 0.286, 0.295, 0.304, 0.312, 0.321, 0.330, 0.339, 0.348, 0.356, 0.365, 0.374, 0.383, 0.391, 0.400, 0.408, 0.417, 0.425, 0.434, 0.442, 0.451, 0.459, 0.467, 0.475, 0.484, 0.492, 0.500, 0.508, 0.516, 0.524, 0.532, 0.540, 0.548, 0.555, 0.563, 0.571, 0.579, 0.586, 0.594, 0.601, 0.609, 0.616, 0.623, 0.631, 0.638, 0.645, 0.652, 0.659, 0.666, 0.673, 0.680, 0.687, 0.694, 0.700, 0.707, 0.714, 0.720, 0.727, 0.733, 0.739, 0.746, 0.752, 0.758, 0.764, 0.770, 0.776, 0.782, 0.788, 0.793, 0.799, 0.805, 0.810, 0.815, 0.821, 0.826, 0.831, 0.837, 0.842, 0.847, 0.852, 0.856, 0.861, 0.866, 0.871, 0.875, 0.880, 0.884, 0.888, 0.893, 0.897, 0.901, 0.905, 0.909, 0.913, 0.917, 0.920, 0.924, 0.927, 0.931, 0.934, 0.937, 0.941, 0.944, 0.947, 0.950, 0.953, 0.956, 0.958, 0.961, 0.963, 0.966, 0.968, 0.971, 0.973, 0.975, 0.977, 0.979, 0.981, 0.983, 0.984, 0.986, 0.987, 0.989, 0.990, 0.991, 0.993, 0.994, 0.995, 0.996, 0.996, 0.997, 0.998, 0.998, 0.999, 0.999, 1.000, 1.000, 1.000,1.000, 1.000, 1.000 };當(dāng)頻率改變時(shí),我們只要改變整個(gè)波表起始位置就可以.比如,當(dāng)輸入方波信號為49.5,通過計(jì)算,應(yīng)當(dāng)輸出678個(gè)pwm對應(yīng)半波339個(gè)
程序中設(shè)置cnt_start=1,frequencyNum=339,遍歷波表時(shí)從第一個(gè)數(shù)到第339個(gè)數(shù),共339個(gè)數(shù),對應(yīng)使用336個(gè)波表時(shí),我們額外補(bǔ)充的前3個(gè)數(shù)中的第2和3個(gè) -1.000 和后三個(gè)數(shù)中第一個(gè)1.000,也就是將缺少的3個(gè)pwm補(bǔ)上
同樣其他頻率變化時(shí),實(shí)現(xiàn)同步。
總結(jié)
以上是生活随笔為你收集整理的spwm单项并网的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 企业视频制作的多媒体软件
- 下一篇: USB-C显示器专用的PD协议芯片,LD