想要請問各位先進,如果我想要測試模組Reverse Park內的演算是否有錯誤,我用DA來將演算出來的數據接上示波器觀看,但是我發現我Reverse Park計算後的值和DA讀出來的數據有所不同,所以想要請問是哪裡出錯呢?我DA是為PA4, PA5兩隻Pin腳。程式中Theta從0~360度,Stat_Volt_q_d固定都給3.3V 。對於輸入電壓值,想要請問是直接給3.3還是我必須要做轉換呢?謝謝主程式如下 Stat_Volt_q_d.qV_Component1 =3.3; Stat_Volt_q_d.qV_Component2 = 3.3; Stat_Volt_alfa_beta = ipark_calc(Stat_Volt_q_d, Theta); Stat_Volt_alfa_beta.qV_Component1 = Stat_Volt_alfa_beta.qV_Component1 / 32766; Stat_Volt_alfa_beta.qV_Component2 = Stat_Volt_alfa_beta.qV_Component2 / 32766; DAC_SetChannel1Data(DAC_Align_12b_R, Stat_Volt_alfa_beta.qV_Component1); DacX = DAC_GetDataOutputValue(DAC_Channel_1); DacTemp = (float) DacX * (3.3/4096); DAC_SetChannel2Data(DAC_Align_12b_R, Stat_Volt_alfa_beta.qV_Component2); DacX = DAC_GetDataOutputValue(DAC_Channel_2); DacTemp = (float) DacX * (3.3/409); 副程式 static void DAC_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); } static void DAC_TIM_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 100; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); TIM_Cmd(TIM2, ENABLE); } static void DAC_Init(void) { DAC_InitTypeDef DAC_InitStructure; DMA_InitTypeDef DMA_INIT; RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095; DAC_Init(DAC_Channel_2, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); DAC_Cmd(DAC_Channel_2, ENABLE); DAC_SetDualChannelData(DAC_Align_12b_R, 0x00, 0x00); } |