Help ATM103 & simpleFOC board

Hello everybody! I am a beginner with simpleFOC. I have bought a simple FOC board (V1.3.3), and I am using it with Arduino UNO to control a BLDC motor with an ATM103 as an encoder. The final goal is to create a spacecraft attitude simulator using wireless ROS. However, I am encountering some problems with the Encoder. I am able to control the BLDC in open loop but, when I use the the example “find_pole_pairs.ino”, I always get “0.00” as encoder angle (even if the motor is actually moving). As far as I know, the ATM103 does not need to enable the pull, right? the wiring connections are:

simpleFOC board → ATM103
A/V -->A
B/V–>B
5V -->5V
I/W–>X
G–>G

The initialisation of the encoder is:

Encoder pendulum = Encoder(A2, 2, 500, A0);

Does anybody have any idea of how to solve this?

Encoder: https://photos.app.goo.gl/cvfyqD73uVnXpLEV9 and https://photos.app.goo.gl/3U7swi3FTUtbhtav6

Hi @Alessandro_Visintini,

First of all I do not have experience with this type of encoder. I think that there is something wrong with the initialisation. I think this will be enough (assuming you are using ATM103 as in the examples of the forum).

//  Encoder(int encA, int encB , int cpr, int index)
//  - encA, encB    - encoder A and B pins
//  - ppr           - impulses per rotation  (cpr=ppr*4)
//  - index pin     - (optional input)
Encoder encoder = Encoder(2, 3, 2048); //Use your own values

Otherwise you can take a look at the following example (uses a quite similair setup to yours) and at the docs of encoders.

I hope that looking at the example will may further help you solving your problem! Otherwise if it did not help you that someone takes a look at it who has more experience with these types of encoders! Good luck :slight_smile:

Thank you very @Wittecactus much for your quick answer! the problem is, according to the connections I have written, the photos I have posted and the documentation, the initialisation seems right. Do you know how is it possible to know if ATM103 needs pull-up resistor? how is it possible to see if an Encoder needs a pull-up resistor? I do not find anything in the datasheet. I would appreciate any help!

Hey @Alessandro_Visintini
Amt103 does not need a pull-up.

Are you using software interrupts with pci manager?
Arduino Uno does not have interrupts on puns A2 and A0 so you should be using the pci manager of similar library. You can find similar code in the examples.
For example in utils

But I’d suggest you to change the board pinout. So set the encoder to pins 2 and 3 and then you don’t need the software interrupts.
Also make sure that that works before trying to use the index pin. :slight_smile:

Dear @Antun_Skuric, thank you very much for the answer, I saw you are very active in the forum. I have tried what you suggested and the encoder now seem to work fine, I’ve tried the “encoder sensor test” example in the utils. However, the example “find_pole_pairs_number” is still not working fine. According to the pictures I’ve attached, the encoder is set to have PPR = 500, Therefore, I create my encoder as " Encoder(2, 3, 2000) ", (cpr = ppr*4) but the output is always something like:

Pole pairs (PP) estimator 

Estimated PP : 6000 
PP = Electrical angle / Encoder angle  
1080.00/0.18 = 6000.00 
 
PP number very high, possible error. 

 Motor ready. 
Set the target voltage using serial terminal:

Do you have any other suggestion of something I might be missing? I am using this motor:

Hey @Alessandro_Visintini
The ATM103 have by default the rage of 2048 ppr. This you can configure if you open the sensor. There are four small sliders. see the page 4.

Make sure you read the good number. Once you have it, just put it into the constructor. Constructor receives the PPR value not CPR, so don’t multiply it by 4!

Dear @Antun_Skuric, I changed the Encoder to 2048 ppr both in the code and on the encoder itself, but I got the same problem. Nevertheless, I managed to solve the problem using BLDCDriver3PWM driver = BLDCDriver3PWM(9,10,6,7), instead of BLDCDriver3PWM driver = BLDCDriver3PWM(3,10,6,7). Now, do you have any clue of the reason a wrong code makes the motor spinning and the Arduino is able to find the correct number of poles? Am I missing something?

Wow, interesting. From what you describe one of the motor phases was not connected, so you were open-loop driving the motor using only 2 phases?
I guess this could work, but you certainly would not get very nice or smooth motion.

Hey @Alessandro_Visintini,

I think that you may have an issue due to the pin confiuration.
Please make sure that each of the Arduino pins is used only once. If you use pin 3 with the encoder you will not be able to use it with the BLDCDriver3PWM.

Here is the link to the docs. You can see the suggested pinouts for single boards there:

Here is a combination that might work for you:

Yes, it was not smooth at all!!

Thank you very much for your help!!