I am trying to employ an MX1508 dual H-bridge motor controller in a project that I am working on. I have no problem getting my Teensy 4.1 to actuate a motor attached to the H-bridge, but the only library that I can find that is set up to work with PWM speed control with the MX1508 (https://github.com/Saeterncj/MX1508) fails to compile.
My hope is that someone on the forum will be able to confirm that the library will (or will not) compile on their computer. I have never had problems with compiling libraries until recently, but over the last few days, I had problems compiling several, so either I am experiencing a run of bad luck, or there is something partially awry with the compiler (or the user).
To keep things simple I attempted to compile the following minimal code:
-------------------------
#include <MX1508.h>
#define PINA 36
#define PINB 37
#define NUMPWM 2
#define PWM 100
MX1508 motorA(PINA,PINB, FAST_DECAY, NUMPWM);
void setup() {}
void loop() {
motorA.motorGo(PWM);
}
-------------------------
And here are the voluminous error messages generated by the compiler:
-------------------------
C:\Users\Michael\AppData\Local\Temp\.arduinoIDE-unsaved2023327-548-19k8st8.wur5\sketch_apr27a\sketch_apr27a.ino:5:16: warning: invalid conversion from 'int' to 'NumOfPwmPins' [-fpermissive]
5 | #define NUMPWM 2
| ^
| |
| int
C:\Users\Michael\AppData\Local\Temp\.arduinoIDE-unsaved2023327-548-19k8st8.wur5\sketch_apr27a\sketch_apr27a.ino:8:38: note: in expansion of macro 'NUMPWM'
8 | MX1508 motorA(PINA,PINB, FAST_DECAY, NUMPWM);
| ^~~~~~
In file included from C:\Users\Michael\AppData\Local\Temp\.arduinoIDE-unsaved2023327-548-19k8st8.wur5\sketch_apr27a\sketch_apr27a.ino:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508/MX1508.h:21:78: note: initializing argument 4 of 'MX1508::MX1508(uint8_t, uint8_t, DecayMode, NumOfPwmPins)'
21 | MX1508(uint8_t pinIN1, uint8_t pinIN2, DecayMode decayMode, NumOfPwmPins numPWM);
| ~~~~~~~~~~~~~^~~~~~
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp: In member function 'void MX1508::setResolution(unsigned int)':
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:32:25: error: 'ICR1' was not declared in this scope
32 | if(_useAnalogWrite16) ICR1 = pwmResolution;
| ^~~~
In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\6D542608C537E51812A9D89560841D14/pch/Arduino.h:6,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.h:4,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp: In member function 'void MX1508::setPWM16(uint8_t, unsigned int)':
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:37:22: error: 'PB1' was not declared in this scope; did you mean 'B1'?
37 | DDRB |= _BV(PB1) | _BV(PB2); /* set pin 9and 10 as outputs */
| ^~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:37:33: error: 'PB2' was not declared in this scope
37 | DDRB |= _BV(PB1) | _BV(PB2); /* set pin 9and 10 as outputs */
| ^~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:5: error: 'TCCR1A' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~~
In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\6D542608C537E51812A9D89560841D14/pch/Arduino.h:6,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.h:4,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:18: error: 'COM1A1' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:32: error: 'COM1B1' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:46: error: 'WGM11' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:39:9: error: 'TCCR1B' was not declared in this scope
39 | TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively
| ^~~~~~
In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\6D542608C537E51812A9D89560841D14/pch/Arduino.h:6,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.h:4,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:39:22: error: 'WGM13' was not declared in this scope
39 | TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively
| ^~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:39:35: error: 'WGM12' was not declared in this scope
39 | TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively
| ^~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
(1<<
)
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:40:9: error: 'ICR1' was not declared in this scope
40 | ICR1 = resolution;
| ^~~~
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp: In member function 'void MX1508::analogWrite16(uint8_t, uint16_t)':
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:50:26: error: 'OCR1A' was not declared in this scope
50 | case 9: OCR1A = val; break;
| ^~~~~
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:51:26: error: 'OCR1B' was not declared in this scope
51 | case 10: OCR1B = val; break;
| ^~~~~
exit status 1
Compilation error: exit status 1
-------------------------
I have reinstalled the Arduino 2.1.0 IDE without effect, but perhaps reinstalling the IDE does not touch the compiler if is found to already exist.
Thanks for your help.
Tim
My hope is that someone on the forum will be able to confirm that the library will (or will not) compile on their computer. I have never had problems with compiling libraries until recently, but over the last few days, I had problems compiling several, so either I am experiencing a run of bad luck, or there is something partially awry with the compiler (or the user).
To keep things simple I attempted to compile the following minimal code:
-------------------------
#include <MX1508.h>
#define PINA 36
#define PINB 37
#define NUMPWM 2
#define PWM 100
MX1508 motorA(PINA,PINB, FAST_DECAY, NUMPWM);
void setup() {}
void loop() {
motorA.motorGo(PWM);
}
-------------------------
And here are the voluminous error messages generated by the compiler:
-------------------------
C:\Users\Michael\AppData\Local\Temp\.arduinoIDE-unsaved2023327-548-19k8st8.wur5\sketch_apr27a\sketch_apr27a.ino:5:16: warning: invalid conversion from 'int' to 'NumOfPwmPins' [-fpermissive]
5 | #define NUMPWM 2
| ^
| |
| int
C:\Users\Michael\AppData\Local\Temp\.arduinoIDE-unsaved2023327-548-19k8st8.wur5\sketch_apr27a\sketch_apr27a.ino:8:38: note: in expansion of macro 'NUMPWM'
8 | MX1508 motorA(PINA,PINB, FAST_DECAY, NUMPWM);
| ^~~~~~
In file included from C:\Users\Michael\AppData\Local\Temp\.arduinoIDE-unsaved2023327-548-19k8st8.wur5\sketch_apr27a\sketch_apr27a.ino:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508/MX1508.h:21:78: note: initializing argument 4 of 'MX1508::MX1508(uint8_t, uint8_t, DecayMode, NumOfPwmPins)'
21 | MX1508(uint8_t pinIN1, uint8_t pinIN2, DecayMode decayMode, NumOfPwmPins numPWM);
| ~~~~~~~~~~~~~^~~~~~
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp: In member function 'void MX1508::setResolution(unsigned int)':
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:32:25: error: 'ICR1' was not declared in this scope
32 | if(_useAnalogWrite16) ICR1 = pwmResolution;
| ^~~~
In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\6D542608C537E51812A9D89560841D14/pch/Arduino.h:6,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.h:4,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp: In member function 'void MX1508::setPWM16(uint8_t, unsigned int)':
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:37:22: error: 'PB1' was not declared in this scope; did you mean 'B1'?
37 | DDRB |= _BV(PB1) | _BV(PB2); /* set pin 9and 10 as outputs */
| ^~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:37:33: error: 'PB2' was not declared in this scope
37 | DDRB |= _BV(PB1) | _BV(PB2); /* set pin 9and 10 as outputs */
| ^~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:5: error: 'TCCR1A' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~~
In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\6D542608C537E51812A9D89560841D14/pch/Arduino.h:6,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.h:4,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:18: error: 'COM1A1' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:32: error: 'COM1B1' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:38:46: error: 'WGM11' was not declared in this scope
38 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1
| ^~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:39:9: error: 'TCCR1B' was not declared in this scope
39 | TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively
| ^~~~~~
In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\6D542608C537E51812A9D89560841D14/pch/Arduino.h:6,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.h:4,
from c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:1:
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:39:22: error: 'WGM13' was not declared in this scope
39 | TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively
| ^~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:39:35: error: 'WGM12' was not declared in this scope
39 | TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively
| ^~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:45:38: note: in definition of macro '_BV'
45 | #define _BV
| ^
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:40:9: error: 'ICR1' was not declared in this scope
40 | ICR1 = resolution;
| ^~~~
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp: In member function 'void MX1508::analogWrite16(uint8_t, uint16_t)':
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:50:26: error: 'OCR1A' was not declared in this scope
50 | case 9: OCR1A = val; break;
| ^~~~~
c:\Users\Michael\Documents\Arduino\libraries\MX1508\MX1508.cpp:51:26: error: 'OCR1B' was not declared in this scope
51 | case 10: OCR1B = val; break;
| ^~~~~
exit status 1
Compilation error: exit status 1
-------------------------
I have reinstalled the Arduino 2.1.0 IDE without effect, but perhaps reinstalling the IDE does not touch the compiler if is found to already exist.
Thanks for your help.
Tim