完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我自己有原理图的,但我搞不清楚这个程序哪里错了,还是根本就不对,求大神指点一二。 #include "msp430x16x.h" #include "IO_init.h" #include "timerB_function.c" #include "ADC_function.c" //#include "Externalsignal_function.c" #define SD_ACTIVE P3OUT &= ~BIT0; // pin SD=1 #define SD_RESET P3OUT |= BIT0; #define FLTCLR_ACTIVE P3OUT |= BIT1; // pin CLT_CLR=0 #define FLTCLR_RESET P3OUT &= ~BIT1; unsigned int FLAG_FAULT = 0; void main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; unsigned int i=0; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; BCSCTL1 &= ~XT2OFF; //开启XT2 ACLK=32.678kHz do{ IFG1 &= ~OFIFG; //清楚振荡器失效标志 for(i=0xff;i>0;i--) ; //延时,等待稳定 }while( (IFG1&OFIFG)!=0 ); //若振荡器失效标志有效,则一直循环直到起振成功 BCSCTL2 = SELM_2 + DIVM_0 + SELS + DIVS_0; //时钟 MCLK=SMCLK=XT2(8MHz) 内部电阻 for(i=100;i>0;i--) ; WDTCTL = WDT_ARST_250; // WDT寄存器设置 WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- _DINT(); sys_init(); WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- SD_RESET; delay(2); FLTCLR_ACTIVE; delay(2); FLTCLR_RESET; delay(2); WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- //上电首次直流侧270V过电压检测 DClink = OverVoltage_270V_detect(); while( DClink>DC270V_MAX ){ SD_ACTIVE; //发送shutdowm信号至IR2133 并反馈系统故障信号 if( P3OUT&BIT0 == 0x00 ){ sent_SysERROR_feedback(); } else{ clr_SysERROR_feedback(); } } //等待外部启动信号有效 External_START(); //上电首次检测冷却液液体温度,如果小于-10℃,则执行方波模式。 tmp = Temperature_detect(); if( tmp < Temperatuer_minus10 ){ FLAG_sqaurePWM = 1;} else{ FLAG_sqaurePWM = 0; } WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- //如果方波模式则初始化方波并启动,否则初始化SVPWM并启动 if( FLAG_sqaurePWM==1 ){ TimerB_init_squarewave(); } else{ TimerB_init_SVPWM(); } SD_RESET; delay(2); FLTCLR_ACTIVE; delay(2); FLTCLR_RESET; delay(2); _EINT(); WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- if( FLAG_sqaurePWM==1 ){ TimerB_start_squarewave(); } else{ TimerB_start_SVPWM(); } WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- SD_RESET; delay(2); FLTCLR_ACTIVE; delay(2); FLTCLR_RESET; delay(2); WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- while(1) { WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- tmp = Temperature_detect(); DClink = OverVoltage_270V_detect(); while( DClink>DC270V_MAX ){ SD_ACTIVE; //发送shutdowm信号至IR2133 并反馈系统故障信号 if( P3OUT&BIT0 == 0x00 ){ sent_SysERROR_feedback(); } else{ clr_SysERROR_feedback(); } } WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- //软件施密特迟滞回门特性 门宽为5℃ //当冷却液液体温度低于-10℃时,由SVPWM调制切换至方波控制模式 //当冷却液液体温度回升至-5℃以上时,由方波控制切换至SVPWM调制模式 if( tmp SD_RESET; delay(2); FLTCLR_ACTIVE; delay(2); FLTCLR_RESET; delay(2); WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- TimerB_stop_SVPWM(); TimerB_init_squarewave(); TimerB_start_squarewave(); FLAG_sqaurePWM = 1 ; WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- } if( tmp>Temperatuer_minus5 && FLAG_sqaurePWM==1){ SD_RESET; delay(2); FLTCLR_ACTIVE; delay(2); FLTCLR_RESET; delay(2); WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- TimerB_stops_quarewave(); TimerB_init_SVPWM(); TimerB_start_SVPWM(); FLAG_sqaurePWM = 0 ; WDTCTL = WDTPW + WDTCNTCL; //-------------- 喂狗 ------------- } } } ② IO_init.h文件程序代码: /************************* 上电默认设置6个IO端口为 普通IO、输出、低电平 、清零IFG 、上升沿触发 、禁止外部中断请求 *************************/ void P1_init( void ){ P1DIR = 0x6f;//输出 ~~~~~~~~~~~~~~~~~~~~~~ P1OUT = 0x00;//输出低电平 P1IFG = 0x00;//无中断请求标志 P1IES = 0x00;//上升沿触发(如果外部中断允许) P1IE = 0x00;//禁止外部中断允许 P1SEL = 0x00;//普通IO功能 } void P2_init( void ){ P2DIR = 0xff;//输出 P2OUT = 0x00;//输出低电平 P2IFG = 0x00;//无中断请求标志 P2IES = 0x00;//上升沿触发(如果外部中断允许) P2IE = 0x00;//禁止外部中断允许 P2SEL = 0x00;//普通IO功能 } void P3_init( void ){ P3DIR = 0xfb;//输出 P3OUT = 0x00;//输出低电平 P3SEL = 0x00;//普通IO功能 } void P4_init( void ){ P4DIR = 0xff;//输出 P4OUT = 0x00;//输出低电平 P4SEL = 0x00;//普通IO功能 } void P5_init( void ){ P5DIR = 0xff;//输出 P5OUT = 0x00;//输出低电平 P5SEL = 0x00;//普通IO功能 } void P6_init( void ){ P6DIR = 0xff;//输出 P6OUT = 0x00;//输出低电平 P6SEL = 0x00;//普通IO功能 } void VSI_IOinit( void ){ //设定P1_5为输入、IO。用于外部启动,高电平有效。 测试时默认接收低电平。 P1DIR &= ~BIT5;//P1DIR.5 = 0 输入 //设置P1_6为输出、IO。用于VSI故障反馈,高电平输出反馈信号 P1DIR |= BIT6;//设置P1_6为输出IO P2OUT &= ~BIT6;//默认为无反馈信号的低电平 } void ADC12_init( void ){ //A3~A7设置为模拟ADC输入功能 P6DIR &= ~BIT3; P6DIR &= ~BIT4; P6DIR &= ~BIT5; P6DIR &= ~BIT6; P6DIR &= ~BIT7; P6SEL |= BIT3; P6SEL |= BIT4; P6SEL |= BIT5; P6SEL |= BIT6; P6SEL |= BIT7; ADC12CTL0 &=~(ENC); //单通道单次转换、采样定时器4分频、不采用内部电压基准、禁闭中断使能、开启ADC内核 ADC12CTL0 = 0 ; ADC12CTL0 |= SHT0_2 + ADC12ON ; //使用采样定时器、信号不反相、ADC_CLK不分频、MCLK(8MHz)、单通道单次转换、BUSY位清零 ADC12CTL1 = 0 ; ADC12CTL1 |= SHP + ADC12SSEL_2; ADC12IFG = 0; ADC12IE = 0; ADC12IV = 0; } void sys_init( void ){ P1_init(); P2_init(); P3_init(); P4_init(); P5_init(); P6_init(); VSI_IOinit(); //TimerB_init(); ADC12_init(); //stop_TimerB(); } 附录6 SVPWM脉冲参数计算器截图及其代码 ① 编程截图 ② 主要程序Visual Basic代码: Private Sub Command1_Click() Dim timer_clk As Double Dim Ts As Double Dim f_out As Double Dim ModulationDepth As Double Const PI = 3.141592654 Const PARA = 0.866025403 Dim TBCCR0 As Integer Dim Dimension As Integer Dim SVcounter As Integer Dim SV_T1 As Double Dim SV_T2 As Double Dim SV_T0 As Double TBCCR0 = 0 Dimension = 0 SVcounter = 0 SV_T1 = 0 SV_T2 = 0 SV_T0 = 0 timer_clk = Val(Text1.Text) Ts = Val(Text2.Text) f_out = Val(Text3.Text) ModulationDepth = Val(Text4.Text) Text5.Text = "" '计算TBCCR0 TBCCR0 = 0.5 * 1000 * timer_clk / Ts '计算数组长度 Dimension = 1000 * Ts / f_out '显示参数资信 Text5.FontBold = False Text5.FontSize = 10 Text5.Text = "The results are :" & vbCrLf Text5.Text = Text5.Text + " TBCCR0 = " & Str(TBCCR0) & vbCrLf Text5.Text = Text5.Text + " the length of array = " & Str(Dimension) & vbCrLf & vbCrLf Text5.Text = Text5.Text + "With following conditions: " & vbCrLf Text5.Text = Text5.Text + " Timer clock = " & Str(timer_clk) & " MHz;" & vbCrLf Text5.Text = Text5.Text + " the frequency of each pulse circle = " & Str(Ts) & " kHz" & vbCrLf Text5.Text = Text5.Text + " the frequency of output = " & Str(f_out) & " Hz" & vbCrLf Text5.Text = Text5.Text + " the modulation depth = " & Format(Str(ModulationDepth), "0.000") & vbCrLf & vbCrLf Text5.Text = Text5.Text + "The arrays are :" & vbCrLf Dim SV_cmp1() As Double Dim SV_cmp2() As Double Dim SV_cmp3() As Double Dim SV_PHA() As Integer Dim SV_PHB() As Integer Dim SV_PHC() As Integer ReDim SV_cmp1(Dimension) ReDim SV_cmp2(Dimension) ReDim SV_cmp3(Dimension) ReDim SV_PHA(Dimension) ReDim SV_PHB(Dimension) ReDim SV_PHC(Dimension) For SVcounter = 0 To Dimension - 1 Step 1 '第一扇区 If SVcounter <= (Dimension * 1 / 6 - 1) And SVcounter >= 0 Then SV_T1 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 1 / 6) SV_T2 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 9 / 6) SV_T0 = (1 - SV_T1 - SV_T2) / 2 SV_cmp1(SVcounter) = SV_T1 + SV_T2 + SV_T0 SV_cmp2(SVcounter) = SV_T2 + SV_T0 SV_cmp3(SVcounter) = SV_T0 SV_PHA(SVcounter) = Int((1 - SV_cmp1(SVcounter)) * TBCCR0 + 0.5) SV_PHB(SVcounter) = Int((1 - SV_cmp2(SVcounter)) * TBCCR0 + 0.5) SV_PHC(SVcounter) = Int((1 - SV_cmp3(SVcounter)) * TBCCR0 + 0.5) End If '第二扇区 If SVcounter <= (Dimension * 2 / 6 - 1) And SVcounter >= (Dimension * 1 / 6) Then SV_T1 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 11 / 6) SV_T2 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 7 / 6) SV_T0 = (1 - SV_T1 - SV_T2) / 2 SV_cmp1(SVcounter) = SV_T1 + SV_T0 SV_cmp2(SVcounter) = SV_T1 + SV_T2 + SV_T0 SV_cmp3(SVcounter) = SV_T0 SV_PHA(SVcounter) = Int((1 - SV_cmp1(SVcounter)) * TBCCR0 + 0.5) SV_PHB(SVcounter) = Int((1 - SV_cmp2(SVcounter)) * TBCCR0 + 0.5) SV_PHC(SVcounter) = Int((1 - SV_cmp3(SVcounter)) * TBCCR0 + 0.5) End If '第三扇区 If SVcounter <= (Dimension * 3 / 6 - 1) And SVcounter >= (Dimension * 2 / 6) Then SV_T1 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 9 / 6) SV_T2 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 5 / 6) SV_T0 = (1 - SV_T1 - SV_T2) / 2 SV_cmp1(SVcounter) = SV_T0 SV_cmp2(SVcounter) = SV_T1 + SV_T2 + SV_T0 SV_cmp3(SVcounter) = SV_T2 + SV_T0 SV_PHA(SVcounter) = Int((1 - SV_cmp1(SVcounter)) * TBCCR0 + 0.5) SV_PHB(SVcounter) = Int((1 - SV_cmp2(SVcounter)) * TBCCR0 + 0.5) SV_PHC(SVcounter) = Int((1 - SV_cmp3(SVcounter)) * TBCCR0 + 0.5) End If '第四扇区 If SVcounter <= (Dimension * 4 / 6 - 1) And SVcounter >= (Dimension * 3 / 6) Then SV_T1 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 7 / 6) SV_T2 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 3 / 6) SV_T0 = (1 - SV_T1 - SV_T2) / 2 SV_cmp1(SVcounter) = SV_T0 SV_cmp2(SVcounter) = SV_T1 + SV_T0 SV_cmp3(SVcounter) = SV_T1 + SV_T2 + SV_T0 SV_PHA(SVcounter) = Int((1 - SV_cmp1(SVcounter)) * TBCCR0 + 0.5) SV_PHB(SVcounter) = Int((1 - SV_cmp2(SVcounter)) * TBCCR0 + 0.5) SV_PHC(SVcounter) = Int((1 - SV_cmp3(SVcounter)) * TBCCR0 + 0.5) End If '第五扇区 If SVcounter <= (Dimension * 5 / 6 - 1) And SVcounter >= (Dimension * 4 / 6) Then SV_T1 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 5 / 6) SV_T2 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 1 / 6) SV_T0 = (1 - SV_T1 - SV_T2) / 2 SV_cmp1(SVcounter) = SV_T2 + SV_T0 SV_cmp2(SVcounter) = SV_T0 SV_cmp3(SVcounter) = SV_T1 + SV_T2 + SV_T0 SV_PHA(SVcounter) = Int((1 - SV_cmp1(SVcounter)) * TBCCR0 + 0.5) SV_PHB(SVcounter) = Int((1 - SV_cmp2(SVcounter)) * TBCCR0 + 0.5) SV_PHC(SVcounter) = Int((1 - SV_cmp3(SVcounter)) * TBCCR0 + 0.5) End If '第六扇区 If SVcounter <= (Dimension * 6 / 6 - 1) And SVcounter >= (Dimension * 5 / 6) Then SV_T1 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 3 / 6) SV_T2 = PARA * ModulationDepth * Cos(2 * PI * (SVcounter / Dimension) + PI * 11 / 6) SV_T0 = (1 - SV_T1 - SV_T2) / 2 SV_cmp1(SVcounter) = SV_T1 + SV_T2 + SV_T0 SV_cmp2(SVcounter) = SV_T0 SV_cmp3(SVcounter) = SV_T1 + SV_T0 SV_PHA(SVcounter) = Int((1 - SV_cmp1(SVcounter)) * TBCCR0 + 0.5) SV_PHB(SVcounter) = Int((1 - SV_cmp2(SVcounter)) * TBCCR0 + 0.5) SV_PHC(SVcounter) = Int((1 - SV_cmp3(SVcounter)) * TBCCR0 + 0.5) End If Next SVcounter Text5.Text = Text5.Text & "unsigned int TB_CCR_A[" & Str(Dimension) & " ] ={" & vbCrLf For SVcounter = 0 To Dimension - 1 Step 1 Text5.Text = Text5.Text & Str(SV_PHA(SVcounter)) & "," If SVcounter Mod 10 = 9 Then Text5.Text = Text5.Text & vbCrLf End If Next SVcounter Text5.Text = Text5.Text & "};" & vbCrLf Text5.Text = Text5.Text & "unsigned int TB_CCR_B[" & Str(Dimension) & " ] ={" & vbCrLf For SVcounter = 0 To Dimension - 1 Step 1 Text5.Text = Text5.Text & Str(SV_PHB(SVcounter)) & "," If SVcounter Mod 10 = 9 Then Text5.Text = Text5.Text & vbCrLf End If Next SVcounter Text5.Text = Text5.Text & "};" & vbCrLf Text5.Text = Text5.Text & "unsigned int TB_CCR_C[" & Str(Dimension) & " ] ={" & vbCrLf For SVcounter = 0 To Dimension - 1 Step 1 Text5.Text = Text5.Text & Str(SV_PHC(SVcounter)) & "," If SVcounter Mod 10 = 9 Then Text5.Text = Text5.Text & vbCrLf End If Next SVcounter Text5.Text = Text5.Text & "};" & vbCrLf End Sub Private Sub Command2_Click() Open "SVresult.txt" For Output As #1 Print #1, Text5.Text Close #1 End Sub Private Sub Text1_Change() End Sub Private Sub Timer1_Timer() Cls Label9.Caption = Now End Sub Private Sub Form_Load() SkinH_Attach Timer1.Interval = 500 Timer1.Enabled = True Label9.Caption = Now End Sub |
|
相关推荐 |
|
只有小组成员才能发言,加入小组>>
3039个成员聚集在这个小组
加入小组2938 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3615 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2350 浏览 1 评论
4813 浏览 1 评论
2579 浏览 1 评论
1335浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3616浏览 2评论
2938浏览 1评论
1524浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-3 18:34 , Processed in 1.407126 second(s), Total 53, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号