Teensy LC reading RPM stopped working

Status
Not open for further replies.
I am doing a projekt where I am reading the Hall sensor on Pc fans with an Teensy LC for that i used following circuid only changing the pullup form 5 to 3.3V:

themakersworkbench.com/content/tutorial/reading-pc-fan-rpm-arduino

At first it worked like a charm but as soon as I turned off the fan the Teensy startet to connect and disconnect the Serial Terminal pretty fast. That stopped when i pulled out the wire connected to the Hall Sensor and the pullup but now it stopped working.

Can anybody tell me what i have done wrong?
 
No, I don't believe anyone could say with certainty what went wrong, from only these words you're posted.

If the 12V power accidentally touches Teensy, even for a brief moment, the board is probably damaged. The very first step is to turn off auto mode in Teensy Loader (click the 4th button in the toolbar) and then press the button on Teensy. If the hardware is still working, Teensy Loader should detect the board. If it's still working, try using Arduino to load the LED blink example. The goal is to check if your Teensy still works and can still upload programs.
 
No, I don't believe anyone could say with certainty what went wrong, from only these words you're posted.

If the 12V power accidentally touches Teensy, even for a brief moment, the board is probably damaged. The very first step is to turn off auto mode in Teensy Loader (click the 4th button in the toolbar) and then press the button on Teensy. If the hardware is still working, Teensy Loader should detect the board. If it's still working, try using Arduino to load the LED blink example. The goal is to check if your Teensy still works and can still upload programs.

Programming works without problems and i even added a blink seqenz to my programm and that keeps running it just dosen`t use the serial communication anymore. That happens when i turn the PWM dutycycle with which I am controlling a Transistor from 100% to 99% and below. so if i turn it down it stops sending but still recives and i have no Idea what the hell is going on.
And if I turn it to 0 the teensy starts resetting.
 
Last edited:
This is my code:

int pin = 6;//PWM pin
int i1 = 22; // InterruptPin
int speed = 100; //Initial speed
int numints; //variable for interrupt
void inter(); //fuction prototypes
void setspeed(int pin, int s);
int a = 100,b,c,d;

void setup()
{
pinMode(pin, OUTPUT);
pinMode(13, OUTPUT);

pinMode(i1, INPUT);
Serial.begin(115200);
analogWriteFrequency(pin, 375000);
analogWriteResolution(7);
analogWrite(pin,0);
attachInterrupt(i5,inter,RISING);

}
void loop ()
{
digitalWrite(13,HIGH);
if(Serial.available()){ // change speed
delay(10);
speed = Serial.parseInt();
if(speed > 30)
setspeed(pin,speed);
else
setspeed(pin,0);
Serial.println(speed);
}
//-----------------
if(speed > 29){

setspeed(pin,100); Set the dutycycle to full on / pin to HIGH to not confuse the Hall sensor with the PWM
numints = 0; // reset number of interrupts
sei();// enable interrupts
delay(250);
cli();// disable interrupts
Serial.println(numints*80); //calculate the rpm
setspeed(pin,speed);
}
else{
a=0;
}
digitalWrite(13,LOW);
delay(3000);
}
void inter(){
numints++; // interrupt just count the number of times it has ben interrupted
}
void setspeed(int pin, int s){ // easier way to not having to write the map function in every analog Write
analogWrite(pin,map(s, 0, 100, 0, 127));
}

I hooked the tachowire like described in the picture with the difference that the pull-up is to 3.3V and the fan is driven by a Transistor

Fan_RPM_Arduino_0.jpg
 
Turning off the interrupts will stop USB Serial and the timer functions like delay from working.
 
Serial.println() should not be called with interrupts disabled. If it needs to wait for USB buffers to become available, the wait could stall forever because the USB interrupt can't run and can't return buffers from previously transmitted data back to the available buffer pool.
 
Serial.println() should not be called with interrupts disabled. If it needs to wait for USB buffers to become available, the wait could stall forever because the USB interrupt can't run and can't return buffers from previously transmitted data back to the available buffer pool.

Turning off the interrupts will stop USB Serial and the timer functions like delay from working.

So i removed the sei and cli functions and still the same issue.
 
Maybe you should post the code you're actually using?

I copied your code from message #4 into Arduino. It does not even verify. There are multiple compile errors, so this obviously can't be a real copy of whatever code you are actually running.
 
The problem is that after reading a speed value with Serial.parseInt() , in the next loop the end of line character is parsed as speed 0, after a timeout in parseInt(), and the output is turned off by the test that checks if speed is > 29.
 
The problem is that after reading a speed value with Serial.parseInt() , in the next loop the end of line character is parsed as speed 0, after a timeout in parseInt(), and the output is turned off by the test that checks if speed is > 29.

No it is not i have no problem with getting the PWM to work it is just the reading parsInt cuts away white spaces if u send "100 60" and do pars int u get 100 and then 60 no problem
 
int pin = 6;
int maxrpm = 0;
int i1 = 22;
int speed = 100;
void inter();
int numints;
void setspeed(int pin, int s);
int a = 100,b,c,d;

void setup()
{
pinMode(pin, OUTPUT);
pinMode(13, OUTPUT);

pinMode(i1, INPUT);
Serial.begin(115200);
analogWriteFrequency(pin, 375000);
analogWriteResolution(7);
analogWrite(pin,0);
attachInterrupt(i1,inter,RISING);

}
void loop ()
{
digitalWrite(13,HIGH);
if(Serial.available()){
delay(10);
speed = Serial.parseInt();
if(speed > 30)
setspeed(pin,speed);
else
setspeed(pin,0);
Serial.println(speed);
}
//-----------------
if(speed > 29){
a = 250/speed *(100-speed);
setspeed(pin,0);
delay(a);
setspeed(pin,100);
numints = 0;
//sei();
delay(250);
//cli();
Serial.println(numints*80);
setspeed(pin,speed);
}
else{
a=0;
}
digitalWrite(13,LOW);
delay(3000);
}
void inter(){
numints++;
}
void setspeed(int pin, int s){
analogWrite(pin,map(s, 0, 100, 0, 127));
}

here again the code that works for me hope it works now
 
Try adding :

Code:
Serial.print("speed:");
Serial.println(speed);

So you can see what output comes from where, and then some extra print close to the a=0 :

Code:
else{
Serial.println("speed is < 29");
a=0;
}
 
Found the Problem was in the circuid but i don`t Understand why it happens can anybody tell me? so i added an Diod into the Tacho signal like this:
a.png

And Now it works.

But WHY?????
 
Status
Not open for further replies.
Back
Top