[N32G03x] ADC定时器触发注入通道转换时刻点不正确

[复制链接]
1072|9
 楼主| 禁基的矮子 发表于 2022-9-6 10:36 | 显示全部楼层 |阅读模式
ADC注入通道设置为扫描模式,TIM1_CC4事件触发转换,但是使用示波器发现ADC转换的触发时刻是定时器更新事件,更换使用TIM8_CC4触发依旧是更新事件触发
芯路例程 发表于 2022-9-6 11:47 | 显示全部楼层
你是想设置成什么方式触发?
 楼主| 禁基的矮子 发表于 2022-9-6 12:21 | 显示全部楼层
芯路例程 发表于 2022-9-6 11:47
你是想设置成什么方式触发?

高级定时器控制电机,使用TIM1_CC4设置ADC采样点。
硬件触发的方式不正确的话,就准备用软件触发了
芯路例程 发表于 2022-9-6 13:35 | 显示全部楼层
禁基的矮子 发表于 2022-9-6 12:21
高级定时器控制电机,使用TIM1_CC4设置ADC采样点。
硬件触发的方式不正确的话,就准备用软件触发了 ...

所以你想通过设置TIM1_CC4来控制ADC的采样周期?
 楼主| 禁基的矮子 发表于 2022-9-6 13:35 | 显示全部楼层
本帖最后由 禁基的矮子 于 2022-9-6 13:39 编辑

