简体   繁体   English

Arduino Uno在所有PWM引脚上的频率相同

[英]Arduino Uno same frequency on ALL PWM pins

I'm controlling a BLDC motor with an inverter/driver IC doing the switching work. 我正在用逆变器/驱动器IC控制BLDC电机来进行开关工作。 I need to provide 6 PWM signals for the driver all at the same frequency. 我需要以相同的频率为驱动器提供6个PWM信号。 The exact frequency doesn't really matter, as long as its between 5kHz to 10kHz and all the PWM pins are the same. 确切的频率并不重要,只要它在5kHz至10kHz之间并且所有PWM引脚都相同即可。

I'm currently using an Arduino Uno, I'm not sure how to program each PWM pin (3, 5, 6, 9, 10, 11) for all the same frequency as the timers(0, 1 and 2) for particular pins have different clock speeds. 我目前正在使用Arduino Uno,我不确定如何针对每个计时器的相同频率(0、1和2)对每个PWM引脚(3、5、6、9、10、11)进行编程引脚具有不同的时钟速度。

  • Pins 5 and 6: controlled by timer0, base frequency 62500Hz 针脚5和6:由计时器0控制,基本频率62500Hz
  • Pins 9 and 10: controlled by timer1, base frequency 31250Hz 针脚9和10:由timer1控制,基本频率31250Hz
  • Pins 11 and 3: controlled by timer2, base frequency 31250Hz 引脚11和3:由timer2控制,基本频率为31250Hz

timer1 and timer2 will be okay and can be scaled down by the prescaler value 8 (7812.5Hz). timer1和timer2可以正常使用,并且可以通过预分频值8(7812.5Hz)进行分频。 Not sure how to get timer0 to the same frequency? 不确定如何将Timer0设置为相同的频率?

http://playground.arduino.cc/Main/TimerPWMCheatsheet http://playground.arduino.cc/Main/TimerPWMCheatsheet

I'm sure a work around is relatively simple. 我确信解决方法相对简单。 Is it possible to divide the frequency for timer0 by a number which is not a prescaler value, say 40? 是否可以将timer0的频率除以不是预分频值的数字(例如40)?

Thanks in advance. 提前致谢。

Pat. 拍。

You haven't included the chip number for your motor controller, but I'm pretty sure you won't be able to achieve what you want with six different timers. 您尚未提供电动机控制器的芯片号,但我敢肯定,使用六个不同的定时器将无法实现所需的功能。 The issue is that the PWM on the different pins all have to be synchronized, not just toggled on and off for the right amount of time. 问题在于,所有引脚上的PWM都必须同步,而不仅仅是在适当的时间打开和关闭。

Instead, you should use a single timer and toggle all the outputs at the correct synchronization. 相反,您应该使用单个计时器,并以正确的同步切换所有输出。 This page has the start of an example in the section "Bit-banging Pulse Width Modulation". 页面在“位敲打脉冲宽度调制”部分中以示例开头。 You would have to modify it to toggle more pins. 您将不得不对其进行修改以切换更多的引脚。

That example is probably still not good enough. 这个例子可能仍然不够好。 Instead, you should be using an interrupt service routine to toggle the pins. 相反,您应该使用中断服务程序来切换引脚。 That way, the PWM runs more independently and allows the loop function to do more. 这样,PWM可以更独立地运行,并允许环路功能执行更多操作。

Your routine will be attached to an output compare interrupt on a timer, and you will have to keep the values of the various PWM outputs in some volatile variables. 您的例程将附加到计时器的输出比较中断,并且您必须将各种PWM输出的值保留在某些易失性变量中。 The output compare register will be set to wake up for the next toggle. 输出比较寄存器将设置为在下一次触发时唤醒。 When the routine runs, it will perform the toggle and set the output compare register for the toggle. 例程运行时,它将执行切换,并为切换设置输出比较寄存器。 The details of the timing and synchronization will depend on the datasheet for your controller. 时序和同步的详细信息取决于控制器的数据表。

The loop function can read inputs and adjust the volatile variables to change the motor speed. 回路功能可以读取输入并调整易失性变量以更改电动机速度。

There are also motor drivers that do all this for you. 也有电机驱动器可以为您完成所有这些工作。 All you have to do is provide a direction and speed, and the chip creates the 6 PWMs for you. 您所要做的就是提供方向和速度,然后芯片为您创建6个PWM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM