12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151 |
- /************************************************************************
- Project: Welling Motor Control Paltform
- Filename: hwsetup.c
- Partner Filename: hwsetup.h
- Description: Hardware setup
- Complier: IAR Embedded Workbench for ARM 7.80.4
- CPU TYPE : STM32F30x
- *************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- *************************************************************************
- Revising History (ECL of this file):
- ************************************************************************/
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
- *************************************************************************/
- #ifndef _HWSETUP_C_
- #define _HWSETUP_C_
- #endif
- /************************************************************************
- Included File
- *************************************************************************/
- #include "syspar.h"
- #include "user.h"
- #include "FuncLayerAPI.h"
- //#include "at32f421_wk_config.h"
- //#include "at32f421_misc.h"
- #include "ti_msp_dl_config.h"
- /************************************************************************
- Constant Table (N/A)
- *************************************************************************/
- //#define UART_HMI_BAUD_RATE (1200)
- #define UART_HMI_IBRD_36_MHZ_1200_BAUD (1875)
- #define UART_HMI_FBRD_36_MHZ_1200_BAUD (0)
- /*************************************************************************
- Exported Functions:
- *************************************************************************/
- /*************************************************************************
- Function: hw_voHardwareSetup;
- Description: Hardware Setup function.
- Call by: main();
- Input Variables: All HW registers
- Output/Return Variables: All HW registers
- Subroutine Call: ...;
- Reference: N/A
- *************************************************************************/
- void hw_voHardwareSetup1(void)
- {
- // Initialize System Control registers, WatchDog to a know state
- hw_voInitSysCtrl();
- // Select GPIO for the device or for the specific application:
- // wk_gpio_config();//
- hw_voInitGPIO();
- }
- void hw_voHardwareSetup2(void)
- {
- // Initialize all the Device Peripherals to a known state:外设配置
- hw_voInitPeri();
- // Initialize interrupt priority of peripherals: 中断优先级
- hw_voInitInt();
- }
- /*************************************************************************
- Local Functions (N/A)
- *************************************************************************/
- /*************************************************************************
- Function: hw_voInitPWM;
- Description: MTU Setup function.
- Call by: main();
- Input Variables: MTU HW registers
- Output/Return Variables: MTU HW registers
- Subroutine Call: ...;
- Reference: N/A
- *************************************************************************/
- void hw_voInitPeri(void)
- {
- // Initialize DMA
- hw_voInitDMA();
- // Initialize ADC
- hw_voInitADC();
- // Initialize Timer1
- hw_voInitTim1();
- /* init cmp function. */
- // wk_cmp_init();
- /* init tmr3 function. */
- // wk_tmr3_init();
- /* init tmr6 function. */
- // wk_tmr6_init();
- /* init tmr16 function. */
- // wk_tmr16_init();
- /* init tmr17 function. */
- // wk_tmr17_init();
- // Initialize SysTick
- hw_voInitSysTick();
- /* init usart1 function. */
- hw_voInitUART1();
- /* init exint function. */
- #if(EMCDEAL_EN==0)
- // wk_exint_config();
- #endif
- #if (UART_ID == 3)
- DL_UART_Main_setBaudRateDivisor(UART_HMI_INST, UART_HMI_IBRD_36_MHZ_1200_BAUD, UART_HMI_FBRD_36_MHZ_1200_BAUD);
- #endif
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitSysCtrl(void)
- {
- //system clock config program
- // wk_system_clock_config();
- //config periph clock
- // wk_periph_clock_config();
- /* config systick clock source */
- // systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8);
-
-
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitGPIO(void)
- {
- // gpio_init_type gpio_init_struct;
- //
- //
- // gpio_default_para_init(&gpio_init_struct);
- //
- // /* add user code begin tmr1_init 1 */
- //
- // /* add user code end tmr1_init 1 */
- //
- // /* configure the tmr1 CH1 pin */
- // gpio_init_struct.gpio_pins = PWM_AH_PIN;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init(PWM_AH_GPIO_PORT, &gpio_init_struct);
- //
- // gpio_pin_mux_config(PWM_AH_GPIO_PORT, GPIO_PINS_SOURCE8, GPIO_MUX_2);
- //
- // /* configure the tmr1 CH1C pin */
- // gpio_init_struct.gpio_pins = PWM_AL_PIN;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init(PWM_AL_GPIO_PORT, &gpio_init_struct);
- //
- // gpio_pin_mux_config(PWM_AL_GPIO_PORT, GPIO_PINS_SOURCE13, GPIO_MUX_2);
- //
- // /* configure the tmr1 CH2 pin */
- // gpio_init_struct.gpio_pins = PWM_BH_PIN;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init(PWM_BH_GPIO_PORT, &gpio_init_struct);
- //
- // gpio_pin_mux_config(PWM_BH_GPIO_PORT, GPIO_PINS_SOURCE9, GPIO_MUX_2);
- //
- // /* configure the tmr1 CH2C pin */
- // gpio_init_struct.gpio_pins = PWM_BL_PIN;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init(PWM_BL_GPIO_PORT, &gpio_init_struct);
- //
- // gpio_pin_mux_config(PWM_BL_GPIO_PORT, GPIO_PINS_SOURCE14, GPIO_MUX_2);
- //
- // /* configure the tmr1 CH3 pin */
- // gpio_init_struct.gpio_pins = PWM_CH_PIN;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init(PWM_CH_GPIO_PORT, &gpio_init_struct);
- //
- // gpio_pin_mux_config(PWM_CH_GPIO_PORT, GPIO_PINS_SOURCE10, GPIO_MUX_2);
- //
- // /* configure the tmr1 CH3C pin */
- // gpio_init_struct.gpio_pins = PWM_CL_PIN;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init(PWM_CL_GPIO_PORT, &gpio_init_struct);
- //
- // gpio_pin_mux_config(PWM_CL_GPIO_PORT, GPIO_PINS_SOURCE15, GPIO_MUX_2);
- //
- // /* configure the tmr1 CH4 pin */
- // gpio_init_struct.gpio_pins = GPIO_PINS_11;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
- // gpio_init(GPIOA, &gpio_init_struct);
- // gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE11, GPIO_MUX_2);
-
- }
-
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitDMA(void)
- {
- // /*=======================================================================
- // DMA1 Ch5 for Timer1
- // =======================================================================*/
- // // DMA_InitTypeDef DMA_InitStructure;
- //
- //// DMA_DeInit(DMA1_Channel5);
- //// DMA_InitStructure.DMA_PeripheralBaseAddr = (ULONG)(&TIM1->DMAR); //澶栬鍦板潃
- //// DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- //// DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //涓嶆墽琛屽璁惧湴鍧�澧為噺鎿嶄綔
- //// DMA_InitStructure.DMA_MemoryBaseAddr = (ULONG)hw_uwPWMCmpr;//(pwm_stGenOut.uwNewTIM1COMPR); // 鍐呭瓨鍦板潃
- //// DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- //// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //鎵ц瀛樺偍鍣ㄥ湴鍧�澧為噺鎿嶄綔
- //// DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//浠庡瓨鍌ㄥ櫒鍒板璁�
- //// DMA_InitStructure.DMA_BufferSize = TIM1_DMA_NUM; //6閫氶亾
- //// DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //鎵ц寰幆鎿嶄綔
- //// DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; //浼樺厛绾ф渶楂�
- //// DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //
- //// DMA_Init(DMA1_Channel5, &DMA_InitStructure);
- //// /* Enable DMA1 Channel 5 */
- //// //DMA_Cmd(DMA1_Channel5, ENABLE);
- //
- // wk_dma1_channel5_init();
- // wk_dma_channel_config(DMA1_CHANNEL5,(uint32_t)&TMR1->dmadt, (uint32_t)hw_uwPWMCmpr, TIM1_DMA_NUM);
- //
- // /*=======================================================================
- // DMA1 Ch1 for ADC1
- // =======================================================================*/
- //// DMA_DeInit(DMA1_Channel1);
- ////
- //// DMA_InitStructure.DMA_PeripheralBaseAddr = (ULONG)(&ADC1->DR);
- //// DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- //// DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- //// DMA_InitStructure.DMA_MemoryBaseAddr = (ULONG)(hw_uwADC1);
- //// DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- //// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
- //// DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
- //// DMA_InitStructure.DMA_BufferSize = ADC1_DMA_NUM;
- //// DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
- //// DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
- //// DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
- //// DMA_Init(DMA1_Channel1, &DMA_InitStructure);
- //// /* Enable DMA1 Channel1 */
- //// DMA_Cmd(DMA1_Channel1, ENABLE);
- //wk_dma1_channel1_init();
- //wk_dma_channel_config(DMA1_CHANNEL1, (uint32_t)&ADC1->odt, (uint32_t)(hw_uwADC1), ADC1_DMA_NUM);
- //dma_channel_enable(DMA1_CHANNEL1, TRUE);
- /*=======================================================================
- DMA1 Ch3 for UART3 receive
- =======================================================================*/
-
- /*=======================================================================
- DMA1 Ch2 for UART3 transmission
- =======================================================================*/
-
-
- // DMA_Cmd(DMA1_Channel2, ENABLE);
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitADC(void)
- {
- // wk_adc1_init();
- }
- void hw_SetIphaseSample(void)
- {
- // ADC1->psq_bit.pclen =3-1; //adc_preempt_channel_length_set(ADC1, 3);
- //
- // ADC1->psq_bit.psn2 = ADC_CHANNEL_0; //閲囨牱閫氶亾1
- // ADC1->psq_bit.psn3 = ADC_CHANNEL_1; //閲囨牱閫氶亾2
- // ADC1->psq_bit.psn4 = ADC_CHANNEL_3; //閲囨牱閫氶亾3
- // adc_preempt_channel_length_set(ADC1, 3);
- // adc_preempt_channel_set(ADC1, ADC_CHANNEL_0, 1, ADC_SAMPLETIME_1_5);
- // adc_preempt_offset_value_set(ADC1, ADC_PREEMPT_CHANNEL_1, 0x0);
- // adc_preempt_channel_set(ADC1, ADC_CHANNEL_1, 2, ADC_SAMPLETIME_1_5);
- // adc_preempt_offset_value_set(ADC1, ADC_PREEMPT_CHANNEL_2, 0x0);
- // adc_preempt_channel_set(ADC1, ADC_CHANNEL_3, 3, ADC_SAMPLETIME_1_5);
- // adc_preempt_offset_value_set(ADC1, ADC_PREEMPT_CHANNEL_3, 0x0);
- }
- //void hw_SetRdsonSample(adc_channel_select_type adc_channel)
- //{
- // ADC1->psq_bit.pclen =2-1;//adc_preempt_channel_length_set(ADC1, 2);
- //
- // ADC1->psq_bit.psn3 = adc_channel; //閲囨牱閫氶亾1
- // ADC1->psq_bit.psn4 = ADC_CHANNEL_6; //閲囨牱閫氶亾2 姣嶇嚎鐢垫祦鍊�
- //
- // adc_preempt_channel_length_set(ADC1, 3);
- // adc_preempt_channel_set(ADC1, ADC_CHANNEL_6, 1, ADC_SAMPLETIME_1_5);
- // adc_preempt_offset_value_set(ADC1, ADC_PREEMPT_CHANNEL_1, 0x0);
- // adc_preempt_channel_set(ADC1, ADC_CHANNEL_0, 2, ADC_SAMPLETIME_1_5);
- // adc_preempt_offset_value_set(ADC1, ADC_PREEMPT_CHANNEL_2, 0x0);
- // adc_preempt_channel_set(ADC1, ADC_CHANNEL_1, 3, ADC_SAMPLETIME_1_5);
- // adc_preempt_offset_value_set(ADC1, ADC_PREEMPT_CHANNEL_3, 0x0);
-
- //}
- /*************************************************************************
- Function:
- Description:OBC
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitUART1()
- {
- // gpio_init_type gpio_init_struct;
- //
- // /* enable the usart1 and gpio clock */
- // crm_periph_clock_enable(CRM_USART1_PERIPH_CLOCK, TRUE);
- // crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
- //
- // gpio_default_para_init(&gpio_init_struct);
- //
- // /* configure the usart2 tx/rx pin */
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init(GPIOB, &gpio_init_struct);
- //
- // /* config usart1 iomux */
- // gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE6, GPIO_MUX_0);
- // gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE7, GPIO_MUX_0);
- //
- //// nvic_irq_enable(USART1_IRQn, 3, 3);
- //
- // /* configure usart1 param */
- // usart_init(USART1, 9600, USART_DATA_8BITS, USART_STOP_1_BIT);
- // usart_transmitter_enable(USART1, TRUE);
- // usart_receiver_enable(USART1, TRUE);
- //// usart_interrupt_enable(USART1, USART_RDBF_INT, TRUE);
- //// usart_interrupt_enable(USART1, USART_TDBE_INT, TRUE);
- // usart_enable(USART1, TRUE);
- }
- /*************************************************************************
- Function:
- Description:BMS
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitUART2()
- {
- // gpio_init_type gpio_init_struct;
- //
- // /* enable the usart1 and gpio clock */
- // crm_periph_clock_enable(CRM_USART2_PERIPH_CLOCK, TRUE);
- // crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
- //
- // gpio_default_para_init(&gpio_init_struct);
- //
- // gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE14, GPIO_MUX_1);
- // gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE15, GPIO_MUX_1);
- //
- // /* configure the usart2 tx/rx pin */
- // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- // gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- // gpio_init_struct.gpio_pins = GPIO_PINS_14 | GPIO_PINS_15;
- // gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- // gpio_init(GPIOA, &gpio_init_struct);
- //
- // /* config usart1 iomux */
- //// gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE14, GPIO_MUX_1);
- //// gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE15, GPIO_MUX_1);
- //
- //// nvic_irq_enable(USART2_IRQn, 3, 3);
- //
- // /* configure usart1 param */
- // usart_init(USART2, 9600, USART_DATA_8BITS, USART_STOP_1_BIT);
- // usart_transmitter_enable(USART2, TRUE);
- // usart_receiver_enable(USART2, TRUE);
- //// usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE);
- //// usart_interrupt_enable(USART2, USART_TDBE_INT, TRUE);
- // usart_enable(USART2, TRUE);
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitTim1(void)
- {
- // tmr_output_config_type tmr_output_struct;
- // tmr_brkdt_config_type tmr_brkdt_struct;
- //
- //// TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- //// TIM_OCInitTypeDef TIM_OCInitStructure;
- //// TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
- ////
- //// TIM_DeInit(TIM1);
- ////
- //// /* Time Base configuration */
- //// TIM_TimeBaseStructure.TIM_Prescaler = 0; // TIMx->PSC 鍒嗛
- //// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned3; // TIMx->CR1 bit5~6鍚戜笂鍚戜笅鍧囪璁剧疆
- //// TIM_TimeBaseStructure.TIM_Period = HW_HPWM_PERIOD; //鑷姩閲嶈杞藉瘎瀛樺櫒 TIMx->ARR
- //// TIM_TimeBaseStructure.TIM_ClockDivision = 0; //TIMx->CR1 bit8~9 鏃堕挓鍒嗛鍥犲瓙
- //// TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;// TIMx->RCR 閲嶅璁℃暟瀵勫瓨鍣�
- //// TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
- ////------------
- // /* configure counter settings */
- // tmr_base_init(TMR1, 2249, 0);
- // tmr_cnt_dir_set(TMR1, TMR_COUNT_TWO_WAY_3);
- // tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);
- // tmr_repetition_counter_set(TMR1, 0);
- // // tmr_period_buffer_enable(TMR1, TRUE); //鑷姩閲嶈杞介瑁呰浇鍏佽
- //
- //
- //
- ////--------
- //
- // // TIM1->EGR = 0x0001;//event generation Register,Bit0:UG=1
- //
- // /* Channel 1, 2,3 Configuration in PWM mode */
- //// TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIMx->CCMR1 bit 4~6 pwm2妯″紡锛�
- //// TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;//TIMx->CCER bit0 鍏抽棴锛� OC1绂佹杈撳嚭
- //// TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;// TIMx->CCER bit2 TIMx->CCER 鍏抽棴锛� OC1N绂佹杈撳嚭
- //// TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;//TIMx->CCER bit1 OC1楂樼數骞虫湁鏁�
- //// TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //TIMx->CCER bit4 OC1N楂樼數骞虫湁鏁堬紱
- //// TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;//TIMx->CR2 bit8 OC1杈撳嚭绌洪棽鐘舵��
- //// TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;//TIMx->CR2 bit9 杈撳嚭绌洪棽鐘舵��
- ////
- //// TIM_OCInitStructure.TIM_Pulse = HW_HHPWM_PERIOD; //TIMx_CCR1,OC1棰勮杞藉��
- //// TIM_OC1Init(TIM1, &TIM_OCInitStructure);
- ////
- //// TIM_OCInitStructure.TIM_Pulse = HW_HHPWM_PERIOD;//TIMx_CCR2,OC2棰勮杞藉��
- //// TIM_OC2Init(TIM1, &TIM_OCInitStructure);
- ////
- //// TIM_OCInitStructure.TIM_Pulse = HW_HHPWM_PERIOD;//TIMx_CCR3,OC3棰勮杞藉��
- //// TIM_OC3Init(TIM1, &TIM_OCInitStructure);
- ////
- //// /* CH4 configuration as ADC trigger signal */
- //// if(cp_stFlg.CurrentSampleModelSelect == SINGLERESISITANCE)
- //// {
- //// TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- //// TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- //// TIM_OCInitStructure.TIM_Pulse = HW_HPWM_PERIOD - 5;
- //// TIM_OC4Init(TIM1, &TIM_OCInitStructure);
- //// }
- //// else if(cp_stFlg.CurrentSampleModelSelect == RDSON)
- //// {
- //// TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- //// TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- //// TIM_OCInitStructure.TIM_Pulse = 1;
- //// TIM_OC4Init(TIM1, &TIM_OCInitStructure);
- //// }
- //// else if(cp_stFlg.CurrentSampleModelSelect == COMBINATION)
- //// {
- //// TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- //// TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- //// TIM_OCInitStructure.TIM_Pulse = 200;
- //// TIM_OC4Init(TIM1, &TIM_OCInitStructure);
- //// }
- //// else if(cp_stFlg.CurrentSampleModelSelect == DOUBLERESISTANCE)
- //// {
- //// TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //TIMx->CCER bit12 杈撳嚭浣胯兘
- //// TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //TIMx->CCER 楂樻湁鏁�
- //// TIM_OCInitStructure.TIM_Pulse = 1; //TIMx_CCR4 CC4 姣旇緝鍊硷紝1锛屽湪娉㈣胺澶勯噰闆嗙浉鐢垫祦
- //// TIM_OC4Init(TIM1, &TIM_OCInitStructure);
- //// }
- //// else
- //// {}
- // //-----------------------
- // /* configure channel 1 output settings */
- // tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B;
- // tmr_output_struct.oc_output_state = FALSE;
- // tmr_output_struct.occ_output_state = FALSE;
- // tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.oc_idle_state = FALSE;
- // tmr_output_struct.occ_idle_state = FALSE;
- // tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
- // tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, HW_HHPWM_PERIOD); //OC1棰勮杞藉��
- // tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
- //
- // tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
- //
- // /* configure channel 2 output settings */
- // tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B;
- // tmr_output_struct.oc_output_state = FALSE;
- // tmr_output_struct.occ_output_state = FALSE;
- // tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.oc_idle_state = FALSE;
- // tmr_output_struct.occ_idle_state = FALSE;
- // tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
- // tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, HW_HHPWM_PERIOD);//OC1棰勮杞藉��
- // tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
- //
- // tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
- //
- // /* configure channel 3 output settings */
- // tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B;
- // tmr_output_struct.oc_output_state = FALSE;
- // tmr_output_struct.occ_output_state = FALSE;
- // tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.oc_idle_state = FALSE;
- // tmr_output_struct.occ_idle_state = FALSE;
- // tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
- // tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_3, HW_HHPWM_PERIOD);//OC1棰勮杞藉��
- // tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_3, FALSE);
- //
- // tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_3, FALSE);
- //
- // /* configure channel 4 output settings */
- // tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B;
- // tmr_output_struct.oc_output_state = FALSE;
- // tmr_output_struct.occ_output_state = FALSE;
- // tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
- // tmr_output_struct.oc_idle_state = FALSE;
- // tmr_output_struct.occ_idle_state = FALSE;
- // tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_4, &tmr_output_struct);
- // tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_4, 108);
- // tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_4, FALSE); //杈撳嚭姣旇緝1棰勮杞藉け鑳�
- //
- // tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_4, FALSE);
- //
- //
- // //-------------------------
- // //TIMx->BDTR 鍒硅溅鍜屾鍖哄瘎瀛樺櫒
- //// TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; // bit11 杩愯妯″紡涓嬪綋瀹氭椂鍣ㄤ笉宸ヤ綔鏃讹紝涓�鏃CxE=1鎴朇CxNE=1锛岄鍏堝紑鍚疧C/OCN骞惰緭鍑烘棤鏁堢數骞筹紝鐒跺悗
- //// //缃甇C/OCN浣胯兘杈撳嚭淇″彿=1銆�
- //// TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; //bit101 绌洪棽妯″紡涓嬪綋瀹氭椂鍣ㄤ笉宸ヤ綔鏃讹紝涓�鏃CxE=1鎴朇CxNE=1锛� OC/OCN棣栧厛杈撳嚭鍏剁┖闂茬數骞筹紝鐒跺悗
- //// // OC/OCN浣胯兘杈撳嚭淇″彿=1銆�
- //// TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_2; //閿佸畾绾у埆2
- //// TIM_BDTRInitStructure.TIM_DeadTime = cp_stControlPara.swIPMDeadTimeNs / 100 * TIM1CLK_KHZ / 1000 / 10;//bot0~7 姝诲尯浜嬮棿1us
- //// TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable; //bit12 寮�鍚埞杞﹁緭鍏�
- //// TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;//bit13 鍒硅溅杈撳叆浣庣數骞虫湁鏁�
- //// TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;//bit14 鑷姩杈撳嚭浣胯兘 MOE鍙兘琚蒋浠剁疆鈥�1鈥�
- //// TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
- ////--------------------
- // /* configure break and dead-time settings */
- // tmr_brkdt_struct.brk_enable = TRUE;//TRUE;//FALSE;//TRUE;
- // tmr_brkdt_struct.auto_output_enable = FALSE;
- //#if(HARDWAREV30==1)
- // tmr_brkdt_struct.brk_polarity =TMR_BRK_INPUT_ACTIVE_HIGH;// TMR_BRK_INPUT_ACTIVE_HIGH;
- //#else
- // tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_HIGH;//TMR_BRK_INPUT_ACTIVE_LOW;// TMR_BRK_INPUT_ACTIVE_HIGH;
- //#endif
- // tmr_brkdt_struct.fcsoen_state = TRUE;
- // tmr_brkdt_struct.fcsodis_state = TRUE;
- // tmr_brkdt_struct.wp_level = TMR_WP_LEVEL_2;
- // tmr_brkdt_struct.deadtime = 72;
- // tmr_brkdt_config(TMR1, &tmr_brkdt_struct);
- // //-------------------
- //// TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);// TIMx->CCMR1 bit3 杈撳嚭姣旇緝1棰勮杞戒娇鑳斤紝闅忔椂鍐欏叆TIMx_CCR1瀵勫瓨鍣紝骞朵笖鏂板啓鍏ョ殑鏁板�肩珛鍗宠捣浣滅敤
- //// TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Disable);//TIMx->CCMR1 bit11
- //// TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Disable);//TIMx->CCMR2 bit3
- //// TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Disable); //TIMx->CCMR2 bit113 Disables the TIM1 peripheral Preload register on CCR4
- //// TIM_ARRPreloadConfig(TIM1, ENABLE); //TIMx->CR1 bit7 鑷姩閲嶈杞介瑁呰浇鍏佽浣� Enables TIMx peripheral Preload register on ARR
- ////
- ////
- //// TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_3Transfers);// TIMx->DCR bit0~4 bit8~12 杩炵画浼犻��3涓�氶亾锛孌MA鍩哄湴鍧�TIMx_CR1
- ////
- ////
- //// TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); //TIMx->SMCR bit7 MSM:1; Master Slave Mode
- //// TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); //TIMx->CR2 bit4~6 涓绘ā寮忛�夋嫨锛屾洿鏂颁簨浠惰閫変负瑙﹀彂杈撳叆(TRGO)
- ////
- //// /*Main Output ENABLE*/
- //// TIM_CtrlPWMOutputs(TIM1, ENABLE); //TIMx->BDTR bit15 MOE 涓昏緭鍑轰娇鑳�
- // //------------------
- // //tmr_counter_enable(TMR1,TRUE);
- // tmr_period_buffer_enable(TMR1, TRUE); //鑷姩閲嶈杞介瑁呰浇鍏佽
- // TMR1->dmactrl = 0x0200|TMR_C1DT_ADDRESS; ////DMA1浼犺緭娆℃暟3 锛孴MR_C1DT_ADDRESS
- //
- //
- // /* configure primary mode settings */
- // tmr_sub_sync_mode_set(TMR1, TRUE); //娆″畾鏃跺櫒鍚屾
- // tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_OVERFLOW);//涓诲畾鏃跺櫒杈撳嚭淇″彿閫夋嫨:婧㈠嚭浜嬩欢
- //
- // tmr_output_enable(TMR1,TRUE);//OEN 涓昏緭鍑轰娇鑳�
- //----------------
-
-
-
-
-
- //
- // wk_tmr1_init();
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- //void hw_voInitTim2(void)
- //{
- //
- // TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- // TIM_ICInitTypeDef TIM_ICInitStructure;
- // TIM_DeInit(TIM2);
- //
- // /* TIM4 capture of sensor of frequency */
- // TIM_TimeBaseStructure.TIM_Prescaler = 0;
- // TIM_TimeBaseStructure.TIM_ClockDivision = 0;
- // TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- //// TIM_TimeBaseStructure.TIM_Period = FTBC_HZ * 4 / FTBS_HZ - 1;
- // TIM_TimeBaseStructure.TIM_Period =TIM2CLK_KHZ * 1000 / FTBS_HZ - 1;
- // TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
- // TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
- //
- //// /* Slaves (TIM2) Configuration */
- //// TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_External1);
- //// /* Selects the Input Trigger source */
- //// TIM_SelectInputTrigger(TIM2, TIM_TS_ITR0); // IRT0锟斤拷TIM1
- //
- // TIM_ARRPreloadConfig(TIM2, ENABLE); // Enables TIMx peripheral Preload register on ARR
- // //TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); // MSM:1; Master Slave Mode
- //
- // TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
- // TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- // TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- // TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- // TIM_ICInitStructure.TIM_ICFilter = 0;
- // TIM_ICInit(TIM2, &TIM_ICInitStructure);
- //
- // TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
- // TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- // TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- // TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- // TIM_ICInitStructure.TIM_ICFilter = 0;
- // TIM_ICInit(TIM2, &TIM_ICInitStructure);
- //}
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- //void hw_voInitTim3(void)
- //{
- //
- // TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- // TIM_ICInitTypeDef TIM_ICInitStructure;
- //
- // TIM_DeInit(TIM3);
- //
- // /* TIM3 capture of sensor of frequency */
- // TIM_TimeBaseStructure.TIM_Prescaler = 19; // TIMx_PSC, Counter clock frequency = fCK_PSC/(PSC[15:0]+1)
- // TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- // TIM_TimeBaseStructure.TIM_Period = 60000; //[15:0] Maximum count value 65535
- // TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- // TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
- // TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
- //
- // /* Hall IC Signal */
- // TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
- // TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- // TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- // TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- // TIM_ICInitStructure.TIM_ICFilter = 0x0;
- // TIM_ICInit(TIM3, &TIM_ICInitStructure);
- //
- // TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
- // TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- // TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- // TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- // TIM_ICInitStructure.TIM_ICFilter = 0x0;
- // TIM_ICInit(TIM3, &TIM_ICInitStructure);
- //
- // TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
- // TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- // TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- // TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- // TIM_ICInitStructure.TIM_ICFilter = 0x0;
- // TIM_ICInit(TIM3, &TIM_ICInitStructure);
- //
- // TIM_ARRPreloadConfig(TIM3, ENABLE); // Enables TIMx peripheral Preload register on ARR
- //
- //}
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- //void hw_voInitTim4(void)
- //{
- // TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- // TIM_DeInit(TIM4);
- //
- // TIM_TimeBaseStructure.TIM_Prescaler = 0;
- // TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- // TIM_TimeBaseStructure.TIM_Period = APB2CLK_KHZ * 1000 / FPWM_HZ * 2; //HW_PWM_PERIOD * 2;
- // TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- // TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
- // TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
- //
- // TIM_ARRPreloadConfig(TIM4, ENABLE); // Enables TIMx peripheral Preload register on ARR
- //}
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
-
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voInitSysTick(void)
- {
- /* Setup systick timer interrupts */
- //SysTick_Config(SystemCoreClock / FSYSTICK_HZ);
- // systick_interrupt_config(system_core_clock / 8 / 1000);
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference: 浼樺厛绾�
- *************************************************************************/
- void hw_voInitInt(void)
- {
- // NVIC_InitTypeDef NVIC_InitStructure;
- //
- // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- //
- // /* Enable the ADC1,2 Interrupt */
- // NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
- //
- // /* Enable the TIM1 Interrupt PWM Interrupt*/
- // NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
- //
- //
- // /* Enable TIM2 Interrupt TIM2 CAP*/
- // NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
- //
- // /* Enable TIM3 Interrupt, TIM3 HALL CAP*/
- // NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
-
- // wk_nvic_config();
-
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:涓柇寮�鍚�
- *************************************************************************/
- void hw_voEnInt(void)
- {
- // /* ADC group conversion Interrupts enable */
- // if(cp_stFlg.CurrentSampleModelSelect== SINGLERESISITANCE)
- // {
- // ADC_ITConfig(ADC2, ADC_IT_JEOC, ENABLE);
- // }
- // else if((cp_stFlg.CurrentSampleModelSelect == DOUBLERESISTANCE) || (cp_stFlg.CurrentSampleModelSelect== RDSON))
- // {
- // ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
- // }
- // else if(cp_stFlg.CurrentSampleModelSelect== COMBINATION)
- // {
- // ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
- // ADC_ITConfig(ADC2, ADC_IT_JEOC, ENABLE);
- // }
- // else
- // {
- //
- // }
- //
- // /* TIM1 Interrupts enable */
- // TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
- //// TIM_ITConfig(TIM1, TIM_IT_CC4, ENABLE);
- //
- // /* TIM2 Interrupts enable */
- // TIM_ITConfig(TIM2, TIM_IT_CC3, ENABLE);
- // TIM_ITConfig(TIM2, TIM_IT_CC4, ENABLE);
- // TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
- //
- // /* TIM3 Interrupts enable */
- // TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
- // TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
- // TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
- // TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE);
- //
- // /* DMA full transfer finish interrupt */
- // DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE);
- // DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE);
-
- //--------------------
- /* add user code begin adc1_init 2 */
- //adc_interrupt_enable(ADC1,ADC_CCE_INT,TRUE);
- // adc_interrupt_enable(ADC1,ADC_PCCE_INT,TRUE);
- //// dma_interrupt_enable(DMA1_CHANNEL1,DMA_FDT_INT,TRUE);
- //
- // /* add user code begin tmr1_init 2 */
- // tmr_interrupt_enable(TMR1,TMR_OVF_INT,TRUE);
- // tmr_flag_clear(TMR1,TMR_BRK_FLAG);
- // tmr_interrupt_enable(TMR1,TMR_BRK_INT,TRUE);
- //
- // // (TMR16,TMR_C1_INT,TRUE);
- // tmr_flag_clear(TMR16, TMR_C1_INT | TMR_OVF_INT );
- // tmr_interrupt_enable(TMR16,TMR_OVF_INT,TRUE);
- // tmr_interrupt_enable(TMR16,TMR_C1_INT,TRUE);
- //
- // // (TMR17,TMR_C1_INT,TRUE);
- // tmr_flag_clear(TMR17, TMR_C1_INT | TMR_OVF_INT );
- // tmr_interrupt_enable(TMR17,TMR_OVF_INT,TRUE);
- // tmr_interrupt_enable(TMR17,TMR_C1_INT,TRUE);
- // //------time3
- // tmr_flag_clear(TMR3, TMR_C1_INT | TMR_OVF_INT |TMR_C2_INT |TMR_C3_INT);
- // tmr_interrupt_enable(TMR3, TMR_C1_INT, TRUE);
- // tmr_interrupt_enable(TMR3, TMR_C2_INT, TRUE);
- // tmr_interrupt_enable(TMR3, TMR_C3_INT, TRUE);
- // tmr_interrupt_enable(TMR3, TMR_OVF_INT, TRUE);
- //
- // usart_interrupt_enable(USART1, USART_RDBF_INT, TRUE);
- // usart_interrupt_enable(USART1, USART_TDBE_INT, TRUE);
- //
- //#ifdef SIMULATION
- // usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE);
- // usart_interrupt_enable(USART2, USART_TDBE_INT, TRUE);
- //#endif
-
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:寮�鍚鏁�
- *************************************************************************/
- void hw_voTimEn(void)
- {
- // tmr_counter_enable(TMR1, TRUE);
- // tmr_counter_enable(TMR3, TRUE);
- // tmr_counter_enable(TMR6, TRUE);
- // tmr_counter_enable(TMR16, TRUE);
- // tmr_counter_enable(TMR17, TRUE);
-
- // /* TIM1 counter enable */
- // TIM_Cmd(TIM1, ENABLE);
- // /* TIM2 counter enable */
- // TIM_Cmd(TIM2, ENABLE);
- // /* TIM3 counter enable */
- // TIM_Cmd(TIM3, ENABLE);
- // /* TIM4 counter enable */
- // TIM_Cmd(TIM4, ENABLE);
- // DL_TimerA_startCounter(MOTOR_PWM_INST);
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:pwm鍒濆鍖�
- *************************************************************************/
- void hw_voPWMInit(void)
- {
- /* Set 50% duty */
- pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[3] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
- /* PWM off */
- hw_voPWMOff();
- /* Charge init */
- hw_uwChrgCt = 0;
- hw_blChrgOvrFlg = FALSE;
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:寮�椹卞姩
- *************************************************************************/
- void hw_voPWMOn(void)
- {
- if (hw_blPWMOnFlg == FALSE)
- {
- // /* CH1, CH2 set to "PWM mode 2" */
- // TMR1->cm1 |= 0x7070;// TIM1->CCMR1 |= 0x7070;
- // /* CH3 set to "PWM mode 2" */
- // TMR1->cm2 |= 0x7070;// TIM1->CCMR2 |= 0x7070;
- // /* CH1, CH2 and CH3 output enable */
- // TMR1->cctrl |= 0x5555;// TIM1->CCER |= 0x5555; 楂樻湁鏁�
- //// TIM1->CCER |= 0x0FFF;
- //
- // /* Flag set */
- DL_Timer_overrideCCPOut(MOTOR_PWM_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, DL_TIMER_CC_0_INDEX);
- DL_Timer_overrideCCPOut(MOTOR_PWM_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, DL_TIMER_CC_1_INDEX);
- DL_Timer_overrideCCPOut(MOTOR_PWM_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, DL_TIMER_CC_2_INDEX);
- hw_blPWMOnFlg = TRUE;
- }
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:鍏抽┍鍔�
- *************************************************************************/
- void hw_voPWMOff(void)
- {
- if (hw_blPWMOnFlg == TRUE)
- {
- // /* CH1, CH2 set to "Frozen" */
- // TMR1->cm1 &= ~0x7070;// TIM1->CCMR1 &= ~0x7070;
- // /* CH3 set to "Frozen" */
- //// TIM1->CCMR2 &= ~0x7070;
- // TMR1->cm2&= ~0x0070; // TIM1->CCMR2 &= ~0x0070; //don't change CC4
- // /* CH1, CH2 set to "Force inactive level" */
- // TMR1->cm1 |= 0x4040;// TIM1->CCMR1 |= 0x4040;
- // /* CH3 set to "Force inactive level" */
- //// TIM1->CCMR2 |= 0x4040;
- // TMR1->cm2 |= 0x0040; // TIM1->CCMR2 |= 0x0040; //don't change CC4
- // /* CH1, CH2 and CH3 complementary output disable */
- //// TIM1->CCER &= ~0x4444;
- // TMR1->cctrl &= ~0x4444;//TIM1->CCER &= ~0x4444;
- //
- DL_Timer_overrideCCPOut(MOTOR_PWM_INST, DL_TIMER_FORCE_OUT_LOW, DL_TIMER_FORCE_CMPL_OUT_LOW, DL_TIMER_CC_0_INDEX);
- DL_Timer_overrideCCPOut(MOTOR_PWM_INST, DL_TIMER_FORCE_OUT_LOW, DL_TIMER_FORCE_CMPL_OUT_LOW, DL_TIMER_CC_1_INDEX);
- DL_Timer_overrideCCPOut(MOTOR_PWM_INST, DL_TIMER_FORCE_OUT_LOW, DL_TIMER_FORCE_CMPL_OUT_LOW, DL_TIMER_CC_2_INDEX);
- /* Flag set */
- hw_blPWMOnFlg = FALSE;
- }
- }
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:50%鍗犵┖姣旇嚜妫�
- *************************************************************************/
- void hw_voCharge(void)
- {
- /* Set 50% duty */
- pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[3] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HHPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
- // pwm_stGenOut.uwNewTIM1COMPR[0] = 337;
- // pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
- // pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
- // pwm_stGenOut.uwNewTIM1COMPR[3] = 337;
- // pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HHPWM_PERIOD;
- // pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
- /* PWM on */
- hw_voPWMOn();
- if (++hw_uwChrgCt > cp_stControlPara.swIPMHvicChrgMs)
- {
- hw_uwChrgCt = 0;
- hw_blChrgOvrFlg = TRUE;
-
- }
- }
- /* Three phase short */
- /*************************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- *************************************************************************/
- void hw_voThrPhsShrt(void)
- {
- /* Set 0% duty */
- pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[3] = HW_HPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HPWM_PERIOD;
- pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HPWM_PERIOD;
- pwm_stGenOut.uwFirstTrigCOMPR = HW_HHHPWM_PERIOD;
- pwm_stGenOut.uwSecondTrigCOMPR = HW_HPWM_PERIOD - HW_HHHPWM_PERIOD;
- /* PWM on */
- hw_voPWMOn();
- }
- /*************************************************************************
- Function
- Description: Initialize UART
- Call by: ;
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: ...;
- Reference: N/A鐪嬮棬鐙�
- ****************************************************************/
- void hw_voIWDGInit(UWORD prer, UWORD rlr)
- {
- // RCC_LSICmd(ENABLE);
- // while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) != SET)
- // {}
- // IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
- // IWDG_SetPrescaler(prer);
- // IWDG_SetReload(rlr);
- // IWDG_ReloadCounter();
- // IWDG_Enable();
- }
- /*************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************/
- #ifdef _HWSETUP_C_
- #undef _HWSETUP_C_
- #endif
- /************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|