Hi, I need some help with my project. I have some basics in electronics but I'm almost a complete beginner in programming. My workflow is as follows. I found a similar project and tried to modify it to suit my needs. However, I have encountered problems where I am stuck and don't know how to proceed.
Short introduction. I am making an auxiliary device for calibrating the Heindenhain encoder. This encoder is located on the rotor of the electric motor. My company fixes the motor winding and always moves the encoder in question during maintenance. As a result, when the motor is returned to the customer and he connects it for use, the motor starts to overheat. The employees have tried to mark the original position of the encoder with a marker, but this is very inaccurate and not always correct. It is unprofitable for me to take each motor to another company where they can calibrate it. And buying a test system is unprofitable as it would not pay for itself. That's why I wanted to do it with an Arduino.
The first thing I did was visit an authorised service for these encoders to see how they set them up.
Sensor used: ERN 1387
Datasheet: https://www.heidenhain.be/fileadmin/pdb/media/img/1085677_03_A_02_ExN_13xx_Aufzugtechnik_en.pdf
(page 5)
The technician at the authorised company found the zero point at the reset point and reseted the position in their program.
He tightened and fixed the encoder. The test continued.
On the rotor of the motor in question, there are 3 magnets that create 3 poles. 0°, 120°, 240°. He turned the rotor manually (motor isnt connected to voltage) . Let's say we went from 0° to 20°. He then applied 24V and 1/10th of the current to the motor according to the motor's rating plate.
The rotor returned to the nearest pole. So from 20° back to 0°. However, it was not exactly 0°, but about 1.53°. The technician said that 3° was the maximum tolerance. Well, the whole test is to come back within three degrees.
So I started to make a simple homemade version. If the outputs of the encoder are A, B, R, C, D. And I know that 2048 pulses should be per full revolution I thought it could be done via attachInterrupt() and a couple of conditions. Where when it detects a pulse from R it knows it's at 0, so I know where to start.
I found an existing project on the internet:
http://www.everythingbends.com/2015/03/encoder-interpolation.html
I repeated the conversion from sin/cos to TTL and started calculating with the arduino
I bought a ready-made evaluation board to avoid problems with soldering etc.
https://www.ichaus.de/upload/pdf/NV_NVH_datasheet_E1en.pdf
So I converted A, B, R on the output and calculated A and B with such a program. So far I have done this on an Arduino Uno. I plan to switch to DUE as I need another attachInterrupt().
My current problem is that I can't get a pulse from R. As soon as I attach it, it starts counting something even without spinning the encoder.
#include "U8glib.h"
#define pot A0
#define pwm 5
#define CLK 13
#define MOSI 11
#define RES 10
#define DC 9
#define CS 8
U8GLIB_SH1106_128X64 oled(CLK, MOSI, CS, DC, RES);
long int prepis = 0;
volatile long temp, counter = 0;
void setup(void) {
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
attachInterrupt(0, ai0, RISING);
attachInterrupt(1, ai1, RISING);
Serial.begin(9600);
// oled.setRot180();
}
void loop(void) {
if( counter != temp )
{
Serial.println (counter);
Serial.println (temp);
temp = counter;
}
// porovnání uloženého a aktuálního času při rozdílu větším než 100 ms se provede obnovení displeje, čas můžeme nastavit dle potřeby
oled.firstPage();
do {
// funkce vykresli vykreslí žádanou obsah
vykresli();
} while ( oled.nextPage() );
// uložení posledního času obnovení
}
void ai0() {
if(digitalRead(3)==LOW){
counter++;
}
else
{
counter--;
}
}
void ai1() {
if(digitalRead(2)==LOW){
counter--;
}
else
{
counter++;
}
}
void vykresli(void) {
oled.setFont(u8g_font_unifont);
oled.setPrintPos(0, 10);
oled.print("pocet impulzov");
oled.setPrintPos(0, 30);
oled.print(counter);
oled.setPrintPos(0, 45);
oled.print("poloha v stupnoch");
oled.setPrintPos(0, 60);
oled.print(counter/5.6888);
}