2 channels of DMA won't work
Hello, I'm trying to use 2channels of DMA , one for PWM in timer1 and one for reading adc1 using timer3 .
dma c2 should give ccr the amount from a uint string[1000](which i deleted from this code for simplifiing to be easier to read) and dma c1 for reading adc1 when timer3 update event acure but THE PROBLEM IS: dma works only either for pwm or for adc , with changing of prescale and arr of timer3 its change and work for other one if psc=719&arr=10 0 in timer3 only pwm work and if psc =11 and arr=200 only adc work , and if psc=60000 and arr=600 (wich i want this) none of the work whats the problem ??
p.s. both of them work perfectly if i dont start other one with hal_start_dma
#define AvarageNum 30
uint32_t adc_resualt[1*AvarageNum];
float sensor1,sensor2,sensor3,sensor4;pwm on timer1 and adc with dam and timer3 start:
MX_GPIO_Init();
MX_TIM3_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_TIM1_Init();
HAL_TIM_Base_Start(&htim3);
HAL_ADC_Start_DMA(&hadc1,adc_resualt,AvarageNum);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);
HAL_TIM_PWM_Start_DMA(&htim1,TIM_CHANNEL_1,(uint32_t *)1999, 1);
while (1)
{
if (sensor1>2000){ HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,1);
}
else{ HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,0);
}
}
/* USER CODE END 3 */
}timer 3 init :
static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 719;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 100;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
}timer1 init:
static void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}dma init:
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* DMA1_Channel2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn);
}adc timer3 callback which read adc :
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc3){
uint32_t sum1=0 , sum2=0 , sum3=0 , sum4=0;
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);
for(int i=0 ; i<AvarageNum ; i+=1){
sum1+= adc_resualt[i];
}
sensor1=sum1/AvarageNum;
}