Go Down

Topic: 3 Wire RPM and arduino pro mini (Read 1 time) previous topic - next topic

Axemaniak

Good evening all,

I'm just having some trouble getting my arduino pro mini to read a CORSAIR SP120 RPM.

Ive used the ardunio for a while now and have successfully programmed a 8 position colour filter wheel for my telescope using hall effect sensors, stepper motors etc.

What my end goal for this will be to drive the fan with PWM at a user determined value (VB Coding on PC) and have the current RPM reported back to my VB Form.

I have followed this electrical schematic and copied the code word for word with no luck!

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

Problem:

Sensor reads 0 RPM.

when i change the value of

    void loop ()
    //Set NbTops to 0 ready for calculations
    { NbTopsFan = 0; //changed this to NbTopsFan = 1;

as expected this changes the serial monitor to report 60 RPM and multiples of 60 for the number changing to 2, 3 etc. So it would seem that the interrupt isn't storing the information for the calculation to be correctly made because it is 0 and we all know what 0 devided by gives us!

I have the spark fun protosnap board (Pro mini) that has all manner of sensors but in particular has a RGB LED. I modified the code to attach to Pin3 interrupt and i can see that the pulses are reaching at least the RGB LED (as I put my finger on the fan essentially stalling it I can see the Red LED pulsing).

I have attached the GND of the Aruduino to the GND of my 12V power supply so they are in common.
I have attached the VCC of the Arduino to the RPM output via a 10k ohm resister and to Pin 3.

I guess from here i have to ask is there something that i have neglected to understand as I am at a loss at present.

Regards
Brendan

PaulS

Quote
I guess from here i have to ask is there something that i have neglected to understand as I am at a loss at present.
You have a problem with some vague hardware (no link) connected in some undefined manner (no schematic) to an Arduino running some undefined code. And, you want us to tell you what is wrong.

I ordered a crystal ball off e-bay. As soon as it arrives, I'll let you know what your problem is.
The art of getting good answers lies in asking good questions.

Axemaniak

Good evening PaulS,

No need to be rude Paul, but clearly you haven't read my post a part from the piece you quoted.

I have given you a schematic (please follow the link).

I have given you the code (it is in the link).

I have given you the arduino board I am using (that was the first line).

But to recap!

Hear is the link with the schematic I have followed.

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

Code: [Select]
    //code by Crenn from http://thebestcasescenario.com
    //project by Charles Gantt from http://themakersworkbench.com
    //To disable interrupts: cli(); disable global interrupts and
    //to enable them: sei(); enable interrupts
     
    //Varibles used for calculations
    int NbTopsFan; int Calc;
     
    //The pin location of the sensor
    int hallsensor = 2; typedef struct{
     
    //Defines the structure for multiple fans and
    //their dividers
    char fantype;
    unsigned int fandiv; }fanspec;
     
    //Definitions of the fans
    //This is the varible used to select the fan and it's divider,
    //set 1 for unipole hall effect sensor
    //and 2 for bipole hall effect sensor
    fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1;
     
    void rpm ()
    //This is the function that the interupt calls
    { NbTopsFan++; }
     
    //This is the setup function where the serial port is initialised,
    //and the interrupt is attached
    void setup()
    { pinMode(hallsensor, INPUT);
    Serial.begin(9600);
    attachInterrupt(0, rpm, RISING); }
     
    void loop ()
    //Set NbTops to 0 ready for calculations
    { NbTopsFan = 0;
     
    //Enables interrupts
    sei();
     
    //Wait 1 second
    delay (1000);
     
    //Disable interrupts
    cli();
     
    //Times NbTopsFan (which is apprioxiamately the fequency the fan
    //is spinning at) by 60 seconds before dividing by the fan's divider
    Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
     
    //Prints the number calculated above
    Serial.print (Calc, DEC);
     
    //Prints " rpm" and a new line
    Serial.print (" rpm\r\n");
    }


When I modify NbTopsFan which has been defined as int, the serial print function reads 60 RPM (I have changed it to NbTopsFan = 1 i tried it with =2 and it reads 120 RPM.

So i know that the interrupt is not firing on the pulse of the hall effect sensor in the fan (to recap that is the Coursair SP120 3 wire PC Fan also mentioned).

I made adjustments to the code to move the interrupt from interrupt 0 (Pin 2) to interrupt 1 (Pin 3) because on the SparkFun Protosnap board it has an RGB Led that attaches to pin 3, 5 and 6. I can see the hall effect pulses visually on the LED and at speed it is like PWM aka it just shines without any pulsing as it is too fast for the naked eye.

Is there anything that you can see that would prevent the cold and schematic from working on the SparkFun Protosnap board that is a Pro Mini.

Regards
Brendan


PaulS

Quote
I have given you a schematic (please follow the link).
There was no link. There was a URL. Why wasn't it a link?

Quote
I have given you the code (it is in the link).
That is NOT your code. Your code is something that you have hunt-and-pecked into the IDE (or copied and pasted). It is stored on YOUR computer. That does us no good.

Code: [Select]
    //The pin location of the sensor
    int hallsensor = 2; typedef struct{


ONE statement per line.

Code: [Select]
    //Varibles used for calculations
    int NbTopsFan;

NbTopsFan is modified in the interrupt handler. How is loop() supposed to know that? The ONLY way it can know is if you declare such variables volatile.

Since the URL you are following doesn't do something so simple properly, I wouldn't trust anything else on that site.
The art of getting good answers lies in asking good questions.

Axemaniak

Okay so I have been going though the issue and after 3 weeks of stuffing around I have eventually found the issue.

the code apart from the errors mentioned was fine.

The specific board I was using being a prototyping board had attached a button, light sensor, RGB Led and a buzzer has its own circuitry to make said components work.

This componentry unbeknown to my learner self was interacting with my circuit and thus stuffing the incoming pulses from the Fan Tach. Once removed both interrupts and pulseIn worked.

On a side note due to the fan only being 1450 RPM I have a far more accurate reading of my fan rpm using pulseIn and not utilising the interrupts. I know this uses the ATMEL bandwidth but currently it isn't an issue.

Regards

ieee488

#5
May 29, 2016, 03:07 pm Last Edit: May 29, 2016, 03:07 pm by ieee488
the code apart from the errors mentioned was fine.

::)

Absolutely silly statement.  With any code, if there were not any errors, it would fine too.


That's like saying apart from the hole in the tire it was fine.




Axemaniak

Well thank you for stating that.

I don't know why people bother posting some times.

I apologise for not being absolutely on point with my expressions within something that I am learning.

Hope you have a fantastic night looking at posts to pick these SILLY things out or you might wish to get a life? :)

ieee488

#7
May 29, 2016, 03:45 pm Last Edit: May 29, 2016, 03:47 pm by ieee488
Well thank you for stating that.

I don't know why people bother posting some times.

I apologise for not being absolutely on point with my expressions within something that I am learning.

Hope you have a fantastic night looking at posts to pick these SILLY things out or you might wish to get a life? :)
When you get serious about programming, then you will realize that downplaying mistakes is bad practice.

You ask someone for help. Someone point out the errors. Then you downplay their help by saying that other than those errors that were mentioned, the code works. DUH!  Code without errors would work, wouldn't it?  But you didn't find it. Someone else did. Thank him for it.  

Try getting help in the future with that attitude.  ::)


Go Up