本帖最后由 11122000 于 2015-3-2 20:49 编辑
如图所示,现在实现的只能让两路信号中心对齐,是不是定时器的设定问题?
需要改动到下面这种情况,两路信号边缘对齐。
arduino里面执行语句表达为:
void loop()
{
if ( Enc_PWM1.read() != 0) {
PWM1_Value += (Enc_PWM1.read()/2) ;//Read data from encoder /*to choose the correct waveform*/
Enc_PWM1.write(0);//Clear encoder data
PWM1_Value = constrain(PWM1_Value, 0, 100);
Timer3.pwm(PWM1_out, PWM1_Value * 10.24);
lcd.setCursor(11, 0);
lcd.print(PWM1_Value);// display Lset value
lcd.print("% ");
}
if ( Enc_PWM2.read() != 0) {
PWM2_Value -= (Enc_PWM2.read()/2) ;//Read data from encoder
Enc_PWM2.write(0);//Clear encoder data turn more 0from the waveform
PWM2_Value = constrain(PWM2_Value, 0, 100);
Timer3.pwm(PWM2_out, PWM2_Value * 10.24); // analogWrite(PWM2_out, PWM2_Value * 2.55);
lcd.setCursor(11, 1);
lcd.print(PWM2_Value);// display Lset value
lcd.print("% ");
}
if ( Enc_Freq.read() != 0) {
Freq_Value += (Enc_Freq.read()*25) ;//Read data from encoder
Enc_Freq.write(0);//Clear encoder data
Freq_Value = constrain(Freq_Value, 100, 20000);
Timer3.setPeriod(1000000/Freq_Value);
Timer3.pwm(PWM2_out, PWM2_Value * 10.2);
Timer3.pwm(PWM1_out, PWM1_Value * 10.2);
} |