我爱下载 发表于 2020-11-28 15:43

【AutoChips AC7801x电机demo板测评】+关键外设测试-ADC和PWM

<p style="text-indent: 21pt; text-align: center;">关键外设测试 - ADC和PWM</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">为了完成电机驱动测试,需要首先完成几个关键外设的驱动:包括AD采样,PWM输出控制,串口等,本次完成ADC采样和PWM驱动测试。</span></span></span></p>

<ol>
        <li style="text-align:justify"><span style="font-size:16pt"><span style="line-height:240%"><span style="font-family:宋体"><span style="font-weight:normal">AD数据采样</span></span></span></span></li>
</ol>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">为了贴近实际的使用,使用了AD的顺序转换和注入式转换配置。AC7801x中集成了一个12bit的ADC转换器,允许使用24MHz的时钟驱动。此AD支持8中模式配置</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">本次测试了Mode3注入组扫描模式,通过外部触发方式,规则组扫描采用DMA方式读取转换结果。</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">通过AutoGen Studio工具配置如下:</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">规则通道配置了IN8,IN9,IN10和内部温度传感器,注入组配置了IN4,IN5,IN6,IN7 。</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">DMA的通道配置:</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">由于DMA仅支持规则组的结果读取,所以只有规则组对应的通道结果才会不读入到指定的内存去中。</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">生成代码,并编译下载到微控制器中。通过串口终端可以读取到规则组中的4个通道的AD采样值。</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">其中IN9-电位器对应1组显示数据,通过调节电位器可以观察到采样值的变化。</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">说明我们的AD转换配置和DMA读取通道都是正常的。</span></span></span></p>

<p style="margin-left:28px; text-align:justify; text-indent:21pt"></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<ol start="2">
        <li style="text-align:justify"><span style="font-size:16pt"><span style="line-height:240%"><span style="font-family:宋体"><span style="font-weight:normal">定时器触发AD转换</span></span></span></span></li>
</ol>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">为了测试AD转换的外部定时器触发,初始化了TIMER0定时器通道和采集传输终端CTU。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">定时器的溢出信号可以作为AD转换的启动信号,CTU负责完成启动信号路由。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">通过AutoGen Studio产生TIMER0配置:</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">通过AutoGen Studio产生CTU配置:</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">可见CTU中将Timer Channel 0 Overflow信号路由到ADC Regular Group Trigger Source。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">生成驱动代码:</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">static void ATC_CTU_Init(void)</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">{</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN CTU_Init 0 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END CTU_Init 0 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; CTU_ConfigType ctuConfig;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN CTU_Init 1 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END CTU_Init 1 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.uart0RxFilterEn = DISABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.rtcCaptureEn = DISABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.acmpCaptureEn = DISABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.uart0RxCaptureEn = DISABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.uartTxModulateEn = DISABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.clkPsc = CTU_CLK_PRESCALER_1;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.adcRegularTriggerSource = CTU_TRIGGER_ADC_TIMER_CH0_OVERFLOW;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.delay0Time = 0;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.adcInjectTriggerSource = CTU_TRIGGER_ADC_PWM1_MATCH;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.delay1Time = 10;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp; &nbsp;ctuConfig.pwdt0In3Source = CTU_PWDT_IN3_SOURCE_UART0_RX;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ctuConfig.pwdt1In3Source = CTU_PWDT_IN3_SOURCE_UART0_RX;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; CTU_Init(&amp;ctuConfig);</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN CTU_Init 2 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END CTU_Init 2 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">}</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">static void ATC_TIMER0_Init(void)</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">{</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN TIMER0_Init 0 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END TIMER0_Init 0 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; TIMER_ConfigType timerConfig;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN TIMER0_Init 1 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END TIMER0_Init 1 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; MSP_TIMER_Init(TIMER_CHANNEL0);</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; timerConfig.timerEn = ENABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; timerConfig.interruptEn = ENABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; timerConfig.linkModeEn = DISABLE;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; timerConfig.periodValue = 119999;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; timerConfig.callBack = TIMER_CHANNEL0_IRQHandler_Callback;</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; TIMER_Init(TIMER_CHANNEL0, &amp;timerConfig);</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN TIMER0_Init 2 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END TIMER0_Init 2 */</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">}</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">这样就会完成AD的外部启动信号的配置,必须注意,AD需要选择外部触发信号元。</span></span></span></p>

<ol start="3">
        <li style="text-align:justify"><span style="font-size:16pt"><span style="line-height:240%"><span style="font-family:宋体"><span style="font-weight:normal">互补式PWM信号输出配置</span></span></span></span></li>
</ol>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">PWM信号输出是直流无刷电机驱动的基础功能,互补式PWM信号输出是一个特定应用方式,尤其是FOC驱动方式中,不可或缺。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">AC7801x微控制器集成了两个PWM发生器,分别为PWM0和PWM1,这里使用PWM1作为目标对象测试。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">配置PWM的周期为15KHz,3组互补信号输出,1us死区时间,占空比80%。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">通过AutoGen Studio配置:</span></span></span></p>

<p style="text-align:justify; text-indent:21pt"></p>

<p style="text-align:justify; text-indent:21pt"></p>

