Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help with measuring RPM of wind turbine using IR emitter/detector and 8051

Status
Not open for further replies.

Nisca

Newbie level 6
Joined
Nov 7, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,378
Basically, there are three blades attached to the hub. I'm trying to use beam breaking method i.e. a pulse is recorded when beam breaks. the steps that I want to implement in my code to achieve my goals are;

1) Measure the time (x) between 1st and 2nd cut. this would be (1/3rd) of period of one revolution. therefore, multiplying it by 3 would give period of 1 revolution.
2) Using RPM = Frequency * 60 would give me the answer in minutes.
3) I want to keep doing this in a loop forever and display it on LCD.


Does my logic makes any sense, is the relationship between RPM and Frequency true? and is it possible to measure the time between two pulses using timers in 8051?,given that the time would be in micro seconds, perhaps.

also, I just need pulses, 5volts = 1 and 0volts = 0 from sensors so I don't need ADC. So, how do I interface my IR with 8051(AT89S51)?
IM USING C language.

I'd really appreciate if anyone can sort me out..

Cheers!!!
 

You are right. You start a timer when the first blade crosses the beam and stop it when the 2nd blade crosses. The counter will give you the number of counts that elapsed. If you know the freq that increments the counter then you can calculate the elapsed time.
To increase precision you can increment the freq of the counter and the number of bits that it will have. May be extending the hardware timer in software.
A better way could be starting the counter on the first blade and ignoring the 2nd and 3rd and then stopping when the 1st.crosses again. This cancels a possible error if the blades are not equally spaced and you dont have to divide by 3.
You can repeat this again and again or accumulate the periods and then calculate the mean which will give more precision.
 
  • Like
Reactions: Nisca

    Nisca

    Points: 2
    Helpful Answer Positive Rating
I just need pulses, 5volts = 1 and 0volts = 0 from sensors so I don't need ADC. So, how do I interface my IR with 8051(AT89S51)?




Here is the image how you should interface IR with MCU, to get 5V & 0V as o/p.
 

Attachments

  • IR ckt.jpg
    IR ckt.jpg
    42 KB · Views: 92

Thanks you for your prompt response. I took you advice into consideration. umm basically I tried something different to calculate the RPM. here is my piece of code commented for better understanding. Could you please go through it and tell me if I've implemented it right and if it makes any sense? I'd really appreciate that....

#include<reg51.h>
sbit IR = P1^0; //setting IR reciever for Port 1.0
int is1=0;

void Timedelay() // time delay for 1 second
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}

void takinginput()
{
unsigned int is2=0;
int n=0;
P1=0xFF;
for(n=0;n<=20;n++)
{
Timedelay();
if(IR!=0); // if IR on port 1.0 goes 1 i.e. detects 5 volts
{
is2++;

}
}
is1=is2;
//RPMcalculation(zis) GOES INTO ANOTHER FUNCTION WHERE RPM IS CALCULATED and FROM THERE TO LCD display
}



void main()
{
while(1)
{
takinginput();
}
}

// NUMBER OF PULSES IN 1 SECOND WOULD BE DIVIDED BY THREE because of three baldes.
// THAT = TOTAL REVOLUTION IN 1 SECOND
// MULTIPLY BY 60 TO GET RPM
 

Well according to me the following editing should be make.
& better to use unsigned char where the variable value is limited (for ex. n is less than 20 !, then no need to use "int n")

void takinginput()
{
unsigned int is2=0;
int n=0;
P1=0xFF;
for(n=0;n<=20;n++)
{
Timedelay(); // this function is not placed properly... it will add 50 ms delay every time !!!!
if(IR!=0); // if IR on port 1.0 goes 1 i.e. detects 5 volts
{
is2++;
for(;IR == 1;); // wait for getting P1.0 to low.

}
}
is1=is2;
}


[/I]
 
  • Like
Reactions: Nisca

    Nisca

    Points: 2
    Helpful Answer Positive Rating
Hey Jigr,
Thanks for your prompt response.
Basically, I'm trying to count number of pulses in 1 second. that is number of 5 volts when beam breaks by blades.
total pulses=counts in 1 second / 3 would give me total revolutions in 1 second.
Multiplying that by 60 would give me RPM. I wanna keep on doing this in a loop.

I don't understand why you've added; for(;IR == 1;); // wait for getting P1.0 to low.?
50ms, 20 times gives me 1 second delay but have I not used it properly?
should I add counting of pulses in time delay function?

Also, you quote at the end is quite motivational. , "Never Leave it until you did it.Every time you fails go for one more time"

Thanks once again!
 

Nisca,
I didnt have time to check your source yet. But here are some comments.
What is the range of RPM that you want to measure and with what precision?
I think that measuring the period will give you more precision than counting the 3 blades during 1 sec.
for example 1000rpm will give you 50 pulses and 1020rpm gives 51pulses. Counting for more than 1 sec will give more precision but it will take longer to measure.
BTW just multiply by 20 (60/3).
 

50ms, 20 times gives me 1 second delay but have I not used it properly?


okay, let it be clear that:

first you need to measure the how many times IR (p1.0) gets high in 1 second.

so for that you've make a delay of 50 ms & make loop to add that delay 20 times.
BUT you've not used that properly.

WHY?

well, in for loop first you've set a counter to 0 (n=0) & end value to 20.
then you're adding a 50 ms delay!
now you're checking whether the IR is high or not---> suppose it's high, then you're incrementing the is2 variable.
now after that n=1 & again you're adding 50 ms delay ... and so on...

