该程序是基于stm32的spwm波形生成,可以应用于dc-ac逆变电路驱动程序。
单片机源程序如下:
- #include "delay.h"
- #include "sys.h"
- #include "key.h"
- #include "adc.h"
- #include "time.h"
- #include "spwm.h"
- #include "usart.h"
- ////////////主程序变量
- char key; //键盘输入
- unsigned int spwmval;
- u16 HZ=50;
- u8 sflag;
- u16 adcx0, adcx1, adcx2 ; //三路ad采样
- ////////串口变量
- int len;
- int pwmx;
- void Usart_Cmd(void);
- int main(void)
- {
- delay_init( ); //延时函数初始化
-
- NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2 ); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
-
- Adc_Init( );
- //button_Init( ); //按键初始化
- //TIM1_PWM_Init( 464 , 0 ); //TIM1 PWM初始化, Fpwm=72M/4096=17.518125Khz
- SPWM_Init(516,1);
- TIM2_Int_Init(1024,2);
- //uart_init(115200);
-
- while( 1 )
- {
- delay_ms(300);
- }
- }
复制代码
Keil代码下载:
spwm调试.rar
(324.22 KB, 下载次数: 328)
|