Infineon IFX007T BLDC motor controll shield

What are you developing?
Post Reply
Pukas
Posts: 2
Joined: Wed Feb 09, 2022 2:19 pm

Infineon IFX007T BLDC motor controll shield

Post by Pukas »

Hi there!

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}
And this is where I'm stuck.
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) ;
}
This code seems to be only fitting for the Arduino UNO (and also the Mega and an evaluation board by the manufacturer not listed in the quotation) because it uses
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!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Infineon IFX007T BLDC motor controll shield

Post by fpiSTM »

Hi,

you're right.
Issue come from the fact those functions (setADCspeedFast, setPwmFrequency) are only available for some specific board (arch).
Maybe you can try to add an new #elif here:
https://github.com/Infineon/IFX007T-Mot ... l.cpp#L994

Code: Select all

#elif defined(ARDUINO_ARCH_STM32)
void IFX007TMotorControl::setPwmFrequency(uint8_t pin, uint16_t divisor)
{
  (void)pin;
  (void)divisor;
  analogWriteFrequency(30000);       // 31250 Hz, obviously we nee the half (fault in XMCforArduino?)
}

void IFX007TMotorControl::setADCspeedFast(void)
{

}
Note that I've simply use the same frequency value 30000 but maybe it is not the correct one.
Pukas
Posts: 2
Joined: Wed Feb 09, 2022 2:19 pm

Re: Infineon IFX007T BLDC motor controll shield

Post by Pukas »

Hi there!

Consider yourself th person of the day, because it worked! Compilation was completed without errors!

I will see if the frequency works and the motor is rotating as it should when my hardware is arriving in the mail.
Should I contact the guys who wrote this library to mention the added STM32 support if the motor runs as it should?

Thank you very much!!!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Infineon IFX007T BLDC motor controll shield

Post by fpiSTM »

Welcome.
If it works then it should be fine to provide the patch, as a pull request for example.
Post Reply

Return to “Projects”