cancel
Showing results for 
Search instead for 
Did you mean: 

Timer PWM arbitrary waveform repition counter does not work

Curtis B.
Senior

Hi everyone,

I am trying to generate an arbitrary PWM waveform using DMA burst write according to AN4776. It works in principle, except of one thing: If i want to have more than one pulse with a specifig period/pulse setting, the RCR should be used. However, no matter what I write to RCR one one pulse with the corresponding settings is generated.

I wrote a short test code.

The burst write data is:

 

 

const uint16_t curve_test[4] = {0x50F,0x50F,0xFE,0x288}; // PSC,ARR,RCR,CCR1

 

 

 Pulse pattern is startet with:

 

 

htim1.hdma[TIM_DMA_ID_CC1]->Instance->CR |= DMA_SxCR_MINC;
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_DMABurst_MultiWriteStart(&htim1,TIM_DMABASE_PSC,TIM_DMA_CC1,(uint32_t *) &curve_test[0],TIM_DMABURSTLENGTH_4TRANSFERS,(uint32_t) 4);

 

 

and stopped with:

 

 

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
	BaseType_t xHigherPriorityTaskWoken;
	xHigherPriorityTaskWoken = pdFALSE;

	HAL_TIM_PWM_Stop_DMA(htim,TIM_CHANNEL_1);
	HAL_TIM_DMABurst_WriteStop(htim,TIM_DMA_CC1);
	xSemaphoreGiveFromISR(xSemaphoreStepperCmplt,&xHigherPriorityTaskWoken);

	portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

 

 

Using this code I only get one pulse per call. Does anyome has a hint what I might do wrong?

BR

Daniel

2 REPLIES 2

Which STM32?

I am not interested in discovering how various Cube/HAL contraptions are supposed to be used, but I suspect some of the functions you are calling in the callback actively disable the timer. Place a breakpoint at the beginning of that function and observe both output and the involved peripherals' registers.

JW

I have founde the mistake. The problem was that the burst transfer and DMA transfer was related to Capture Compare and not to update event. I had to configure the DMA channel to "TIM1_UP" and to call the burst transfer by

HAL_TIM_DMABurst_MultiWriteStart(&htim1,TIM_DMABASE_PSC,TIM_DMA_UPDATE,(uint32_t *) &curve_data[0],TIM_DMABURSTLENGTH_4TRANSFERS,(uint32_t) puls_cnt);

.

The related callback then is:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)