2017-01-29 06:52 AM
Hi, I'm new to STM32 microcontrollers, now I have STM32F3Discovery board and I want to implement a signal follower.
The microcontroller read the signal from ADC1 pin A0 and generate it on DAC1 channel2.
when I have compiled my code with stdperiph the generated signal is a perfect copy, now when I tried to use HAL library using STM32CubeMX the output signal is slightly lower than the original.
/**************************** ADC init function generated by Cube Mx **************************/
static void MX_ADC1_Init(void)
{ADC_MultiModeTypeDef multimode;
ADC_ChannelConfTypeDef sConfig;hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc1.Init.LowPowerAutoWait = DISABLE; hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } multimode.DMAAccessMode = ADC_DMAACCESSMODE_DISABLED; multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE; if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) { Error_Handler(); } sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = 1; sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); }}
/**************************** my main function **************************/
int main(void)
{HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init(); MX_DAC_Init();HAL_DAC_Start(&hdac,DAC_CHANNEL_2);
HAL_ADC_Start(&hadc1);while (1){
HAL_DAC_SetValue(&hdac,DAC_CHANNEL_2,DAC_ALIGN_12B_R,HAL_ADC_GetValue(&hadc1)); }}#adc #hal #stm32f32017-01-29 10:10 AM
To check if the result is a carbon copy, use a debugger or dump out the gpio, adc, dac register values for both and then compare it to find clues in minutes. All the best in your debug!
2017-01-30 02:03 AM
Hi,
Now I haven't good knowledge to do debugging with STM, any good tutorial to do it ?
Regards