123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("AutoChips Software") are
- * protected under relevant copyright laws. The information contained herein is
- * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
- * the prior written permission of AutoChips inc. and/or its licensors, any
- * reproduction, modification, use or disclosure of AutoChips Software, and
- * information contained herein, in whole or in part, shall be strictly
- * prohibited.
- *
- * AutoChips Inc. (C) 2016. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
- * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
- * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
- * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
- * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
- * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
- * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
- * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
- * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
- * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
- * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
- * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
- * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
- * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
- * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
- */
- /**********<Incldue>**********/
- #include "ac780x_gpio.h"
- #include "ac780x.h"
- #include "ac780x_timer.h"
- #include "ac780x_pwm.h"
- #include "Motor.h"
- /**********<Prototype>*********/
- /**********<Variable>*********/
- uint32_t g_positvePulse;///<pulse width positive value
- uint32_t g_negativePulse;///<pulse width negative value
- uint32_t g_freq;///<pulse width period value
- float g_duty;///<pulse duty value
- uint32_t g_hallStatus;///<hall status value
- uint32_t g_overFlowCount;//PWM1计数溢出中断
- /**
- * PWM1_CallBack
- *
- * @param[in] device: device pointer
- * @param[in] wpara: callback parameter
- * @param[in] lpara: callback parameter
- * @return none
- * @brief PWM CallBack
- */
- void PWM1_CallBack(void *device, uint32_t wpara, uint32_t lpara)
- {
- //PWM计数器溢出中断
- if (wpara & PWM_INIT_CNTOF_Msk)
- {
- g_overFlowCount ++;
- //user add
-
- }
- //PWM通道中断
- //通过判断回调返回的lpara对应PWM_STR_CHnSF_Msk位状态判断是否发生通道中断
- if (lpara & PWM_STR_CHSF_Msk)
- {
-
- //user add
- //通道0中断
- if (lpara & PWM_STR_CH0SF_Msk)
- {
-
- }
- //通道1中断
- if (lpara & PWM_STR_CH1SF_Msk)
- {
-
- }
-
-
- }
- }
- /**
- *
- * @param[in] none
- *
- * @return none
- *
- * @brief Motor_Init
- *
- */
- void Motor_Init(void)
- {
- PWM_ConfigType pwmConfig;
- PWM_ModulationConfigType initModeStruct;
- PWM_IndependentChConfig independentChConfig[2];
-
- memset(&pwmConfig, 0, sizeof(pwmConfig));
- memset(&initModeStruct, 0, sizeof(initModeStruct));
-
- //MSP_PWM_Init(PWM1);
-
- /* independent channel 2 configuration */
- independentChConfig[0].channel = PWM_CH_2;
- independentChConfig[0].chValue = 0;
- independentChConfig[0].levelMode = PWM_HIGH_TRUE;
- independentChConfig[0].polarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;
- independentChConfig[0].interruptEn = DISABLE;
- independentChConfig[0].initLevel = PWM_LOW_LEVEL;
- independentChConfig[0].triggerEn = DISABLE;
- /* independent channel 3 configuration */
- independentChConfig[1].channel = PWM_CH_3;
- independentChConfig[1].chValue = 0; //MOD_PWM>>1;
- independentChConfig[1].levelMode = PWM_HIGH_TRUE;
- independentChConfig[1].polarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;
- independentChConfig[1].interruptEn = DISABLE;
- independentChConfig[1].initLevel = PWM_LOW_LEVEL;
- independentChConfig[1].triggerEn = DISABLE;
- initModeStruct.countMode = PWM_UP_COUNT;
- initModeStruct.deadtime = 24;
- initModeStruct.deadtimePsc = PWM_DEADTIME_DIVID_1;
- initModeStruct.initChOutputEn = ENABLE;
- initModeStruct.initTriggerEn = DISABLE;
- initModeStruct.independentChannelNum = 2;
- initModeStruct.independentChConfig = independentChConfig;
- pwmConfig.mode = PWM_MODE_MODULATION;
- pwmConfig.clkSource = PWM_CLK_SOURCE_APB;
- pwmConfig.clkPsc = PWM_PRES;
- pwmConfig.initValue = 0;
- pwmConfig.maxValue = MOD_PWM - 1;
- pwmConfig.overflowInterrupEn = ENABLE;
- pwmConfig.cntOverflowFreq = 0;
- pwmConfig.interruptEn = DISABLE;
- pwmConfig.callBack = PWM1_CallBack; //PWM中断回调
- pwmConfig.initModeStruct = &initModeStruct;
- PWM_Init(PWM1, &pwmConfig);
- NVIC_SetPriority(PWM1_IRQn, 0); //设置PWM模块中断的优先级
- }
- void Motor_Positive(uint8_t speed)
- {
- uint16_t chValue=0;
- if(speed > 100) speed = 100;
- //speed = 100 -speed;
-
- chValue = (uint16_t)speed*(MOD_PWM-1)/100;
-
- printf("Motor_Positive, speed:%d \r\n", speed);
- PWM_SetChannelCountValue(PWM1, PWM_CH_3, 0);
- PWM_SetChannelCountValue(PWM1, PWM_CH_2, chValue);
-
- }
- void Motor_Negative(uint8_t speed)
- {
- uint16_t chValue=0;
- if(speed > 100) speed = 100;
- //speed = 100 -speed;
-
- chValue = (uint16_t)speed*MOD_PWM/100;
- printf("Motor_Negative, speed:%d \r\n", speed);
-
- PWM_SetChannelCountValue(PWM1, PWM_CH_2, 0);
- PWM_SetChannelCountValue(PWM1, PWM_CH_3, chValue);
-
- }
- //电机停止转动
- void Motor_Stop(void)
- {
- PWM_SetChannelCountValue(PWM1, PWM_CH_2, 0);
- PWM_SetChannelCountValue(PWM1, PWM_CH_3, 0);
- }
- /**********<End>*********/
|