I have created a class that outputs a 25K PWM signal on either pin 9 or pin 10 for the Arduino Nano. And on the Nano it works perfectly. However if I change the board to "Arduino Every" I get 'TCCR1A' was not declared in this scope'. I am including <Arduino.h> but it seams these defines are non-existing for the Arduino Every board? This board is suppose to be compatible with the Nano, why are these defines not found then?
My code (note: separate C++ file, so its not the sketch file) :
#include <Arduino.h>
#include "HixPinPWM25KHz.h"
HixPinPWM25KHz::HixPinPWM25KHz(int nPinNumber): HixPin(nPinNumber) {
}
void HixPinPWM25KHz::begin() {
//25KHz PWM only supported on ping 9 and 10
if ( (m_nPinNumber != 9) && (m_nPinNumber != 10) ) {
return;
}
// Configure Timer 1 for PWM @ 25 kHz.
TCCR1A = 0; // undo the configuration done by...
TCCR1B = 0; // ...the Arduino core library
TCNT1 = 0; // reset timer
TCCR1A = _BV(COM1A1) // non-inverted PWM on ch. A
| _BV(COM1B1) // same on ch; B
| _BV(WGM11); // mode 10: ph. correct PWM, TOP = ICR1
TCCR1B = _BV(WGM13) // ditto
| _BV(CS10); // prescaler = 1
ICR1 = 320; // TOP = 320
pinMode(m_nPinNumber, OUTPUT);
analogWrite(50);
}
void HixPinPWM25KHz::analogWrite(float percent) {
int value = (int) ( (percent * (float)320) / (float)100 );
switch (m_nPinNumber) {
case 9:
OCR1A = value;
break;
case 10:
OCR1B = value;
break;
default:
// no other pin will work
break;
}
}