1
0

add poc adc with timer

This commit is contained in:
Rémi Heredero 2024-01-13 12:21:40 +01:00
parent da4e4773f1
commit b4818a75b1
6 changed files with 62 additions and 36 deletions

View File

@ -56,7 +56,6 @@ void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void ADC_IRQHandler(void);
void TIM1_CC_IRQHandler(void);
void TIM6_DAC_IRQHandler(void);
void LTDC_IRQHandler(void);
void DMA2D_IRQHandler(void);

View File

@ -6,9 +6,13 @@
*/
#include "stm32f7xx_hal.h"
#include "main.h"
extern "C" void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc) {
HAL_GPIO_TogglePin(OUT1_GPIO_Port, OUT1_Pin);
volatile uint32_t value = HAL_ADC_GetValue(hadc);
}

View File

@ -93,6 +93,8 @@ static void MX_USART1_UART_Init(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
@ -140,14 +142,16 @@ int main(void)
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_1);
HAL_ADC_Start_IT(&hadc3);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
HAL_ADC_Start_IT(&hadc3);
HAL_Delay(2000);
//HAL_Delay(2000);
@ -241,8 +245,8 @@ static void MX_ADC3_Init(void)
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc3.Init.ContinuousConvMode = DISABLE;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING;
hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DMAContinuousRequests = DISABLE;
@ -595,14 +599,16 @@ static void MX_TIM1_Init(void)
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
/* USER CODE BEGIN TIM1_Init 1 */
/* USER CODE END TIM1_Init 1 */
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.Prescaler = 199;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 65535;
htim1.Init.Period = 99;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
@ -615,6 +621,10 @@ static void MX_TIM1_Init(void)
{
Error_Handler();
}
if (HAL_TIM_OC_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
@ -622,6 +632,32 @@ static void MX_TIM1_Init(void)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.BreakFilter = 0;
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
sBreakDeadTimeConfig.Break2Filter = 0;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM1_Init 2 */
/* USER CODE END TIM1_Init 2 */

View File

@ -677,9 +677,6 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
HAL_GPIO_Init(ARDUINO_PWM_D10_GPIO_Port, &GPIO_InitStruct);
/* TIM1 interrupt Init */
HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
/* USER CODE BEGIN TIM1_MspInit 1 */
/* USER CODE END TIM1_MspInit 1 */
@ -862,8 +859,6 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
*/
HAL_GPIO_DeInit(ARDUINO_PWM_D10_GPIO_Port, ARDUINO_PWM_D10_Pin);
/* TIM1 interrupt DeInit */
HAL_NVIC_DisableIRQ(TIM1_CC_IRQn);
/* USER CODE BEGIN TIM1_MspDeInit 1 */
/* USER CODE END TIM1_MspDeInit 1 */

View File

@ -58,7 +58,6 @@
extern ADC_HandleTypeDef hadc3;
extern DMA2D_HandleTypeDef hdma2d;
extern LTDC_HandleTypeDef hltdc;
extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim6;
/* USER CODE BEGIN EV */
@ -217,20 +216,6 @@ void ADC_IRQHandler(void)
/* USER CODE END ADC_IRQn 1 */
}
/**
* @brief This function handles TIM1 capture compare interrupt.
*/
void TIM1_CC_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_CC_IRQn 0 */
/* USER CODE END TIM1_CC_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
/* USER CODE BEGIN TIM1_CC_IRQn 1 */
/* USER CODE END TIM1_CC_IRQn 1 */
}
/**
* @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
*/

View File

@ -1,7 +1,9 @@
#MicroXplorer Configuration settings - do not modify
ADC3.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0
ADC3.Channel-IN0=ADC_CHANNEL_0
ADC3.IPParameters=Channel-IN0,Channel-0\#ChannelRegularConversion
ADC3.ExternalTrigConv=ADC_EXTERNALTRIGCONV_T1_CC1
ADC3.ExternalTrigConvEdge=ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING
ADC3.IPParameters=Channel-IN0,Channel-0\#ChannelRegularConversion,ExternalTrigConv,ExternalTrigConvEdge
FMC.CASLatency1=FMC_SDRAM_CAS_LATENCY_3
FMC.ExitSelfRefreshDelay1=7
FMC.IPParameters=CASLatency1,SDClockPeriod1,SDClockPeriod2,ReadBurst1,ReadBurst2,LoadToActiveDelay1,ExitSelfRefreshDelay1,SelfRefreshTime1,RowCycleDelay1,RowCycleDelay2,WriteRecoveryTime1,RPDelay1,RPDelay2,RCDDelay1
@ -148,10 +150,11 @@ Mcu.Pin171=VP_RTC_VS_RTC_Alarm_B_Intern
Mcu.Pin172=VP_RTC_VS_RTC_Alarm_A_Intern
Mcu.Pin173=VP_SYS_VS_tim6
Mcu.Pin174=VP_TIM1_VS_ClockSourceINT
Mcu.Pin175=VP_TIM2_VS_ClockSourceINT
Mcu.Pin176=VP_TIM3_VS_ClockSourceINT
Mcu.Pin177=VP_TIM5_VS_ClockSourceINT
Mcu.Pin178=VP_TIM8_VS_ClockSourceINT
Mcu.Pin175=VP_TIM1_VS_no_output1
Mcu.Pin176=VP_TIM2_VS_ClockSourceINT
Mcu.Pin177=VP_TIM3_VS_ClockSourceINT
Mcu.Pin178=VP_TIM5_VS_ClockSourceINT
Mcu.Pin179=VP_TIM8_VS_ClockSourceINT
Mcu.Pin18=PB9
Mcu.Pin19=PB7
Mcu.Pin2=PE2
@ -242,7 +245,7 @@ Mcu.Pin96=PF6
Mcu.Pin97=PF5
Mcu.Pin98=PH2
Mcu.Pin99=PJ6
Mcu.PinsNb=179
Mcu.PinsNb=180
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F746NGHx
@ -261,7 +264,6 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true
NVIC.TIM1_CC_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true
NVIC.TimeBase=TIM6_DAC_IRQn
NVIC.TimeBaseIP=TIM6
@ -1221,8 +1223,11 @@ SPI2.Direction=SPI_DIRECTION_2LINES
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
SPI2.Mode=SPI_MODE_MASTER
SPI2.VirtualType=VM_MASTER
TIM1.IPParameters=Prescaler
TIM1.Prescaler=0
TIM1.Channel-Output\ Compare1\ No\ Output=TIM_CHANNEL_1
TIM1.IPParameters=Prescaler,Period,Channel-Output Compare1 No Output,OCMode_1
TIM1.OCMode_1=TIM_OCMODE_TOGGLE
TIM1.Period=99
TIM1.Prescaler=199
TIM12.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
TIM12.IPParameters=Channel-PWM Generation1 CH1
TIM2.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
@ -1249,6 +1254,8 @@ VP_SYS_VS_tim6.Mode=TIM6
VP_SYS_VS_tim6.Signal=SYS_VS_tim6
VP_TIM1_VS_ClockSourceINT.Mode=Internal
VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT
VP_TIM1_VS_no_output1.Mode=Output Compare1 No Output
VP_TIM1_VS_no_output1.Signal=TIM1_VS_no_output1
VP_TIM2_VS_ClockSourceINT.Mode=Internal
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
VP_TIM3_VS_ClockSourceINT.Mode=Internal