西莫电机圈

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

查看: 2929|回复: 3

[求助] st2.0电机库时钟配置触发输出问题

[复制链接]

该用户从未签到

发表于 2015-4-13 12:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我现在在改写st2.0电机库,为什么配置时钟的触发输出库里是TIM_SelectOutputTrigger(TIMER_NUM, TIM_TRGOSource_Update);
更新触发
按手册上写应该是采用CC4通道比较匹配触发TIM_SelectOutputTrigger(TIMER_NUM, TIM_TRGOSource_OC4Ref);才对的吧
但是我改成TIM_TRGOSource_OC4Ref的时候尽然触发不了
不改的话,ADC触发无论是配置为ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_TRGO);
还是ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4);
都是在更新事件的时候才触发的,我通过量PWM波形看到上桥PWM都是在高电平中点,不是在低电平中点,请教各位有谁知道?
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过

该用户从未签到

 楼主| 发表于 2015-4-13 12:53 | 显示全部楼层
TIM配置代码如下:
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
       
//#if DRIVE_AUTO_OUTPUT_LOW_SIDE <= 0
//    TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
//#endif       

    TIM1_RCC_Configuration();
    TIM1_GPIO_Configuration();
       
    /* Time Base configuration */
                TIM_DeInit(TIMER_NUM);       
                TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
    TIM_TimeBaseStructure.TIM_Prescaler = PWM_PRSC;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;
    TIM_TimeBaseStructure.TIM_Period = PWM_PERIOD-1;
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2;
    TIM_TimeBaseStructure.TIM_RepetitionCounter = REP_RATE;
    TIM_TimeBaseInit(TIMER_NUM, &TIM_TimeBaseStructure);
               
    /* Channel 1 Configuration in PWM mode */
                TIM_OCStructInit(&TIM_OCInitStructure);
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
               
#if PMOS_ON_HIGH_SIDE > 0
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
                TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
#else
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
                TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
#endif
   

#if DRIVE_AUTO_OUTPUT_LOW_SIDE <= 0
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
#else
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;               
#endif       

                TIM_OCInitStructure.TIM_Pulse = 0;
    TIM_OC1Init(TIMER_NUM, &TIM_OCInitStructure);
                TIM_OCInitStructure.TIM_Pulse = 0;
    TIM_OC2Init(TIMER_NUM, &TIM_OCInitStructure);
                TIM_OCInitStructure.TIM_Pulse = 0;
    TIM_OC3Init(TIMER_NUM, &TIM_OCInitStructure);
               
                /* Channel 4 Configuration in OC */
                TIM_OCStructInit(&TIM_OCInitStructure);
                TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;   //oí1.2.3í¨μàμ&#196;PWM1&#196;£ê&#189;&#213;yo&#195;&#207;à·′£&#172;2&#206;&#191;&#188;
                                                                                                                                //        TIM1_CCMR1&#188;&#196;′&#230;&#198;÷μ&#196;4-6&#206;&#187;&#161;£       
                TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;     ////CCR4 &#213;a&#184;&#246;±&#216;D&#235;ê&#228;3&#246;ê1&#196;üoó2&#197;&#196;ü′¥·¢ADC1μ&#196;×¢è&#235;í¨μà2é&#209;ù
                TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;   //  TIM_OutputState_Enable            
                TIM_OCInitStructure.TIM_Pulse = PWM_PERIOD -1;//2*PWM_PERIOD -20 - 30; //20&#206;aμ&#231;á÷2é&#209;ùê±&#188;&#228; 30&#206;a±£&#214;¤2é&#209;ùê±&#191;ì&#212;útim &#184;üD&#194;ê&#194;&#188;t2úéú&#214;&#174;&#199;°
               
                TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
                TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;         
                TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
                TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;      
               
                TIM_OC4Init(TIMER_NUM, &TIM_OCInitStructure);
               
                /* Enables the TIM1 Preload on CC1 Register */
                TIM_OC1PreloadConfig(TIMER_NUM, TIM_OCPreload_Enable);  //&#198;&#244;ó&#195;±è&#189;&#207;&#198;÷μ&#196;ó°×ó&#188;&#196;′&#230;&#198;÷£¨&#214;±μ&#189;2úéú&#184;üD&#194;ê&#194;&#188;t2&#197;&#184;ü&#184;&#196;éè&#214;&#195;£&#169;
                /* Enables the TIM1 Preload on CC2 Register */
                TIM_OC2PreloadConfig(TIMER_NUM, TIM_OCPreload_Enable);
                /* Enables the TIM1 Preload on CC3 Register */
                TIM_OC3PreloadConfig(TIMER_NUM, TIM_OCPreload_Enable);
                /* Enables the TIM1 Preload on CC4 Register */
                TIM_OC4PreloadConfig(TIMER_NUM, TIM_OCPreload_Enable);
               
