各位好
在 Arduino权威指南 示例CH18R5 脉冲发生器程序编译时发生错误。我是新手刚开始接触arduino,实在搞不定,只能求大家帮忙分析了。
/////////////////////////////////////////以下是原程序出错块///////////////////////////////////////////////
bool setPulseWidth(long microseconds)
{
bool ret = false;
int prescaleValue = prescale[Timer1.clockSelectBits];
// calculate time per tick in ns
long precision = (F_CPU / 128000) * prescaleValue ;
period = precision * ICR1 / 1000; // period in microseconds
if ( microseconds < period)
{
duty = map(microseconds, 0, period, 0, 1024);
if ( duty < 1)
duty = 1;
if (microseconds > 0 && duty < RESOLUTION)
{
Timer1.pwm(outPin, duty);
ret = true;
}
}
///////////////////////////////////////// END ///////////////////////////////////////////////
报错信息
Arduino:1.6.8 (Windows 7):"Arduino/Genuino Uno"
In file included from E:\arduino\ArduinoCookbook\ch18\ch18r5\ch18r5.ino:1:0:
d:\Documents\Arduino\libraries\TimerOne/TimerOne.h: In function 'bool setPulseWidth(long int)':
d:\Documents\Arduino\libraries\TimerOne/TimerOne.h:157:26: error: 'unsigned char TimerOne::clockSelectBits' is private
static unsigned char clockSelectBits;
^
ch18r5:95: error: within this context
int prescaleValue = prescale[Timer1.clockSelectBits];
^
ch18r5:104: error: 'RESOLUTION' was not declared in this scope
if (microseconds > 0 && duty < RESOLUTION)
^exit status 1
within this context
在 Arduino权威指南 示例CH18R5 脉冲发生器程序编译时发生错误。我是新手刚开始接触arduino,实在搞不定,只能求大家帮忙分析了。
/////////////////////////////////////////以下是原程序出错块///////////////////////////////////////////////
bool setPulseWidth(long microseconds)
{
bool ret = false;
int prescaleValue = prescale[Timer1.clockSelectBits];
// calculate time per tick in ns
long precision = (F_CPU / 128000) * prescaleValue ;
period = precision * ICR1 / 1000; // period in microseconds
if ( microseconds < period)
{
duty = map(microseconds, 0, period, 0, 1024);
if ( duty < 1)
duty = 1;
if (microseconds > 0 && duty < RESOLUTION)
{
Timer1.pwm(outPin, duty);
ret = true;
}
}
///////////////////////////////////////// END ///////////////////////////////////////////////
报错信息
Arduino:1.6.8 (Windows 7):"Arduino/Genuino Uno"
In file included from E:\arduino\ArduinoCookbook\ch18\ch18r5\ch18r5.ino:1:0:
d:\Documents\Arduino\libraries\TimerOne/TimerOne.h: In function 'bool setPulseWidth(long int)':
d:\Documents\Arduino\libraries\TimerOne/TimerOne.h:157:26: error: 'unsigned char TimerOne::clockSelectBits' is private
static unsigned char clockSelectBits;
^
ch18r5:95: error: within this context
int prescaleValue = prescale[Timer1.clockSelectBits];
^
ch18r5:104: error: 'RESOLUTION' was not declared in this scope
if (microseconds > 0 && duty < RESOLUTION)
^exit status 1
within this context