Hall sensors. INPUT_PULLUP

Good day!
My project considers hall sensors use. I have found that need the command as:
pinMode(Pin#, INPUT_PULLUP); (pin# what gets the hall signal)

But it seems logically pull the pin down. While the hall sensor is closed it sends HIGH and we see the HIGH on the our pin. Otherwise pin always on the LOW position.
Am I wrang

Wrong, it is HIGH, until the sensor is closed to ground, then LOW.

Hi,
Can you please post a link to data/spec of the Hall Effect device?

Have you protoboarded a sensor and see how it works?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi again?
I spin the blcd motor by hand. Reading Hall sensors.
For now, I want in my scetch just to get printed: "caught hallA change", in case the signal has changed on the hallA. But that doesn't happen. Why?

volatile byte hallA = LOW;
volatile byte hallC = LOW;
volatile byte hallB = LOW;

void setup() {

Serial.begin(9600);

// Arduino Leonardo / read hall sensors of the BLDC motor

pinMode(0, INPUT_PULLUP); // read hallA
pinMode(1, INPUT_PULLUP); //read hallB
pinMode(2, INPUT_PULLUP);//read hallC

attachInterrupt(0, hall_A_Change, CHANGE); // interrapt while the signal hallA changed

}

void loop() {

// monitoring hall sensors. (manually rotate the motor)

int hallA = digitalRead(0);
int hallB = digitalRead(2);
int hallC = digitalRead(1);

Serial.print ("hallA="); Serial.print (hallA); Serial.print (" ");
Serial.print ("hallB="); Serial.print (hallB); Serial.print (" ");
Serial.print ("hallC="); Serial.println (hallC);
}

void hall_A_Change() 
{
Serial.println("caught hallA change ");
}

Encoder.ino (807 Байт)

What part number is your sensor?

The typical Hall Effect switch like the A3144 is an open collector output so requires a pullup resistor.

image

No idea. Thay are into blcd motor

What Arduino board are you using? On many Arduino boards pins 0 and 1 are the hardware serial pins so should not be use for anything else if the serial port is in use.

OK, I typed that before I saw your last post.

Interrupt 0 is on pin 2. See the attachInterrupt() reference.

Hi,
Can you please post a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

These variables:-

Are totally different variables to these variables.

They might have the same name but are not in any other way connected to the variables you declared as volatile in the opening lines.

Hi Tom,
I have a drawing but without motor and leonardo connections. But overall principal is there. I just open corresponding transistors. In this scheme I check the capacitors and another functions. Sorry if it is not you mean

I use Leonardo. I need pins 0,1,2 to create the interraption functions

OK. I have simplified the program as much as possible. It seems to be the way it works. I will continue to study further. Thank you.

volatile int count = LOW;
void setup() {
Serial.begin(9600);

// Arduino Leonardo / read hall sensors of the BLDC motor
pinMode(0, INPUT_PULLUP); // read hallA - pin D0
pinMode(1, INPUT_PULLUP); //read hallB - pin D1
pinMode(2, INPUT_PULLUP);//read hallC- pin D2

attachInterrupt(2, CodeA, RISING);         // interrapt 2 while the signal hallA up
}
void loop() {
// monitoring hall sensors. (manually rotate the motor)
int hallA = digitalRead(0);
int hallB = digitalRead(2);
int hallC = digitalRead(1);

Serial.print ("hallA="); Serial.print (hallA); Serial.print (" ");
Serial.print("count="); Serial.println(count);
}

void CodeA() {
count++;
}

I have drawn some image. Unfortunately I do not know if it is the right hall code for my bldc. Will hope. The interaction algorithm is below:

attachInterrupt(3, hall_CB, RISING); //  hall_B RISING, Code(halls ACB) = 011,  D1 - int3
attachInterrupt(1, hall__B, FALLING);  // hall_C FALLING, Code = 001,  D2 - int1
attachInterrupt(2, hallA_B, RISING);  // hall_A RISING, Code = 101,  D0 - int2
attachInterrupt(3, hallA__,FALLING);  // hall_B FALLING, Code = 100,  D1 - int3
attachInterrupt(1, hallAC_,RISING);  //  hall_C RISING, Code = 110,  D2 - int1
attachInterrupt(2, hall_C_,FALLING);  // hall_A FALLING, Code = 010,  D0 - int2

Note here you are printing out a 16 bit variable without disabling the interrupts, so you will occasionally get the wrong value when one byte changes and cause the other byte to change. Then when you access this variable you can get one old byte and one new one. This will give you all sorts of erroneous numbers some times.

Thank you so much. I don't know all the details yet. In a real project, I will remove all Serial.prints. Can you please rate the program as a whole?


// set all halls as zero
int hallA = LOW; int hallB = LOW; int hallC = LOW; 

volatile int PWM = 0;  // PWM signal will be appears while some interruptions due to hall commands

void setup() {
 Serial.begin(9600);
pinMode(3, OUTPUT);pinMode(5, OUTPUT); pinMode(6, OUTPUT);pinMode(9, OUTPUT); pinMode(10, OUTPUT);pinMode(11, OUTPUT); 

   // First step: close all transistors
digitalWrite(3, LOW); digitalWrite(5, LOW);digitalWrite(6, LOW);digitalWrite(9, LOW); digitalWrite(10, LOW);digitalWrite(11, LOW);

// Arduino reads hall sensors of the BLDC motor (interraption sets for Leonardo)
pinMode(0, INPUT_PULLUP); //  hallA - pin D0 - int 2 
pinMode(1, INPUT_PULLUP); //  hallB - pin D1 - int 3
pinMode(2, INPUT_PULLUP); // hallC- pin D2 - int  1
   
attachInterrupt(3, hall_CB, RISING); //  hall_B RISING, Code(halls ACB) = 011,  D1 - int3
attachInterrupt(1, hall__B, FALLING);  // hall_C FALLING, Code = 001,  D2 - int1
attachInterrupt(2, hallA_B, RISING);  // hall_A RISING, Code = 101,  D0 - int2
attachInterrupt(3, hallA__, FALLING);  // hall_B FALLING, Code = 100,  D1 - int3
attachInterrupt(1, hallAC_, RISING);  //  hall_C RISING, Code = 110,  D2 - int1
attachInterrupt(2, hall_C_, FALLING);  // hall_A FALLING, Code = 010,  D0 - int2
 
                               
int PWM = (analogRead(A0)/4);// read the potentiometer that adjust PWM 

// at the first step, briefly turn the rotor once:
for (int i = 0; i < 1; i++)  // at the first step, briefly turn the rotor once
{
int hallA = digitalRead(0); 
int hallB = digitalRead(1);  
int hallC = digitalRead(2); 
 {  
     if (hallA == LOW && hallC == HIGH && hallB == HIGH)
  {
  digitalWrite(9, PWM); // (A-)=pin9, transistor М4 
  digitalWrite(10, PWM); // (B+)= pin10, transistor М5
  int X = 1;
  }
   if (hallA == LOW && hallC == LOW && hallB == HIGH)
  {
   digitalWrite(10, PWM); // (B+)=pin10, transistor М5
   digitalWrite(11, PWM); // (C-)=pin11, transistor М6 
   int X = 2; 
  }
  if (hallA == HIGH && hallC == LOW && hallB == HIGH)
  {
  digitalWrite(3, PWM); // (A+)=pin3, transistor М1
  digitalWrite(11, PWM); // (C-)=pin11,transistor М6  
  int X = 3;
  }
  if (hallA == HIGH && hallC == LOW && hallB == LOW)
  {
  digitalWrite(3, PWM); // (A+)=pin3, transistor М1
  digitalWrite(5, PWM); // (B-)=pin5, transistor М2  
  int X = 4;
  }
  if (hallA == HIGH && hallC == HIGH && hallB == LOW)
  {
    digitalWrite(6, PWM); // (C+)=pin6, transistor М3
    digitalWrite(5, PWM); // (B-)=pin5, transistor М2
    int X = 5;
  }
  if (hallA == LOW && hallC == HIGH && hallB == LOW)
  {
    digitalWrite(9, PWM); // (A-)=pin9, transistor М4
    digitalWrite(6, PWM); // (C+)=pin6, transistor М3  
    int X = 6;
  }
  }
}
}
void loop() {
}



//  programs that performed while interruptions at hall signals has been appeared. Considered phases are connected to + or -

// A-, B+ 
void hall_CB () {
digitalWrite(9, PWM); // (A-)=pin9, transistor М4 
digitalWrite(10, PWM); // (B+)=pin10, transistor М5
}
// B+, C- 
void hall__B () {
digitalWrite(10, PWM); // (B+)=pin10, transistor М5
digitalWrite(11, PWM); // (C-)=pin11, transistor М6  
}
// A+, C-
void hallA_B () {
digitalWrite(3, PWM); // (A+)=pin3, transistor М1
digitalWrite(11, PWM); // (C-)=pin11, transistor М6  
} 
 // A+, B- 
void hallA__ () {
digitalWrite(3, PWM); // (A+)=pin3, transistor М1
digitalWrite(5, PWM); // (B-)=pin5, transistor М2  
  }
  // C+, B-
void hallAC_ (){
digitalWrite(6, PWM); // (C+)=pin6, transistor М3
digitalWrite(5, PWM); // (B-)=pin5, transistor М2  
}
  // A-, C+
void hall_C_ (){
 digitalWrite(9, PWM); // (A-)=pin9, transistor М4
 digitalWrite(6, PWM); // (C+)= pin6, transistor М3  
}

 

I just assembled the wiring physically. Haven't turned on the power to the motor yet. I want to test the program. I'll put it off for next year.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.