123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 |
- /************************************************************************
- 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)
- *************************************************************************/
- /*************************************************************************
- 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
- /* init usart2 function. */
- #if (SIMULATION == 0)
- hw_voInitUART2();
- #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);
- //
- //#if (SIMULATION == 0)
- // 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!
- *************************************************************************/
|