<p style="text-align:justify; text-indent:21pt"></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">在Channel0-1 Setup中,必须配置CHannel0 And Channel1 Mode Select为Combine模式才表示通道0和通道1是互补输出模式。</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; 生成驱动代码:</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">static void ATC_PWM1_Init(void)</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">{</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN PWM1_Init 0 */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; uint32_t ch1_count,ch2_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ch2_count = (MOD_PWM &gt;&gt; 1) * 80 /100;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; ch1_count = MOD_PWM - ch2_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END PWM1_Init 0 */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; PWM_ConfigType pwmConfig;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; PWM_ModulationConfigType initModeStruct;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN PWM1_Init 1 */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; </span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END PWM1_Init 1 */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; MSP_PWM_Init(PWM1);</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.mode = PWM_MODE_MODULATION;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.clkSource = PWM_CLK_SOURCE_APB;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.clkPsc = PWM_PRES;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.initValue = 0;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.maxValue = MOD_PWM-1;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.overflowInterrupEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.cntOverflowFreq = 0;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.interruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.countMode = PWM_UP_COUNT;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.deadtime = 24;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.deadtimePsc = PWM_DEADTIME_DIVID_1;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.initChOutputEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.initTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; PWM_CombineChConfig combineChConfig;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* combine channel 0 and channel 1 configuration */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.pairChannel = PWM_CH_0;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stValue = ch1_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndValue = ch2_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.levelMode = PWM_HIGH_TRUE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.deadtimeEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.complementEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stMatchDir = PWM_MATCH_DIR_DOWN;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndMatchDir = PWM_MATCH_DIR_DOWN;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stInterruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndInterruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stInitLevel = PWM_LOW_LEVEL;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndInitLevel = PWM_LOW_LEVEL;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* combine channel 2 and channel 3 configuration */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.pairChannel = PWM_CH_2;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp; &nbsp;combineChConfig.ch1stValue = ch1_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndValue = ch2_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.levelMode = PWM_HIGH_TRUE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.deadtimeEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.complementEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stMatchDir = PWM_MATCH_DIR_UP;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndMatchDir = PWM_MATCH_DIR_DOWN;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stInterruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndInterruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stInitLevel = PWM_HIGH_LEVEL;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndInitLevel = PWM_HIGH_LEVEL;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* combine channel 4 and channel 5 configuration */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.pairChannel = PWM_CH_4;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stValue = ch1_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndValue = ch2_count;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.levelMode = PWM_HIGH_TRUE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.deadtimeEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.complementEn = ENABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stMatchDir = PWM_MATCH_DIR_DOWN;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndMatchDir = PWM_MATCH_DIR_DOWN;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stInterruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndInterruptEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stInitLevel = PWM_HIGH_LEVEL;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndInitLevel = PWM_HIGH_LEVEL;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch1stTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; combineChConfig.ch2ndTriggerEn = DISABLE;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.combineChannelNum = 3;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; initModeStruct.combineChConfig = combineChConfig;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; pwmConfig.initModeStruct = &amp;initModeStruct;</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; PWM_Init(PWM1, &amp;pwmConfig);</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE BEGIN PWM1_Init 2 */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; /* USER CODE END PWM1_Init 2 */</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">}</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">编译下载到微控制器中,通过示波器我们可以观察PWM的一组互补输出波形。</span></span></span></p>

<p style="text-indent:0cm; text-align:justify">&nbsp;</p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">其中蓝色为通道0,黄色为通道1,从图种可以看到,两个波形为互补输出模式,下面的A通道和B通道的输出信息总结都可以看到,信号频率为15KHz,占空比接近80%(由于示波器带宽不足导致测试结果误差)。</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"></p>

<p style="text-indent:0cm; text-align:justify"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">&nbsp;&nbsp;&nbsp; 这幅图中,放大互补信号波形,我们测量A通道下降沿到B通道上升沿的时间,可见测试时间接近1us的时间,这个时间就是死区时间,验证了我们的配置参数。</span></span></span></p>

<p style="text-indent:0cm; text-align:justify"></p>

<p style="text-align:justify; text-indent:21pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">通过上面关键外设的测试研究,基本摸清了AC7801x外设的使用方法,对于后面电机驱动的研究扫清了硬件驱动部分的障碍。下一步对霍尔信号的采样进行研究测试。</span></span></span></p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

<p style="text-align:justify; text-indent:21pt">&nbsp;</p>

w494143467 发表于 2020-11-28 16:04

<p>关键外设测评的不错哈,后面我应该会用到。</p>

我爱下载 发表于 2020-11-28 21:05

w494143467 发表于 2020-11-28 16:04
关键外设测评的不错哈,后面我应该会用到。

<p>希望对大家有益,共同学习讨论</p>

freebsder 发表于 2020-11-29 11:38

<p>和st好像,连USER CODE BEGIN 、&nbsp;USER CODE END都如此像</p>

我爱下载 发表于 2020-12-1 07:59

freebsder 发表于 2020-11-29 11:38
和st好像,连USER CODE BEGIN 、&nbsp;USER CODE END都如此像

<p>不管是不是抄来的,重要的是它具备了这样的功能,这就是进步,先有,在超越,这个思路对</p>

freebsder 发表于 2020-12-1 15:20

我爱下载 发表于 2020-12-1 07:59
不管是不是抄来的,重要的是它具备了这样的功能,这就是进步,先有,在超越,这个思路对

<p>等ST再继续涨价,以后就可以pin2pin,code2code替换了。</p>

zxopenljx 发表于 2021-4-22 17:29

<p>谢谢分享</p>
页: [1]
查看完整版本: 【AutoChips AC7801x电机demo板测评】+关键外设测试-ADC和PWM