//#if DRIVE_AUTO_OUTPUT_LOW_SIDE <= 0
    /* Automatic Output enable, Break, dead time and lock configuration*/
    TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;  //TIM_OSSRState_Enable  TIM_OSSIState_Disable
    TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSRState_Enable;
    TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
    TIM_BDTRInitStructure.TIM_DeadTime  = TIMER_DeadTime_Value;//64;
    TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
    TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
    TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
    TIM_BDTRConfig(TIMER_NUM, &TIM_BDTRInitStructure);
//#endif       

                TIM_SelectOutputTrigger(TIMER_NUM, TIM_TRGOSource_Update); //&#209;&#161;&#212;&#241;TIM1′¥·¢&#198;÷ê&#228;3&#246;&#196;£ê&#189;
//                TIM_SelectOutputTrigger(TIMER_NUM, TIM_TRGOSource_OC4Ref); //&#209;&#161;&#212;&#241;TIM1′¥·¢&#198;÷ê&#228;3&#246;&#196;£ê&#189;
               
//                TIM_ClearITPendingBit(TIMER_NUM, TIM_IT_Break);//&#199;&#229;3t&#189;&#244;&#188;±é23μ&#214;D&#182;&#207;±ê&#214;&#190;&#206;&#187;
//                TIM_ITConfig(TIMER_NUM, TIM_IT_Break,DISABLE); //ENABLE ê1&#196;ü&#189;&#244;&#188;±é23μ&#214;D&#182;&#207;  &#199;°&#195;&#230;DèòaTIM1_BDTRInitStructure.TIM_Break = TIM_Break_Enable;

//                // Clear Update Flag
//                TIM_ClearFlag(TIMER_NUM, TIM_FLAG_Update);
////               
//                TIM_ITConfig(TIMER_NUM, TIM_IT_Update, ENABLE); //&#212;úê&#199;·&#241;Dèòa&#182;áè&#161;ADC&#214;D&#190;&#246;&#182;¨1&#216;±&#213;&#187;ò&#191;a&#198;&#244;&#184;üD&#194;ê&#194;&#188;t&#214;D&#182;&#207;
////               
//                TIM_ITConfig(TIMER_NUM, TIM_IT_CC4,ENABLE);
               
                Motor_DRIVE_ON();
               
    /* TIMER_NUM counter enable */
    TIM_Cmd(TIMER_NUM, ENABLE);

    /* Main Output Enable */
    TIM_CtrlPWMOutputs(TIMER_NUM, ENABLE);
               
                // Resynch to have the Update evend during Undeflow
                TIM_GenerateEvent(TIMER_NUM, TIM_EventSource_Update);       
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2015-4-13 13:19 | 显示全部楼层
自己顶,哪位看看
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2015-4-13 17:12 | 显示全部楼层
问题已解决,TIM_TimeBaseStructure.TIM_Period = PWM_PERIOD-1;和CCR4   TIM_OCInitStructure.TIM_Pulse = PWM_PERIOD -1;不能相等
,需要改为TIM_OCInitStructure.TIM_Pulse = PWM_PERIOD -2;

评分

参与人数 1西莫币 +1 收起 理由
18201975434 + 1 多谢支持

查看全部评分

西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西莫电机圈 ( 浙ICP备10025899号-3 浙公网安备:33028202000436号

GMT+8, 2024-11-19 16:47 , Processed in 0.263801 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表