Pages: 1 2 [3] 4 5   Go Down
Author Topic: Count how many pulses per second  (Read 5369 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How does it work?
How long have you got?

Basically, a transistor amplifies current.  You put a small current in to the base, and you control a large current flowing through the collector->emitter.  With Ohm's law, it is effectively going from a small voltage (the fan) to a large voltage (the 0->5v switching signal).

A transistor only has a limited amount of amplification it can do - any more than that and it becomes "saturated" - that is, the waveform becomes clipped off at the top and bottom.

A transistor can only amplify positive voltages.  Like a diode, if you put a negative voltage in, it gets blocked.  So, to combat that, you add an extra voltage to the incoming signal - the "offset voltage".  This makes the negative voltages coming in positive, and pushes up the positive voltages to make them higher, so the whole incoming waveform is made up of positive voltages.

It is important to get the level of this offset correct, so that the output, which will also have a proportional offset, isn't completely in the saturation area.  If that happens, then the transistor will be permanently on.  We don't care about some clipping - in fact, as it is a digital input, we like clipping.  It makes for a good clean square wave that the input likes, so the more amplification the better.  Different incoming offsets will provide different amounts of amplification due to the way a transistor works, so hitting a sweet spot, or "operating point" can make the output signal just what we want.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How does it work?
How long have you got?

Basically, a transistor amplifies current.  You put a small current in to the base, and you control a large current flowing through the collector->emitter.  With Ohm's law, it is effectively going from a small voltage (the fan) to a large voltage (the 0->5v switching signal).

A transistor only has a limited amount of amplification it can do - any more than that and it becomes "saturated" - that is, the waveform becomes clipped off at the top and bottom.

A transistor can only amplify positive voltages.  Like a diode, if you put a negative voltage in, it gets blocked.  So, to combat that, you add an extra voltage to the incoming signal - the "offset voltage".  This makes the negative voltages coming in positive, and pushes up the positive voltages to make them higher, so the whole incoming waveform is made up of positive voltages.

It is important to get the level of this offset correct, so that the output, which will also have a proportional offset, isn't completely in the saturation area.  If that happens, then the transistor will be permanently on.  We don't care about some clipping - in fact, as it is a digital input, we like clipping.  It makes for a good clean square wave that the input likes, so the more amplification the better.  Different incoming offsets will provide different amounts of amplification due to the way a transistor works, so hitting a sweet spot, or "operating point" can make the output signal just what we want.
I'm not sure i got all that becuase my english is not fantastic. But when i put a voltage on the base. +5V thourgh the 1k restistor, isn't it that who gives the transistor the 0,6V it needs to work not the pulse from the fan? And if my calculations is right you get a voltage of 4.1V over the 1k resistor, there for 4.1V to the base on the transistor, or am I wrong? And i still don't get the 10k resistor. Maybe I'm to stupid. 
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The 10K resistor is the same 10K resistor you would have if you had a simple pushbutton instead of a transistor.  The transistor is just taking the place of that pushbutton.

The 1K resistor works with the 220Ω resistor.  They divide the voltage between them using the formula:
(220 / (1,000+220)) * 5V

Which is (220 / 1220) * 5

Which is 0.18 * 5

Which is 0.9V at the point between the two resistors.  This is the offset voltage.  On top of that is placed the signal from the fan.  That is an AC waveform which is (for example) swinging between -0.5v and +0.5v.  So, with the added 0.9V, the waveform now swings between +0.4v and +1.4v.  This swings nicely around a good operating point for the transistor so it goes into saturation during the upper portion of the wave, and is switched off in the lower portion of the wave.

As the transistor switches on and off it connects and disconnects the 10K resistor to ground.  When the transistor is off, you measure the full 5V at the point between the 10K and the transistor.  When the transistor is on (saturated), you measure 0V (slightly higher due to the junction drop of the transistor) at that point.  Just like a pushbutton.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So the offset voltage is the same as the voltage you get over the 220 ohms resistor if you are doing your calculations following ohms law?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, the offset voltage is a proportion of the 5V as set by the ratio of the 1K to the 220Ω.  It has nothing to do with Ohm's law.  Yes, you can do Ohm's law calculations on it, but that would just yield you the current flowing through the combined 1K and 220Ω, not the voltage at the mid point.

Read http://en.wikipedia.org/wiki/Voltage_divider for more detail.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And when the transistor is closed the led is high, and when it is open the led is low?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, the offset voltage is a proportion of the 5V as set by the ratio of the 1K to the 220Ω.  It has nothing to do with Ohm's law.  Yes, you can do Ohm's law calculations on it, but that would just yield you the current flowing through the combined 1K and 220Ω, not the voltage at the mid point.

Read http://en.wikipedia.org/wiki/Voltage_divider for more detail.

But if you do like this.

1000+220=1220
5/1220=0,0040983
0,0040983*220=0,9

The voltage over the 220 ohm resistor = 0,9V
You said that the offset voltage was 0,9V
Isn't that Ohms law I have used.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you two are discussing different circuits. The one Majenko laid out before has no led?

Himym, for a red led needs IIRC at least 180 ohms resistance with 5V to keep it from burning up. Most are using 220 ohm, I don't like it so bright so I use 330, 470 or more. What you did shows that even boosted, your fan to transistor is not enough to allow much current flow or maybe some other resistor is moderating current flow.
Do you have a resistor between the fan and transistor grid? Or one between power and transistor collector?

Logged

Examples can be found in your IDE.

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Isn't that Ohms law I have used.
Yes, that is Ohms law, and it is possible to calculate it using Ohms law, but it is rather convoluted.  You calculate the current through the divider, then calculate the voltage drop across one resistor using that current.

It is much easier to calculate the ratio of the resistors (220/(1000+220)) and then multiply that by the voltage across the whole divider.  That way you don't need to worry about the current.  The ratio will be a static value regardless of the voltage.  If you use a voltage divider to, for example, reduce a voltage to fit into the range of an ADC input, then the voltage coming in will be changing.  Thus, the current will be changing.  Your way would mean calculating the current for every possible voltage to know what the output of the divider would be for that voltage.  Using the ratio you know that it will always be a specific proportion of the input.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you two are discussing different circuits. The one Majenko laid out before has no led?

Himym, for a red led needs IIRC at least 180 ohms resistance with 5V to keep it from burning up. Most are using 220 ohm, I don't like it so bright so I use 330, 470 or more. What you did shows that even boosted, your fan to transistor is not enough to allow much current flow or maybe some other resistor is moderating current flow.
Do you have a resistor between the fan and transistor grid? Or one between power and transistor collector?


I'm using majenkos circuit. I just conected a led to the collector on the transistor. But I'm not using a resistor in serie with the led, becuase when I used a 220ohm resistor the led didn't work.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's because it wasn't getting enough power, probably because it's running off 5V through the internal pullup resistor which is about 20k ohms. Whatever you do, don't set that pin to OUTPUT!
Logged

Examples can be found in your IDE.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's because it wasn't getting enough power, probably because it's running off 5V through the internal pullup resistor which is about 20k ohms. Whatever you do, don't set that pin to OUTPUT!

What do you mean. Which pin should I not set to output?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The one that you are using for INPUT to read the fan. I did forget that in Majenko's circuit (that I just looked at again) the internal pin pullup isn't the only possible power source to the transistor. It also gets Vcc (5V) through 10k ohms. When the transistor is OFF the pin will read HIGH. When the transistor is ON it grounds the power, the pin will read LOW, and your led gets 5V through 10k ohms which is enough to light it dim.

I bet you could put 220-1k ohms instead of the 10k resistor, get a brighter led and hurt nothing.
But you don't need to now since you know the fan data must be readable.

Use digital instead of analog read and set up a Pin Change Interrupt. The interrupt will stop the regular program, turn interrupts off, run a special -short- routine you make (like "pulse++;") and turn interrupts back on (plus some register saving you don't care about now) and then resume your regular code like nothing happened. Your program can watch microseconds go by (with micros()) until 1 second is up and see how many pulses were counted. You can know to within 4 microseconds I think.

If instead you just watch the pin you might be able to tell about how even the pulses are.

There is a pulseIn command to measure ulse widths but I see people get results with variance using it.
Logged

Examples can be found in your IDE.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The one that you are using for INPUT to read the fan. I did forget that in Majenko's circuit (that I just looked at again) the internal pin pullup isn't the only possible power source to the transistor. It also gets Vcc (5V) through 10k ohms. When the transistor is OFF the pin will read HIGH. When the transistor is ON it grounds the power, the pin will read LOW, and your led gets 5V through 10k ohms which is enough to light it dim.

I bet you could put 220-1k ohms instead of the 10k resistor, get a brighter led and hurt nothing.
But you don't need to now since you know the fan data must be readable.

Use digital instead of analog read and set up a Pin Change Interrupt. The interrupt will stop the regular program, turn interrupts off, run a special -short- routine you make (like "pulse++;") and turn interrupts back on (plus some register saving you don't care about now) and then resume your regular code like nothing happened. Your program can watch microseconds go by (with micros()) until 1 second is up and see how many pulses were counted. You can know to within 4 microseconds I think.

If instead you just watch the pin you might be able to tell about how even the pulses are.

There is a pulseIn command to measure ulse widths but I see people get results with variance using it.

Can you please give me an idea how that code would look like?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like the code here:
http://arduino.cc/playground/Main/PcInt



Logged

Examples can be found in your IDE.

Pages: 1 2 [3] 4 5   Go Up
Jump to: