完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,
我正在尝试使用stm8s Discovery开发板为爱好级RC-UAV设计稳定系统。 现在我只是想让mcu: 1)按时和关闭时间捕获输入信号,并将它们存储在各自的变量中。 2)输出与输入相同的PWM信号,并调整导通时间和关断时间。 到目前为止,我还没有取得任何成功,如果有人有任何建议或建议,我将不胜感激。我最接近工作的代码是固件附带的tiM1或2输入捕获示例。这是我使用的部分的副本。 / ** ************************************************** **************************** * @file TIM2_Input_Capture main.c * @brief此文件包含TIM2输入捕获示例的主要功能。 * @author STMicroelectronics - MCD应用团队 * @version V1.1.1 * @date 06/05/2009 ************************************************** **************************** * *仅用于提供客户的目标的现有固件 *提供关于他们的产品的编码信息,以便他们保存 * 时间。因此,STMICROELECTRONICS不承担任何责任 *针对任何索赔引起的直接,间接或间接损害 *从这些固件的内容和/或由客户的使用 *与此处包含的产品相关的编码信息。 * *< h2>< center>& copy; COPYRIGHT 2009 STMicroelectronics< / center>< / h2> * @image html logo.bmp ************************************************** **************************** * / / *包括----------------------------------------------- ------------------- * / #include''stm8s.h'' / ** * @addtogroup TIM2_Input_Capture * @ { * / / * Private typedef ---------------------------------------------- ------------- * / / * Private define ---------------------------------------------- -------------- * / #define TIM2ClockFreq((u32)2000000) / * Private macro ---------------------------------------------- --------------- * / / *私有变量---------------------------------------------- ----------- * / u32 LSIClockFreq = 0; u16 ICValue1 = 0,ICValue2 = 0; void main(void) { / *每8个事件只捕获一次! * / / *启用TI1的捕获* / TIM2_ICInit(TIM2_CHANNEL_1,TIM2_ICPOLARITY_FALLING,TIM2_ICSELECTION_DIRECTTI,TIM2_ICPSC_DIV8,0x00); / *启用CC1中断* / TIM2_ITConfig(TIM2_IT_CC1,ENABLE); / *启用TIM2 * / TIM2_Cmd(ENABLE); / *清除CC1标志* / TIM2_ClearFlag(TIM2_FLAG_CC1); / *将LSI连接到COO引脚* / GPIO_Init(GPIOE,GPIO_PIN_0,GPIO_MODE_OUT_PP_LOW_FAST); CLK_CCOConfig(CLK_OUTPUT_LSI); CLK_CCOCmd(ENABLE); / *在CC1上等待捕获* / while((TIM2-> SR1& TIM2_FLAG_CC1)!= TIM2_FLAG_CC1); / *获得CCR1值* / ICValue1 = TIM2_GetCapture1(); TIM2_ClearFlag(TIM2_FLAG_CC1); / *等待cc1上的捕获* / while((TIM2-> SR1& TIM2_FLAG_CC1)!= TIM2_FLAG_CC1); / *获得CCR1值* / ICValue2 = TIM2_GetCapture1(); TIM2_ClearFlag(TIM2_FLAG_CC1); / *计算LSI时钟频率* / LSIClockFreq =(8 * TIM2ClockFreq)/(ICValue2 - ICValue1); / *在这里插入一个断点* / 而(1); } 以上来自于谷歌翻译 以下为原文 Hello, I'm attempting to design a stabilization system for a hobby level RC-UAV, using stm8s Discovery dev board. Right Now I'm just trying to get the mcu to: 1)Capture the input signals on-time and off-time, and store them in respective variables. 2)Output a PWM signal that identical to the input, as well as adjust the on-time and off-time to match. So far I haven't had any success, if anybody has any suggestions or advice it would be much appreciated. The code that I have gotten the closest to working is the TIM1 or 2 Input capture example included with the firmware. Here's a copy of the portion I use. /** ****************************************************************************** * @file TIM2_Input_Capturemain.c * @brief This file contains the main function for TIM2 Input Capture example. * @author STMicroelectronics - MCD Application Team * @version V1.1.1 * @date 06/05/2009 ****************************************************************************** * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * |
|
相关推荐
11个回答
|
|
嗨Mken,
我记得我使用过这个例子,它运行正常! mitbestengrüssen, mcu粉丝 以上来自于谷歌翻译 以下为原文 Hi Mken, I remember that I have used this example and it works fine ! mit besten grüssen, mcu fan |
|
|
|
现在的例子是它将在第一个CC1 FLag有效且SR1为低电平时启动CC1定时器并将其值记录到ICValue1,然后它将在CC1标志有效且SR1为低电平时记录第二个实例并将其值记录到ICValue2但是如果您使用调试器并观察ICValue1,ICValue2,LSICLKFreq,并添加另一个在x =(ICValue2 - ICValue1)等方程式中使用的变量,您会注意到ICValue1的值为y,而ICValue2将具有y + y的值。
但是,如果你在不同的通道上输出带有PWM输出的GPIO和LSI输出命令,并说将PWM设置为50Hz并且开启时间为10%,并试着让这个例子告诉你准时或你的关机 - 时间,它不能这样做,因为它计算整个周期,如果它在第一个下降沿开始计数,那么在第二个下降沿,它采用新的计数器值,这是一个整个脉冲周期,在50Hz是40000计数。 这不是我想要完成的,我想捕获输入准时的数量,将其存储在变量中,然后重置计数器(因为我只能使用每个通道的一个定时器通道)接收器)捕获输入关闭时间的计数并将其存储在不同的变量中,将两个变量加在一起得到脉冲周期,这样我就可以将它用于PWM输出预分频器周期,然后使用其中任何一个 - 时间变量或关闭时间变量来控制PWM输出的占空比,并且捕获计数器仍然是动态的,因此如果脉冲的导通时间改变,输出的导通时间会改变相同的量。 以上来自于谷歌翻译 以下为原文 As the example is now it will start the CC1 timer on the first CC1 FLag active and SR1 low and record its value to ICValue1, then it will record the second instance when CC1 Flag is active and SR1 is low and record its value to ICValue2 however if you use the debugger and watch ICValue1, ICValue2, LSICLKFreq, and add in another variable that is used in an equations such as x = (ICValue2 - ICValue1) you'll notice that ICValue1 will have a value of y and ICValue2 will have a value of y+y. However if you switch out the GPIO and LSI output commands with a PWM out on a different channel and say set the PWM out to 50Hz with a 10% on-time and try to have this example tell you either your on-time or your off-time, it can't do it because it counts for the whole cycle, as in if it starts counting at the first falling edge then on the 2nd falling edge it takes the new counter value which is one entire pulse period which at 50Hz is 40000 counts. Which isn't what I'm trying to accomplish, I want to capture the number of counts the inputs on-time is store it in a variable then reset the counter (since I can only use one channel of the timers per channel of the reciever) and capture the number of counts the input off-time is and store it in a different variable, add the two variables together to get the pulses period so I could use it for the PWM out prescaler period, and then use either the on-time variable or the off-time variable to control the duty-cycle of the PWM out, and still have the Capture counter be dynamic so if the on-time of the pulse changes the on-time of the output changes the same amount. |
|
|
|
嗨Mken C-学习者,
我不明白你对这个例子的解释。 我对这个例子的理解是: 定时器2通道1配置为在下降沿捕获外部信号,输入中的信号除以8。 执行该功能时,定时器2(TIM2)计数器开始计数:TIM2_Cmd(ENABLE); 当检测到下降沿时,CC1标志置1,当执行ICValue1 = TIM2_GetCapture1()时,CCR1寄存器存储在ICValue1中; 当检测到第二个下降沿时,CC1再次置位,当执行ICValue2 = TIM2_GetCapture1()时,CCR1寄存器存储在ICValue2中; PS:当CC1置位时,计数器值自动保存在CCR1寄存器中 我希望这有帮助。 Mitbestengrüssen, MCU风扇 以上来自于谷歌翻译 以下为原文 Hi Mken C- learner, I don't understand your interpretation of the example. My own understanding of the example is: Timer 2 channel 1 is configured to capture external signal on falling edge, the signal in input is divided by 8. The timer 2 (TIM2) counter starts counting when executing this function: TIM2_Cmd(ENABLE); when a falling edge is detected the CC1 flag is set and CCR1 register is stored in ICValue1 when executing ICValue1 = TIM2_GetCapture1(); when the second falling edge is detected the CC1 is set again and CCR1 register is stored in ICValue2 when executing ICValue2 = TIM2_GetCapture1(); PS: when the CC1 is set the counter value is automatically saved in the CCR1 register I hope this helps. Mit besten grüssen, MCU fan |
|
|
|
我的道歉我没有仔细查看rm0016文档以了解CC1标志是如何工作的,我想说的是当CC1的标志处于活动状态时它将值存储在ICValue1中它不会重置计数器下一个Flag激活。基本上,如果CC1标志在15000计数时被激活,那么该值存储在ICValue1中,但是在捕获之后计数器被重置,这样当CC1标志被激活时,第二次从45000开始计数,那么该值被放入ICValue2 ,并且计数器重置的唯一时间是它溢出时。
我想要做的是在下降沿或上升沿(我决定将其设置为)启动计数器,并在相反的边沿重置计数器。 因此,例如我想要做的是,当检测到上升沿时,计数器开始,然后在下降沿,计数器停止,然后该值被置于ICValue1中,并且计数器在下降沿重新启动,然后在下一个上升沿停止,捕获并保存到ICValue2,并在下一个脉冲周期再次重复该循环。 在看完RM0016文档后,我发现了PWM输入示例,但它只能用于TIM1上通道1或通道2的输入,但我需要使用4个通道,因为来自RC接收器的信号是设置为当CH1的脉冲变低时,CH2的脉冲变为高电平,当CH2的脉冲变为低电平时,CH3的脉冲变为高电平,等等8个通道,尽管我只会使用其中的4个。 这里是来自接收器的伺服脉冲的图像。 以下是我想尝试捕捉信号的方法。 如果图片尺寸太大,我道歉。 以上来自于谷歌翻译 以下为原文 My apologys I hadn't looked through the rm0016 document well enough to understand how the CC1 Flag worked, what I'm trying to say is that when CC1's Flag is active and it stores the value in ICValue1 it doesn't reset the counter on the next Flag activation. Basicly if CC1 flag is activated at say 15000 counts, that value is stored in ICValue1, but the counter is reset after the capture so that when the CC1 flag is activated a second time at 45000 counts from start, then that value gets placed into ICValue2, and the only time the counter gets reset is when it overflows. What I'm wanting to do is start the counter at either the falling edge or the rising edge (which ever I decide to set it to) and have the counter reset on the opposite edge. So for example of what I'd Like to do is, when a rising edge is detected the counter starts, then at the falling edge the counter stops then that value is placed in ICValue1 and the counter is restarted at the falling edge and is then stopped at the next rising edge, captured and saved to ICValue2, and the cycle is repeated again for the next pulse cycle. Also after looking threw the RM0016 document I found the PWM input example that does just that HOWEVER it only works for input on channel 1 or channel 2 on TIM1 but I need to use 4 channels, since the the signals coming from my RC-receiver are set up so that when CH1's pulse goes low CH2's pulse goes high, and when CH2's pulse goes low CH3's pulse goes high, and so on for 8 channels although I'm only gonna use 4 of them. Here an image of the servo pulses from the receiver. And here is how I wanna try and capture the signals. I apologize if the images are oversized. |
|
|
|
嗨Mken C-学习者,
如果有什么东西可以帮助你,我在参考手册中寻找过。 PWM输入无法帮助您,因为它会计算周期报告和总周期,但您在应用中需要的是测量高低电平持续时间。不是吗? 但我有一个问题:为什么你不ICValue 2 - ICValaue1你有你需要的持续时间? 如果上面的解决方案不适合你,我可以建议在参考手册中查找如何使用SMCR寄存器中的触发器选择“TS”位来帮助你,因为有关如何重置计数器的描述外部事件。 如果您有更新/问题,请随时通知我? Mitbestengrüssen, MCU风扇 以上来自于谷歌翻译 以下为原文 Hi Mken C- learner, I have looked for in the reference manual if something could help you. PWM input couldn't help you because it counts the cycle report and total period but what you need in your application is measuring both high and low levels duration. Isn't it ? But I have a question: why you don't ICValue 2 - ICValaue1 and you have the duration you need ? If the solution above isn't suitable for you, I can suggest to look for in the reference manual how to use the trigger selection ''TS'' bits in SMCR register it could help you because there description on how to reset the counter on external event. Keep me informed if you have updates / questions ? Mit besten grüssen, MCU fan |
|
|
|
感谢lowpowermcu的帮助,使用ICValue2 - ICValue1只能工作到一定程度,因为计数器不会复位,直到溢出导致两个变量中的随机数。
然而,我确实设法让它得到90%的计算,我现在有了它可以复制并匹配4个输入中的2.5个,通道3和4完美地工作但是通道2正在改变ch1命令而ch1正好被正确捕获相反,ch1正在计算从高脉冲到高脉冲的整个周期.... EUREKA! 我只是弄清楚如何做到这一点,这里是代码的副本,有一些不需要的变量我只是用它们来试图找出如何复制输入循环时间来清理和稳定输出。由于我的副本并将它们从示例代码中粘贴而不修改它们,因此某些注释也不正确。 #include''stm8s.h'' u16 CH1on = 0,CH2on = 0,CH3on = 0,CH4on = 0; u16 CH1ontime = 0,CH2ontime = 0,CH3ontime = 0,CH4ontime = 0; u16 dtcy = 0,periodcount = 39999,periodcountX = 0,periodcounty = 0,periodcountz = 0; void main(void){ TIM1_DeInit(); / *启用捕获* / TIM1_ICInit(TIM1_CHANNEL_1,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_2,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_3,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_4,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); / *设置TIM1 SMCR寄存器以触发Ch1 Rising Edge上的计数器复位* / TIM1-> SMCR = 0x44; / *启用TIM2 * / TIM1_Cmd(ENABLE); / *启用CC1中断* / TIM1_ITConfig(TIM1_IT_CC1,ENABLE); TIM1_ITConfig(TIM1_IT_CC2,ENABLE); TIM1_ITConfig(TIM1_IT_CC3,ENABLE); TIM1_ITConfig(TIM1_IT_CC4,ENABLE); / *清除CC1标志* / TIM1_ClearFlag(TIM1_FLAG_CC1); TIM1_ClearFlag(TIM1_FLAG_CC2); TIM1_ClearFlag(TIM1_FLAG_CC3); TIM1_ClearFlag(TIM1_FLAG_CC4); TIM2_DeInit(); TIM3_DeInit(); for(;;){ while((TIM1-> SR1& TIM1_FLAG_CC1)!= TIM1_FLAG_CC1); / *获得CCR1值* / CH1ontime = TIM1_GetCapture1(); TIM1_ClearFlag(TIM1_FLAG_CC1); while((TIM1-> SR1& TIM1_FLAG_CC2)!= TIM1_FLAG_CC2); / *获得CCR1值* / CH2on = TIM1_GetCapture2(); TIM1_ClearFlag(TIM1_FLAG_CC2); while((TIM1-> SR1& TIM1_FLAG_CC3)!= TIM1_FLAG_CC3); / *获得CCR1值* / CH3on = TIM1_GetCapture3(); TIM1_ClearFlag(TIM1_FLAG_CC3); while((TIM1-> SR1& TIM1_FLAG_CC4)!= TIM1_FLAG_CC4); / *获得CCR1值* / CH4on = TIM1_GetCapture4(); TIM1_ClearFlag(TIM1_FLAG_CC4); periodcountX =(CH2on + CH2ontime); periodcounty =(CH3on + CH3ontime); periodcountz =(CH4on + CH4ontime); CH2ontime =(periodcount-CH2on); CH3ontime =(periodcount-(CH3on-CH2on)); CH4ontime =(periodcount-(CH4on-CH3on)); / * TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); * / TIM2_TimeBaseInit(TIM2_PRESCALER_1,periodcount); //初始化TIM3的输出通道2。 TIM2_OC3Init(TIM2_OCMODE_PWM1,TIM2_OUTPUTSTATE_ENABLE,CH1on,TIM2_OCPOLARITY_LOW); //初始化TIM3的输出通道2。 TIM2_OC1Init(TIM2_OCMODE_PWM1,TIM2_OUTPUTSTATE_ENABLE,CH2ontime,TIM2_OCPOLARITY_LOW); //启用TIM3。 TIM2_Cmd(ENABLE); / * TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); * / TIM3_TimeBaseInit(TIM3_PRESCALER_1,periodcount); //初始化TIM3的输出通道2。 TIM3_OC2Init(TIM3_OCMODE_PWM1,TIM3_OUTPUTSTATE_ENABLE,CH3ontime,TIM3_OCPOLARITY_LOW); //初始化TIM3的输出通道2。 TIM3_OC1Init(TIM3_OCMODE_PWM1,TIM3_OUTPUTSTATE_ENABLE,CH4ontime,TIM3_OCPOLARITY_LOW); //启用TIM3。 TIM3_Cmd(ENABLE); } } 以上来自于谷歌翻译 以下为原文 Thanks lowpowermcu for the help, using ICValue2 - ICValue1 only works to a degree since the counter doesn't reset until overflow which causes random numbers in both variables. However I did manage to get it 90% figured out, I have it now where the mcu can replicate and match 2.5 of the 4 inputs, channels 3 and 4 work perfectly but channel 2 is changing with ch1 commands and ch1 simply is being captured correctly, instead ch1 is counting the entire period from high pulse to high pulse.... EUREKA!! I just figured out how to do it, here's a copy of the code there are a few variables that aren't needed I'm just using them to try and figure out how to duplicate the inputs cycle time to clean up and stabilize the outputs. Also some of the comments are incorrect due to my copy and pasting them from the example code and not modifying them. #include ''stm8s.h'' u16 CH1on =0, CH2on =0, CH3on = 0, CH4on = 0; u16 CH1ontime = 0, CH2ontime = 0, CH3ontime = 0, CH4ontime = 0; u16 dtcy = 0, periodcount = 39999, periodcountX = 0, periodcounty = 0, periodcountz = 0; void main(void){ TIM1_DeInit(); /* Enable capture*/ TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_2, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_3, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_4, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); /*Set TIM1 SMCR register to trigger counter reset on Ch1 Rising Edge*/ TIM1->SMCR = 0x44; /* Enable TIM2 */ TIM1_Cmd(ENABLE); /* Enable CC1 interrupt */ TIM1_ITConfig(TIM1_IT_CC1, ENABLE); TIM1_ITConfig(TIM1_IT_CC2, ENABLE); TIM1_ITConfig(TIM1_IT_CC3, ENABLE); TIM1_ITConfig(TIM1_IT_CC4, ENABLE); /* Clear CC1 Flag*/ TIM1_ClearFlag(TIM1_FLAG_CC1); TIM1_ClearFlag(TIM1_FLAG_CC2); TIM1_ClearFlag(TIM1_FLAG_CC3); TIM1_ClearFlag(TIM1_FLAG_CC4); TIM2_DeInit(); TIM3_DeInit(); for (;;){ while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1); /* Get CCR1 value*/ CH1ontime = TIM1_GetCapture1(); TIM1_ClearFlag(TIM1_FLAG_CC1); while((TIM1->SR1 & TIM1_FLAG_CC2) != TIM1_FLAG_CC2); /* Get CCR1 value*/ CH2on = TIM1_GetCapture2(); TIM1_ClearFlag(TIM1_FLAG_CC2); while((TIM1->SR1 & TIM1_FLAG_CC3) != TIM1_FLAG_CC3); /* Get CCR1 value*/ CH3on = TIM1_GetCapture3(); TIM1_ClearFlag(TIM1_FLAG_CC3); while((TIM1->SR1 & TIM1_FLAG_CC4) != TIM1_FLAG_CC4); /* Get CCR1 value*/ CH4on = TIM1_GetCapture4(); TIM1_ClearFlag(TIM1_FLAG_CC4); periodcountX = (CH2on + CH2ontime); periodcounty = (CH3on + CH3ontime); periodcountz = (CH4on + CH4ontime); CH2ontime = (periodcount-CH2on); CH3ontime = (periodcount-(CH3on - CH2on)); CH4ontime = (periodcount-(CH4on - CH3on)); /*TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1,0);*/ TIM2_TimeBaseInit(TIM2_PRESCALER_1, periodcount); // Initialise output channel 2 of TIM3. TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, CH1on, TIM2_OCPOLARITY_LOW); // Initialise output channel 2 of TIM3. TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, CH2ontime, TIM2_OCPOLARITY_LOW); // Enable TIM3. TIM2_Cmd(ENABLE); /*TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1,0);*/ TIM3_TimeBaseInit(TIM3_PRESCALER_1, periodcount); // Initialise output channel 2 of TIM3. TIM3_OC2Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE, CH3ontime, TIM3_OCPOLARITY_LOW); // Initialise output channel 2 of TIM3. TIM3_OC1Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE, CH4ontime, TIM3_OCPOLARITY_LOW); // Enable TIM3. TIM3_Cmd(ENABLE); } } |
|
|
|
嗨Mken,
在下沉代码之前我有一个问题。 测量伺服脉冲时需要的精度是多少?要测量的PWM信号的最小值,最大值和步长是多少?它是一些Âμs还是ms?你的时钟配置怎么样? 这个细节可以大大简化您的代码。 带着敬意, MCU风扇 以上来自于谷歌翻译 以下为原文 Hi Mken, I have a question before sinking in the code. What is the precision that you need when measuring the servo pulses ? What is the minimum, maximum and steps of the PWM signals to be measured ? Is it of some µs or ms ? what about your clock configuration ? This detail could considerably simplify your code. With regards, MCU fan |
|
|
|
我现在找不到它,但我记得读过5uS相当于伺服的1度,我将运行无刷电机,但它们仍然使用与rc伺服相同的精确脉冲。最小导通时间为1mS中性为1.5mS,最大为2ms,我希望它尽可能精确。至于时钟,我有定时器运行在默认的2MHz,如果PWMIConfig命令不仅仅适用于TIM1 CH1或TIM1 CH2,代码可以很好地简化为可能的6-10行,因为它使用互补通道但触发器仅适用于TI1F_ED,TI1FP1和TI2FP2,这也是我实际获得代码同时使用所有4个通道的唯一方法,尽管到目前为止它只能在示波器上产生良好的脉冲,试过它在某些伺服系统和伺服系统上都摆动到最大限度,即使控制器设置在空档位置,也不会响应任何指令信号。
以上来自于谷歌翻译 以下为原文 I can't find it at the moment but I remember reading that 5uS is equivalent to 1 degree on the servo, I'll be running Brushless motors but they still use the same exact pulses as a rc servo. The minimum ontime is 1mS neutral is 1.5mS and Maximum is 2ms, I want it as precise as possible. As for the clock I have the Timers running at default 2MHz, the code could very well be simplified down to possible 6-10lines if the PWMIConfig command didn't ONLY work for TIM1 CH1 or TIM1 CH2 since it uses the complementary channel but the trigger is only available for TI1F_ED, TI1FP1, and TI2FP2, also the fact that this is the only way I've actually gotten the code to work with all 4 channels at once, although so far it ONLY produces a good pulse on the oscilliscope, tryed it on some servos and the servos all swing to max limit one way and don't respond to any command signals even with the controls set to neutral position. |
|
|
|
嗨Mken,
我还有一个问题是四个信号之间是否存在同步或它们是独立的? 如上图所示,pwm帧是否恒定:22.5ms。如果您需要关闭时间的情况,您需要准时,您可以从开启时间提取帧持续时间来计算关闭时间???? 我想了解更多你的应用程序,所以我可以建议你更好的配置计时器。 Mitbestengrüssen, MCULüfter 以上来自于谷歌翻译 以下为原文 Hi Mken, I have an other question is there a synchronization between the four signals or they are independent ? Is the pwm frame constant as you have drawn in the figure above: 22.5ms. If it the case why you need the off-time, you need the on-time and you can sustract the frame duration from the on-time to compute the off-time ???? I am trying to understand more your application so I can suggest you the better config for timer. Mit besten grüssen, MCU Lüfter |
|
|
|
我不确定你的信号同步是什么意思。
至于id,pwm帧是常数是和否,是它的常数但是它准确地接近20ms,并且没有因为它确实稍微移动但仅移动了1ms。 我原本想要关机时间,因为那是我唯一能够获得1ms-2ms导通时间输出,没有意识到输出上的pwm模式2是一个更好的选择,我已经切换输出pwm1模式到pwm2这是一个很好的工作,因为我可以直接将cptured值发送到输出,ch3和4中有一些例外,因为ch2之后的捕获因此它们的值是先前通道和那个通道组合的总和所以有一点数学但不多。 我还修复了大部分伺服信号输出,除了CH1它现在可以工作但是不正确,而不是停留在说它振荡的中性伺服位置但是我使用TI1F_ED在脉冲序列开始时复位计数器将其精确定位给我,仍然能够获得CH1的可用捕获值。 这是一个包含所有更新的修订版本。 #include''stm8s.h'' u16 CH1on = 0,CH2on = 0,CH3on = 0,CH4on = 0; u16 CH1ontime = 0,CH2ontime = 0,CH3ontime = 0,CH4ontime = 0; u16 dtcy = 0,periodcount = 40100,periodcountX = 0,periodcounty = 0,periodcountz = 0; void main(void){ TIM1_DeInit(); / *启用捕获* / TIM1_ICInit(TIM1_CHANNEL_1,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV8,0); TIM1_ICInit(TIM1_CHANNEL_2,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_3,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_4,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); / *设置TIM1 SMCR寄存器以触发Ch1 Rising Edge上的计数器复位* / TIM1-> SMCR = 0x44; / *启用TIM2 * / TIM1_Cmd(ENABLE); / *启用CC1中断* / TIM1_ITConfig(TIM1_IT_CC1,ENABLE); TIM1_ITConfig(TIM1_IT_CC2,ENABLE); TIM1_ITConfig(TIM1_IT_CC3,ENABLE); TIM1_ITConfig(TIM1_IT_CC4,ENABLE); / *清除CC1标志* / TIM1_ClearFlag(TIM1_FLAG_CC1); TIM1_ClearFlag(TIM1_FLAG_CC2); TIM1_ClearFlag(TIM1_FLAG_CC3); TIM1_ClearFlag(TIM1_FLAG_CC4); TIM2_DeInit(); TIM3_DeInit(); for(;;){ while((TIM1-> SR1& TIM1_FLAG_CC1)!= TIM1_FLAG_CC1); / *获得CCR1值* / CH1on = TIM1_GetCapture1(); TIM1_ClearFlag(TIM1_FLAG_CC1); while((TIM1-> SR1& TIM1_FLAG_CC2)!= TIM1_FLAG_CC2); / *获得CCR1值* / CH2on = TIM1_GetCapture2(); TIM1_ClearFlag(TIM1_FLAG_CC2); while((TIM1-> SR1& TIM1_FLAG_CC3)!= TIM1_FLAG_CC3); / *获得CCR1值* / CH3on = TIM1_GetCapture3(); TIM1_ClearFlag(TIM1_FLAG_CC3); while((TIM1-> SR1& TIM1_FLAG_CC4)!= TIM1_FLAG_CC4); / *获得CCR1值* / CH4on = TIM1_GetCapture4(); TIM1_ClearFlag(TIM1_FLAG_CC4); periodcountX =(CH2on + CH2ontime); periodcounty =(CH3on + CH3ontime); periodcountz =(CH4on + CH4ontime); CH3ontime =(CH3on-CH2on); CH4ontime =(CH4on-CH3on); / * TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); * / TIM2_TimeBaseInit(TIM2_PRESCALER_1,periodcount); //初始化TIM3的输出通道2。 TIM2_OC3Init(TIM2_OCMODE_PWM1,TIM2_OUTPUTSTATE_ENABLE,CH1on,TIM2_OCPOLARITY_LOW); //初始化TIM3的输出通道2。 TIM2_OC1Init(TIM2_OCMODE_PWM2,TIM2_OUTPUTSTATE_ENABLE,CH2on,TIM2_OCPOLARITY_LOW); //启用TIM3。 TIM2_Cmd(ENABLE); / * TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); * / TIM3_TimeBaseInit(TIM3_PRESCALER_1,periodcount); //初始化TIM3的输出通道2。 TIM3_OC1Init(TIM3_OCMODE_PWM2,TIM3_OUTPUTSTATE_ENABLE,CH3ontime,TIM3_OCPOLARITY_LOW); //初始化TIM3的输出通道2。 TIM3_OC2Init(TIM3_OCMODE_PWM2,TIM3_OUTPUTSTATE_ENABLE,CH4ontime,TIM3_OCPOLARITY_LOW); //启用TIM3。 TIM3_Cmd(ENABLE); } } 以上来自于谷歌翻译 以下为原文 I'm not sure what you mean by synchronization of the signals. As for id the pwm frame is constant yes and no, yes its constant but its closer to 20ms exactly, and no because it does shift slightly but only by 1ms. I wanted the off-time originaly because that was the only was I was able to get the 1ms-2ms on-time output, not realizing that pwm mode 2 on the outputs is a beter choice for this and I have since switch the outputs from pwm1 mode to pwm2 which is working much beter, since I can just send the cptured value directly to the output with a few exceptions in ch3 and 4 since the capture after ch2 so their values are the sum of the previous channels and that channel combined so there is a little math involved but not much. I have also fixed most of my servo signal outputs except for CH1 it works now but incorrectly, instead of stay at say the neutral servo position it oscillates but I pinpointed it down to me using TI1F_ED to reset the counter at the start of the pulse sequence, and still be able to get a usable capture value for CH1. Here's a revised version with all the updates. #include ''stm8s.h'' u16 CH1on =0, CH2on =0, CH3on = 0, CH4on = 0; u16 CH1ontime = 0, CH2ontime = 0, CH3ontime = 0, CH4ontime = 0; u16 dtcy = 0, periodcount = 40100, periodcountX = 0, periodcounty = 0, periodcountz = 0; void main(void){ TIM1_DeInit(); /* Enable capture*/ TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV8, 0); TIM1_ICInit(TIM1_CHANNEL_2, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_3, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_4, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); /*Set TIM1 SMCR register to trigger counter reset on Ch1 Rising Edge*/ TIM1->SMCR = 0x44; /* Enable TIM2 */ TIM1_Cmd(ENABLE); /* Enable CC1 interrupt */ TIM1_ITConfig(TIM1_IT_CC1, ENABLE); TIM1_ITConfig(TIM1_IT_CC2, ENABLE); TIM1_ITConfig(TIM1_IT_CC3, ENABLE); TIM1_ITConfig(TIM1_IT_CC4, ENABLE); /* Clear CC1 Flag*/ TIM1_ClearFlag(TIM1_FLAG_CC1); TIM1_ClearFlag(TIM1_FLAG_CC2); TIM1_ClearFlag(TIM1_FLAG_CC3); TIM1_ClearFlag(TIM1_FLAG_CC4); TIM2_DeInit(); TIM3_DeInit(); for (;;){ while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1); /* Get CCR1 value*/ CH1on = TIM1_GetCapture1(); TIM1_ClearFlag(TIM1_FLAG_CC1); while((TIM1->SR1 & TIM1_FLAG_CC2) != TIM1_FLAG_CC2); /* Get CCR1 value*/ CH2on = TIM1_GetCapture2(); TIM1_ClearFlag(TIM1_FLAG_CC2); while((TIM1->SR1 & TIM1_FLAG_CC3) != TIM1_FLAG_CC3); /* Get CCR1 value*/ CH3on = TIM1_GetCapture3(); TIM1_ClearFlag(TIM1_FLAG_CC3); while((TIM1->SR1 & TIM1_FLAG_CC4) != TIM1_FLAG_CC4); /* Get CCR1 value*/ CH4on = TIM1_GetCapture4(); TIM1_ClearFlag(TIM1_FLAG_CC4); periodcountX = (CH2on + CH2ontime); periodcounty = (CH3on + CH3ontime); periodcountz = (CH4on + CH4ontime); CH3ontime = (CH3on - CH2on); CH4ontime = (CH4on - CH3on); /*TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1,0);*/ TIM2_TimeBaseInit(TIM2_PRESCALER_1, periodcount); // Initialise output channel 2 of TIM3. TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, CH1on, TIM2_OCPOLARITY_LOW); // Initialise output channel 2 of TIM3. TIM2_OC1Init(TIM2_OCMODE_PWM2, TIM2_OUTPUTSTATE_ENABLE, CH2on, TIM2_OCPOLARITY_LOW); // Enable TIM3. TIM2_Cmd(ENABLE); /*TIM1_PWMIConfig(TIM1_CHANNEL_2,TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1,0);*/ TIM3_TimeBaseInit(TIM3_PRESCALER_1, periodcount); // Initialise output channel 2 of TIM3. TIM3_OC1Init(TIM3_OCMODE_PWM2, TIM3_OUTPUTSTATE_ENABLE, CH3ontime, TIM3_OCPOLARITY_LOW); // Initialise output channel 2 of TIM3. TIM3_OC2Init(TIM3_OCMODE_PWM2, TIM3_OUTPUTSTATE_ENABLE, CH4ontime, TIM3_OCPOLARITY_LOW); // Enable TIM3. TIM3_Cmd(ENABLE); } } |
|
|
|
好吧,我终于让代码按照我想要的方式解决了一些小问题,但它们与硬件有关,以防万一有人想使用Discovery板在远程控制应用程序中使用,捕获接收器脉冲然后将它们输出到伺服电机或电机控制器这里是迄今为止的代码。
#include''stm8s.h'' u16 CH1on = 0,CH2on = 0,CH3on = 0,CH4on = 0; u16 Throttle3 = 0,Rudder4 = 0,Rightmotor = 0,Leftmotor = 0,Frontmotor = 0,Backmotor = 0; u16 periodcount = 40100; void main(void){ TIM1_DeInit(); / *启用捕获* / TIM1_ICInit(TIM1_CHANNEL_1,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_2,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_3,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); TIM1_ICInit(TIM1_CHANNEL_4,TIM1_ICPOLARITY_FALLING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0); / *设置TIM1 SMCR寄存器以在Ch1上升沿和下降沿触发计数器复位* / TIM1-> SMCR = 0x44; / *启用TIM1 * / TIM1_Cmd(ENABLE); / *启用CC1,2,3,4中断* / TIM1_ITConfig(TIM1_IT_CC1,ENABLE); TIM1_ITConfig(TIM1_IT_CC2,ENABLE); TIM1_ITConfig(TIM1_IT_CC3,ENABLE); TIM1_ITConfig(TIM1_IT_CC4,ENABLE); / *清除CC1,2,3,4标志* / TIM1_ClearFlag(TIM1_FLAG_CC1); TIM1_ClearFlag(TIM1_FLAG_CC2); TIM1_ClearFlag(TIM1_FLAG_CC3); TIM1_ClearFlag(TIM1_FLAG_CC4); / *清除所有TIM2和TIM3的位* / TIM2_DeInit(); TIM3_DeInit(); for(;;){ while((TIM1-> SR1&amp; TIM1_FLAG_CC1)!= TIM1_FLAG_CC1); / *获得CCR1值* / CH1on = TIM1_GetCapture1(); TIM1_ClearFlag(TIM1_FLAG_CC1); while((TIM1-> SR1&amp; TIM1_FLAG_CC2)!= TIM1_FLAG_CC2); / *获得CCR2值* / CH2on = TIM1_GetCapture2(); TIM1_ClearFlag(TIM1_FLAG_CC2); while((TIM1-> SR1&amp; TIM1_FLAG_CC3)!= TIM1_FLAG_CC3); / *获得CCR3值* / CH3on = TIM1_GetCapture3(); TIM1_ClearFlag(TIM1_FLAG_CC3); while((TIM1-> SR1&amp; TIM1_FLAG_CC4)!= TIM1_FLAG_CC4); / *获得CCR4值* / CH4on = TIM1_GetCapture4(); TIM1_ClearFlag(TIM1_FLAG_CC4); / *从CH3开启时间减去CH2时间以使CH3正确开启时间* / 节流3 =(CH3on-CH2on); / *从CH4开启时间减去CH3开启时间以获得CH4真实时间* / Rudder4 =(CH4on-CH3on); / *设置Throttle3以最初控制所有4个电机油门* / 后电机=节气门3; Leftmotor = Throttle3; Rightmotor = Throttle3; Frontmotor = Throttle3; if((CH2on&lt; 2950)&amp;(Throttle3&gt; 2180)){ 后电机=(Throttle3 - (3000 - CH2on)); } else if((CH2on&gt; 3050)&amp;(Throttle3&gt; 2180)){ Frontmotor =(Throttle3 - (CH2on -3000)); } if((CH1on&lt; 2950)&amp;(Throttle3&gt; 2180)){ Leftmotor =(Throttle3 - (3000 - CH1on)); } else if((CH1on&gt; 3050)&amp;(Throttle3&gt; 2180)){ 右电机=(节气门3 - (CH1on -3000)); } if((Rudder4&lt; 2950)&amp;(Throttle3&gt; 2180)){ Leftmotor =(Throttle3 - (3000 - Rudder4)); Rightmotor =(Throttle3 - (3000 - Rudder4)); } else if((Rudder4&gt; 3050)&amp;(Throttle3&gt; 2180)){ 后电机=(Throttle3 - (3000 - Rudder4)); Frontmotor =(Throttle3 - (3000 - Rudder4)); } / *设置TIM2和TIM3以50Hz运行,时钟脉冲为2MHz * / TIM2_TimeBaseInit(TIM2_PRESCALER_1,periodcount); TIM3_TimeBaseInit(TIM3_PRESCALER_1,periodcount); //初始化TIM2的输出通道1和3以控制左右电机。 TIM2_OC3Init(TIM2_OCMODE_PWM2,TIM2_OUTPUTSTATE_ENABLE,Frontmotor,TIM2_OCPOLARITY_LOW); TIM2_OC1Init(TIM2_OCMODE_PWM2,TIM2_OUTPUTSTATE_ENABLE,Leftmotor,TIM2_OCPOLARITY_LOW); //启用TIM2。 TIM2_Cmd(ENABLE); //初始化TIM3的输出通道1和2以控制前后电机。 TIM3_OC1Init(TIM3_OCMODE_PWM2,TIM3_OUTPUTSTATE_ENABLE,Rightmotor,TIM3_OCPOLARITY_LOW); TIM3_OC2Init(TIM3_OCMODE_PWM2,TIM3_OUTPUTSTATE_ENABLE,Rearmotor,TIM3_OCPOLARITY_LOW); //启用TIM3。 TIM3_Cmd(ENABLE); } } 以上来自于谷歌翻译 以下为原文 Well I finally got the the code to work just the way I wanted to with a few minor issues but they are hardware related, and just in case someone wants to use the Discovery board for use in a remote control application, to capture the receivers pulses and then output them to servos or motor controls here is the code to date. #include ''stm8s.h'' u16 CH1on =0, CH2on =0, CH3on = 0, CH4on = 0; u16 Throttle3 = 0, Rudder4 = 0, Rightmotor = 0, Leftmotor = 0, Frontmotor =0, Rearmotor = 0; u16 periodcount = 40100; void main(void){ TIM1_DeInit(); /* Enable capture*/ TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_2, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_3, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); TIM1_ICInit(TIM1_CHANNEL_4, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0); /*Set TIM1 SMCR register to trigger counter reset on Ch1 Rising Edge and falling edge*/ TIM1->SMCR = 0x44; /* Enable TIM1 */ TIM1_Cmd(ENABLE); /* Enable CC1, 2, 3, 4 interrupt */ TIM1_ITConfig(TIM1_IT_CC1, ENABLE); TIM1_ITConfig(TIM1_IT_CC2, ENABLE); TIM1_ITConfig(TIM1_IT_CC3, ENABLE); TIM1_ITConfig(TIM1_IT_CC4, ENABLE); /* Clear CC1, 2, 3, 4 Flag*/ TIM1_ClearFlag(TIM1_FLAG_CC1); TIM1_ClearFlag(TIM1_FLAG_CC2); TIM1_ClearFlag(TIM1_FLAG_CC3); TIM1_ClearFlag(TIM1_FLAG_CC4); /*Clear all of TIM2 and TIM3's bits*/ TIM2_DeInit(); TIM3_DeInit(); for (;;){ while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1); /* Get CCR1 value*/ CH1on = TIM1_GetCapture1(); TIM1_ClearFlag(TIM1_FLAG_CC1); while((TIM1->SR1 & TIM1_FLAG_CC2) != TIM1_FLAG_CC2); /* Get CCR2 value*/ CH2on = TIM1_GetCapture2(); TIM1_ClearFlag(TIM1_FLAG_CC2); while((TIM1->SR1 & TIM1_FLAG_CC3) != TIM1_FLAG_CC3); /* Get CCR3 value*/ CH3on = TIM1_GetCapture3(); TIM1_ClearFlag(TIM1_FLAG_CC3); while((TIM1->SR1 & TIM1_FLAG_CC4) != TIM1_FLAG_CC4); /* Get CCR4 value*/ CH4on = TIM1_GetCapture4(); TIM1_ClearFlag(TIM1_FLAG_CC4); /*Subtract CH2 on time from CH3 ontime to get CH3 correct ontime*/ Throttle3 = (CH3on - CH2on); /*Subtract CH3 ontime from CH4 ontime to get CH4 true ontime*/ Rudder4 = (CH4on - CH3on); /*Set Throttle3 to control all 4 motors throttle initially*/ Rearmotor = Throttle3; Leftmotor = Throttle3; Rightmotor = Throttle3; Frontmotor = Throttle3; if ((CH2on < 2950) & (Throttle3 > 2180)){ Rearmotor = (Throttle3 - (3000 - CH2on)); } else if ((CH2on >3050) & (Throttle3 > 2180)){ Frontmotor = (Throttle3 - (CH2on -3000)); } if ((CH1on < 2950) & (Throttle3 > 2180)) { Leftmotor = (Throttle3 -(3000 - CH1on)); }else if ((CH1on >3050) & (Throttle3 > 2180)) { Rightmotor = (Throttle3 - (CH1on -3000)); } if ((Rudder4 < 2950) & (Throttle3 > 2180)){ Leftmotor = (Throttle3 -(3000 - Rudder4)); Rightmotor = (Throttle3 -(3000 - Rudder4)); } else if ((Rudder4 > 3050) & (Throttle3 > 2180)){ Rearmotor = (Throttle3 - (3000 - Rudder4)); Frontmotor = (Throttle3 - (3000 - Rudder4)); } /*Set TIM2 and TIM3 to run at 50Hz with a 2MHz clock pulse*/ TIM2_TimeBaseInit(TIM2_PRESCALER_1, periodcount); TIM3_TimeBaseInit(TIM3_PRESCALER_1, periodcount); // Initialise output channel 1 and 3 of TIM2 to control the left and right motors. TIM2_OC3Init(TIM2_OCMODE_PWM2, TIM2_OUTPUTSTATE_ENABLE, Frontmotor, TIM2_OCPOLARITY_LOW); TIM2_OC1Init(TIM2_OCMODE_PWM2, TIM2_OUTPUTSTATE_ENABLE, Leftmotor, TIM2_OCPOLARITY_LOW); // Enable TIM2. TIM2_Cmd(ENABLE); // Initialise output channel 1 and 2 of TIM3 to control the front and rear motors. TIM3_OC1Init(TIM3_OCMODE_PWM2, TIM3_OUTPUTSTATE_ENABLE, Rightmotor, TIM3_OCPOLARITY_LOW); TIM3_OC2Init(TIM3_OCMODE_PWM2, TIM3_OUTPUTSTATE_ENABLE, Rearmotor, TIM3_OCPOLARITY_LOW); // Enable TIM3. TIM3_Cmd(ENABLE); } } |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2666 浏览 1 评论
3221 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1793 浏览 1 评论
3622 浏览 6 评论
6003 浏览 21 评论
950浏览 4评论
1322浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
596浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1315浏览 3评论
1374浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 08:54 , Processed in 1.626000 second(s), Total 97, Slave 80 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号