I'm using an STM32G474RE board and experimenting using a timer as an interrupt to call the DMA controller - which I think indexes into an array which holds values for my Sine wave lookup table.
I have all of this working using STMCubeMX and IDE.
At the moment it looks like (but i'm not sure):
- the timer increments a variable to the size of the array then resets back to zero,
- the DMA then rolls round to send the value to the DAC, this works great,
I would like to create a further 2 outputs, which I have working but I want to shift the index so the DMA retrieves data from the array x values into the array, the aim being I want to have a 120 Degree phase shift from phase A to phase B then C. e.g.
- Phase A 0 Degree (array index starts at 0)
- Phase B 120 Degree (array index start at 100)
- Phase C 240 Degree (array index starts at 200)
A snippet of the main function is below.
Is it possible to pre-load the index into the array so it starts filling the DAC with values later into the array?
I really appreciate any guidance.
Thanks, Nick
I have tried this and it works using STMCubeMx to generate the project and built the project using CubeIDE.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_DAC1_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
// The DAC,DMA and Look up table are defined here I think ,
HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*)Wave_LUT_BIG, 2500, DAC_ALIGN_12B_R);
HAL_TIM_Base_Start(&htim2);
HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_2, (uint32_t*)Wave_LUT_COS, 128, DAC_ALIGN_12B_R);
HAL_TIM_Base_Start(&htim2);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}