Hi @PaulS and @MatrixRat
I did what you both suggested, added a 1k resistor from the sn74 output to the 3.3 vcc and it started working with my teensy rather than the teensy being fully unresponsive. A huge step forward towards the right direction. Thanks for both of your inputs.
I forgot to mention I received these motors from a college lab and there are 2 halls soldered to it. Hall sensor 1 has a "leading signal" when the motor is rotating right, and hall sensor 2 has a "leading signal" when the motor rotates left. So I tweaked the code to add both simultaneously because they share the same one VCC and GND wires from being soldered the the motor. Plugging one hall properly but not the other may have been also causing issues.
The hall counts were still off so I did the proper set up: (ran all unused OEs to VCC (+3.3v) so they remain off and reduce noise/floating issues from the SN74 chip.
I then added a 0.1uf Capacitor between GND and the +3.3v rail that powered the SN74, the pulse counts cleaned up pretty well. I tested it out a few times, and then also with a 0.22uf capacitor for comparisons sake.
I also added snap on ferrite rings on all of the wires. Not sure if it made a difference.
Code:
//global:
volatile long hallCount=0;
void setup()
{
pinMode(hallSensor1, INPUT_PULLUP);
pinMode(hallSensor2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(hallSensor1), hallCounter1, RISING);
attachInterrupt(digitalPinToInterrupt(hallSensor2), hallCounter2, RISING);
}
void hallCounter1() {
if (motorFWDS== 0) //means motor rot right, so add to hall count
hallCount= hallCount+1;
}
void hallCounter2() {
if (motorFWDS== 1) //means motor rot left, so subtract from hall count
hallCount= hallCount-1;
}
I noticed the current, far minor, challenge:
With the 0.1uf cap, however much I run the motor in the right direction, when I turn it the opposite direction to return to an equal number of rotations/revolutions going left, the hall sensor count ISR triggers more rotating left vs when the motor turns right.
I ran a test to spin the motors both ways for 5, 10, ... 30s at a time one way and then the opposite to try to get the halls back to 0, but the hall count always runs about 3-5% more negative. I used a software motor run time with a delay between motor direction change.
EX)
Trial 1:
With 0.1uf capacitor, For a 30s rotate right, minor pause, then left, hall count starts at 0, goes up to 29,992 counts, then rotating right for 30s, it goes back to -950 counts. In the 2nd trial, same 30s, it went from 0 -> 22,892 -> -822 hall counts. In the Arduino, the hall counts get within 1% each time, within +/- 100 pulses vs +/- 1000 pulses on my teensy. So I am still not optimizing my logic shift circuitry well.
Trial 2:
Used a 0.22uf capacitor for comparison's sake (to see if the hall count discrepancy's were a noise issue), and I got obscure counts. In the same 30s trial of spinning the motor right then left, the halls went: 0 -> 32,000 -> 12,900. So this time the hall sensors' ISR triggered more when the motors spun right and less when the motors spun left.
I think the imbalance ISR triggering is because of some noise issue and/or I used 2 1k resistors going to the +3.3v rail, but the 0.22uf capacitor trial makes me think I need to get an oscilloscope to learn to use/understand what's going on with the halls when I spin the motor both ways.
I drew a basic outline (apologies for using paint vs a nice schematic)