So problem is you're adding a delay of 50 ms every time before checking the IR bit.
so in short, in complete 1 sec. you're checking the IR bits for only 20 times !!!

but in actually, you need to keep monitoring it for complete 1 sec. (not for only 20 times in sec.)& need to increment is2 for
whenever it gets high & after 1 sec. that loop should be end.




I don't understand why you've added; for(;IR == 1;); // wait for getting P1.0 to low.?

well that is to wait in that same loop till the IR gets low.
because if we don't do that, then is2 will get incrementing till the Ir gets low.
normally IR will stay high for more than 1 ms (for less than speed of 60000 rpm), so we need to wait till it gets off, other wise
controller will keep adding is2++ for 1ms. (though in you're code you're adding 50 ms after every count so this error gets covered under
that big error--- but check it in my code (see below))

well you can use for(;IR == 0;); or while(IR==0); to wait till IR = 0


so you need to go for following code:

Code:
void Timedelay()         interrupt 1                    // time delay for 1 second
{
      n++;                                                      // define n as char globally 
      if(n==20)                                               // only satisfies after1 sec. 
      {
              ET0 = 0;                                        // stop timer interrupt immediately when 1 sec completes.
              // now check the value of is2 (i.e. is1 = is2 should place here)
              //RPMcalculation(zis) GOES INTO ANOTHER FUNCTION WHERE RPM IS CALCULATED and FROM THERE TO LCD display
              // after displaying now again we need to start 1sec timer so....            
              TL0=0xFD;
              TH0=0x4B;
              ET0 = 1;                                        // start timer interrupt agian
              TR0=1;                                         // start timer.
      }
}

void takinginput()
{
     unsigned int is2=0;
     P1=0xFF;
     TR0=1;                                                // start timer
     while(1)                                                // infinite loop
     {
             if(IR!=0);                                      // if IR on port 1.0 goes 1 i.e. detects 5 volts
             {    
                    is2++;
                    while(IR == 1);                     // wait for getting P1.0 to low.
              }
     }

void main()
{
     TMOD=0x01;
     TL0=0xFD;
     TH0=0x4B;
     EA=1;                                                // enable interrupts
     ET0=1;                                               // enable timer 0 interrupts
     takinginput();
}
 
Last edited:
you are a savior Jigr!
OK, I took your advice and amended my code as you advised me to do. I added the RPM calculation and LCD display as-well. I've messaged you the whole code
separately.
I tested the LCD bit of the code on Proteus software and it works but couldn't find IR components to test my code on Proteus simulation software.
I wanted to ask you about the IR sensors, you attached an image of IR reflective sensors couple of days back but the problem is that
I couldn't find them in UK. I got my hands on the one I've attached along with that I've also enclosed the circuit as-well.
In all honesty, I got this circuit from one of my friends, I changed a little bit and tried implementing it but it doesn't work. could you point out what could be the problem?
and do you recommend any other IR sensor?

Thank you for all the help so far!!!

- - - Updated - - -

I think that measuring the period will give you more precision than counting the 3 blades during 1 sec.

Thanks for your response,
You are quite right about it but I couldn't get my head around measuring period for every 3rd pulse and then calculating RPM. I'd really appreciate if you can help me out with that, my precision would increase by a knock amount.
I'll be using a standard pedestal fan with RPM of about 2000 as my source of wind.
I've messaged you my code so far, took help from "jigr 4 electronics". LCD bit is tested but couldn't test the IR sensor bit because of problems in circuit.
I've attached the circuit and IR sensor in my response to "jigr" above.
Do you reckon, I should use another IR sensor? what do I've to do with my code in order to implement your way??
 

Attachments

  • pRS1C-2110714_rshalt1_dt.jpg
    pRS1C-2110714_rshalt1_dt.jpg
    8.6 KB · Views: 75
  • IR circuit.jpg
    IR circuit.jpg
    12.3 KB · Views: 87

After you resolve the measurement problem. Consider all the environmental cases of disturbances from ideal.

- Zero wind, A fixed time, time interval counter should be limited or a sanity timer on overflow processes.
- Averaging and throw out false readings from noise injection on sensor.
- Results when LEd reduces by 50% from aging and detector noise from full sunlight. Make sure you have IR blocking filter and adequate sunlight aperture block.
- effects of supply variation, temperature variation and noise.
 

whenever you get your problem solved do share your solution/mistakes here so that other can have your reference.

Will sure do Jigar, Thanks for all the help!!!
I'll implement the circuit and do everything you've advised me to do. This will take a day or two so I'll get back to you if the problem persist. PLEASE DON'T DISAPPEAR ON ME. :)
Thanks you!!!
 

Here is what you need for more than 1 sensor & to detect them through LED.
but the resistor values will be the same which we've discussed.
 

Attachments

  • IRcircuit.gif
    IRcircuit.gif
    7.3 KB · Views: 80

Here is what you need for more than 1 sensor & to detect them through LED.
but the resistor values will be the same which we've discussed.

Hi Jigar,
Hope you are keeping well. Thanks for the attachment.
I tried implementing the circuit but my values of RPM are not constant. It keeps fluctuating and at times go to -ve. I'm still working on it and Ill post everything I did after successful implementation.

Could you please tell me what could be the problem? and could you please send me hall effect sensor tutorials you mentioned the other day?

Im using L-7113F3BT (IR LED) and L-7113P3C (photo transistor)

Thanks a lot!!!
 

Thanks man!!!
Good links!! :)
 

HI, I want to use this USBASP,
**broken link removed** to program my 8051 (AT89S52) but I do not know where to begin..
I'd really appreciate if someone could walk me through the process.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top