这是我根据官方例程TIMTrigger_AutoInjection将规则通道取消后的测试代码
  1. #include "misc.h"
  2. #include "n32g031_adc.h"
  3. #include "n32g031_gpio.h"
  4. #include "n32g031_rcc.h"
  5. #include "n32g031_tim.h"

  6. ADC_InitType ADC_InitStructure;
  7. TIM_TimeBaseInitType TIM_TimeBaseStructure;
  8. OCInitType TIM_OCInitStructure;
  9. __IO uint16_t  ADC_InjectedConvertedValueTab[32];
  10. __IO uint32_t Index;

  11. void RCC_Configuration(void);
  12. void GPIO_Configuration(void);
  13. void NVIC_Configuration(void);

  14. int main(void)
  15. {
  16.     /* System clocks configuration ---------------------------------------------*/
  17.     RCC_Configuration();

  18.     /* NVIC configuration ------------------------------------------------------*/
  19.     NVIC_Configuration();

  20.     /* GPIO configuration ------------------------------------------------------*/
  21.     GPIO_Configuration();

  22.     /* TIM1 configuration ------------------------------------------------------*/
  23.     /* Time Base configuration */
  24.     TIM_InitTimBaseStruct(&TIM_TimeBaseStructure);
  25.     TIM_TimeBaseStructure.Period = 3000 - 1; // 0xFF;
  26.     TIM_TimeBaseStructure.Prescaler = 0;
  27.     TIM_TimeBaseStructure.ClkDiv = 0x0;
  28.     TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
  29.     TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure);
  30.     /* TIM1 channel1 configuration in PWM mode */
  31.     TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1;
  32.     TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE;
  33.     TIM_OCInitStructure.Pulse = 2400 - 1;
  34.     TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH;
  35.     TIM_InitOc4(TIM1, &TIM_OCInitStructure);

  36.     /* ADC configuration ------------------------------------------------------*/
  37.     ADC_InitStructure.MultiChEn = ENABLE;
  38.     ADC_InitStructure.ContinueConvEn = DISABLE;
  39.     ADC_InitStructure.ExtTrigSelect = ADC_EXT_TRIGCONV_NONE;
  40.     ADC_InitStructure.DatAlign = ADC_DAT_ALIGN_R;
  41.     ADC_InitStructure.ChsNumber = 1;
  42.     ADC_Init(ADC, &ADC_InitStructure);

  43.     /* Set injected sequencer length */
  44.     ADC_ConfigInjectedSequencerLength(ADC, 2);
  45.     /* ADC injected channel Configuration */
  46.     ADC_ConfigInjectedChannel(ADC, ADC_CH_0_PA0, 1, ADC_SAMP_TIME_6CYCLES5);
  47.     ADC_ConfigInjectedChannel(ADC, ADC_CH_1_PA1, 2, ADC_SAMP_TIME_6CYCLES5);
  48.     /* ADC injected external trigger configuration */
  49.     ADC_ConfigExternalTrigInjectedConv(ADC, ADC_EXT_TRIG_INJ_CONV_T1_CC4);
  50.     /* Enable automatic injected conversion start after regular one */
  51.     ADC_EnableAutoInjectedConv(ADC, DISABLE);
  52.     /* Enable JEOC interrupt */
  53.     ADC_ConfigInt(ADC, ADC_INT_JENDC, ENABLE);

  54.     /* Enable ADC external trigger */
  55.     ADC_EnableExternalTrigInjectedConv(ADC, ENABLE);

  56.     /* Enable ADC */
  57.     ADC_Enable(ADC, ENABLE);

  58.     /*wait ADC is ready to use*/
  59.     while (!ADC_GetFlagStatusNew(ADC, ADC_FLAG_RDY))
  60.         ;
  61.     /*wait ADC is powered on*/
  62.     while (ADC_GetFlagStatusNew(ADC, ADC_FLAG_PD_RDY))
  63.         ;

  64.     /* TIM1 counter enable */
  65.     TIM_Enable(TIM1, ENABLE);
  66.     /* TIM1 main Output Enable */
  67.     TIM_EnableCtrlPwmOutputs(TIM1, ENABLE);

  68.     while (1) {
  69.     }
  70. }

  71. /**
  72. * [url=home.php?mod=space&uid=247401]@brief[/url]  Configures the different system clocks.
  73. */
  74. void RCC_Configuration(void)
  75. {
  76.     ErrorStatus HSIStartUpStatus;
  77.     /* Enable peripheral clocks ------------------------------------------------*/
  78.     /* Enable TIM1 clocks */
  79.     RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1, ENABLE);

  80.     /* Enable GPIO clocks */
  81.     RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB, ENABLE);
  82.     /* Enable ADC clocks */
  83.     RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE);

  84.     /* RCC_ADCHCLK_DIV16*/
  85.     ADC_ConfigClk(ADC_CTRL3_CKMOD_AHB, RCC_ADCHCLK_DIV3);

  86.     /* enable ADC1M clock */
  87.     RCC_EnableHsi(ENABLE);

  88.     /* Wait til1 HSI is ready*/
  89.     HSIStartUpStatus = RCC_WaitHsiStable();
  90.     if (HSIStartUpStatus == SUCCESS) {
  91.     }
  92.     else {
  93.         /* If HSI fails to start-up, the application will have wrong clock configuration. User can add here some code to
  94.          * deal with this error*/
  95.         /* Go to infinital 1oop*/
  96.         while (1) {
  97.         }
  98.     }

  99.     RCC_ConfigAdc1mClk(RCC_ADC1MCLK_SRC_HSI, RCC_ADC1MCLK_DIV8);
  100. }

  101. /**
  102. * [url=home.php?mod=space&uid=247401]@brief[/url]  Configures the different GPIO ports.
  103. */
  104. void GPIO_Configuration(void)
  105. {
  106.     GPIO_InitType GPIO_InitStructure;

  107.     GPIO_InitStruct(&GPIO_InitStructure);
  108.     /* Configure TIM1_CH4(PA11) as alternate function push-pull */
  109.     GPIO_InitStructure.Pin = GPIO_PIN_11;
  110.     GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW;
  111.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
  112.     GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM1;
  113.     GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);

  114.     /* Configure PB.07 as output push-pull */
  115.     GPIO_InitStructure.Pin = GPIO_PIN_7;
  116.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
  117.     GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);

  118.     /* Configure PA.00 and PA.01 as analog input */
  119.     GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1;
  120.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG;
  121.     GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
  122. }

  123. /**
  124. * @brief  Configures NVIC and Vector Table base location.
  125. */
  126. void NVIC_Configuration(void)
  127. {
  128.     NVIC_InitType NVIC_InitStructure;

  129.     /* Configure and enable ADC interrupt */
  130.     NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
  131.     NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  132.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  133.     NVIC_Init(&NVIC_InitStructure);
  134. }

  135. /**
  136. * @brief  This function handles ADC global interrupts requests.
  137. */
  138. void ADC_IRQHandler(void)
  139. {
  140.     /* Set PA.06 pin */
  141.     GPIOB->PBSC = GPIO_PIN_7;
  142.     /* Get injected channel11 converted value */
  143.     if (Index >= sizeof(ADC_InjectedConvertedValueTab) / sizeof(ADC_InjectedConvertedValueTab[0])) {
  144.         Index = 0;
  145.     }
  146.     ADC_InjectedConvertedValueTab[Index++] = ADC_GetInjectedConversionDat(ADC, ADC_INJ_CH_1);
  147.     ADC_InjectedConvertedValueTab[Index++] = ADC_GetInjectedConversionDat(ADC, ADC_INJ_CH_2);
  148.     /* Clear ADC JEOC pending interrupt bit */
  149.     ADC_ClearIntPendingBit(ADC, ADC_INT_JENDC);
  150.     /* Reset PA.06 pin */
  151.     GPIOB->PBC = GPIO_PIN_7;
  152. }


  
 楼主| 禁基的矮子 发表于 2022-9-6 15:18 | 显示全部楼层
芯路例程 发表于 2022-9-6 13:35
所以你想通过设置TIM1_CC4来控制ADC的采样周期?

是通过TIM1_CC4控制ADC的采样时刻
芯路例程 发表于 2022-9-7 13:14 | 显示全部楼层
禁基的矮子 发表于 2022-9-6 15:18
是通过TIM1_CC4控制ADC的采样时刻

用到操作系统了吗?如果用到就在定时器里面发送一个信号量。
 楼主| 禁基的矮子 发表于 2022-9-7 21:26 | 显示全部楼层
芯路例程 发表于 2022-9-7 13:14
用到操作系统了吗?如果用到就在定时器里面发送一个信号量。

根据手册可以使用比较事件硬件触发,既然有问题,只好在比较中断中软件触发
芯路例程 发表于 2022-9-15 11:37 | 显示全部楼层
禁基的矮子 发表于 2022-9-7 21:26
根据手册可以使用比较事件硬件触发,既然有问题,只好在比较中断中软件触发 ...

是的,只能考虑这种方法了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

60

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部