This is my first post here, so first hi at all and here is a little bit about me:
My name is Lukas, I'm from Germany and I'm fairly new to microelectronics. I've started just a few weeks ago and like to play around with my Arduino or Nucleo 64 to learn more about coding and hardware. At the moment I've got myself an absolute encoder (CUI AMT22) and wrote my first code (based on the manufacturers code) to read it out. That means I'm able to read just a little bit of C++ already.
To extend my project I want to operate a hobby BLDC motor with my Nucleo in a closed loop (with my encoder). For that I searched around the internet
and found this Board by Infineon: https://www.infineon.com/cms/de/product ... d_ifx007t/
The good thing is Infineon made this board open source and there's code available on Github for using it with an Arduino Uno right out the box: https://github.com/Infineon/IFX007T-Motor-Control
So I loaded the example code (IFX007_BLDC_BEMF.ino) with the Arduino library manager and tried to compile it in the Arduino IDE for my Nucleo 64 (F401RE) but I've got back an error:
Code: Select all
c:/users/lukas/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\lukas\AppData\Local\Temp\arduino-sketch-466D07EEC5F4544840C484368CC14F9C\libraries\IFX007T-Motor-Control\IFX007T-Motor-Control.cpp.o: in function `IFX007TMotorControl::begin()':
IFX007T-Motor-Control.cpp:(.text._ZN19IFX007TMotorControl5beginEv+0x84): undefined reference to `IFX007TMotorControl::setPwmFrequency(unsigned char, unsigned short)'
c:/users/lukas/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: IFX007T-Motor-Control.cpp:(.text._ZN19IFX007TMotorControl5beginEv+0x90): undefined reference to `IFX007TMotorControl::setPwmFrequency(unsigned char, unsigned short)'
c:/users/lukas/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: IFX007T-Motor-Control.cpp:(.text._ZN19IFX007TMotorControl5beginEv+0xa0): undefined reference to `IFX007TMotorControl::setPwmFrequency(unsigned char, unsigned short)'
c:/users/lukas/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\lukas\AppData\Local\Temp\arduino-sketch-466D07EEC5F4544840C484368CC14F9C\libraries\IFX007T-Motor-Control\IFX007T-Motor-Control.cpp.o: in function `IFX007TMotorControl::configureBLDCMotor(BLDCParameter)':
IFX007T-Motor-Control.cpp:(.text._ZN19IFX007TMotorControl18configureBLDCMotorE13BLDCParameter+0x88): undefined reference to `IFX007TMotorControl::setADCspeedFast()'
collect2.exe: error: ld returned 1 exit status
Compilation error: exit status 1}
Seemingly the compiler has a problem with a few (two?) functions that set the speed for the PWM and the ADC.
I've then looked into the IFX007T-Motor-Control.cpp file (linked above in Github) and found these two functions
when I'm scrolling all the way down:
Code: Select all
void IFX007TMotorControl::setPwmFrequency(uint8_t pin, uint16_t divisor)
{
byte mode;
if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch (divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 64: mode = 0x03; break;
case 256: mode = 0x04; break;
case 1024: mode = 0x05; break;
default: return;
}
if (pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
} else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
} else if (pin == 3 || pin == 11) {
switch (divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 32: mode = 0x03; break;
case 64: mode = 0x04; break;
case 128: mode = 0x05; break;
case 256: mode = 0x06; break;
case 1024: mode = 0x07; break;
default: return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
/**
* Source: https://forum.arduino.cc/index.php?topic=6549.0
*/
void IFX007TMotorControl::setADCspeedFast(void)
{
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// set prescale to 16
sbi(ADCSRA,ADPS2) ;
cbi(ADCSRA,ADPS1) ;
cbi(ADCSRA,ADPS0) ;
}
specific lines to manipulate settings on the used microcontroller board itself.
So my question to you is, if I've got that correct so far and if I want to use this library with my STM32 I "only" have to edit this functions
with code that sets the ADC and PWM with a "language" corresponding to my Nucleo board?
I would also be very thankful if you could help me out with a scetch that might work, because I'm only a beginner.
Thank you very much!