bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

How to read motor's tach out open collector

Sat Aug 11, 2018 8:56 pm

I have this motor which has a tach output that I want to use to read motors RPM.

https://docs-emea.rs-online.com/webdocs ... 328e26.pdf

On page 4 there is a shcematic diagram and it also says Tach output: open collector, 1 pulse per revolution, electrically isolated.

How do I connect tach wire to Pi Zero and which code can I use to read the RPM data?

PiGraham
Posts: 3452
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How to read motor's tach out open collector

Sat Aug 11, 2018 10:40 pm

Connect Pin 4 tacho to a gpio input, connect the GND pin between motor interface and Pi and set a pullup. Set a callback on the input to cout up each time the tach line pulses low.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Thu Aug 16, 2018 6:32 pm

Connected and using internal pullup resistor and it seems to work. I use http://abyz.me.uk/rpi/pigpio/examples.h ... ead_RPM_py to read the RPM. But I am getting quite a low value. Readings are different on different speeds. But they do not match the specs. On max speed the the reading is 970 rpms while the motors max rpm according to specs is 2580rpms. The reasding is way too low. I am setting one revolution which is what the specs say.

I wonder what is wrong. Could there be wrong readings due to internal pullup resistor instead of if I would use external one?

PiGraham
Posts: 3452
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How to read motor's tach out open collector

Thu Aug 16, 2018 6:48 pm

Can you turn the rotor one turn by and see what the tach signal does?

How do you know it's running at 2580? Do you have a separate way to measure it?

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Thu Aug 16, 2018 8:56 pm

My bad. It turns out the readings were correct. I wasn't actually getting full speed as I though. I am controlling the motor using PWM and when I set it to 100% it not really a full speed. I found it out when I controlled it with potentiometer then setting to max it just goes like crazy and I got 2500 something rpm.

so with PWM controll and at 100% pwm signal the motor actually get up to 30% of its max speed. I need to find out why. Any ideas are welcome.

PiGraham
Posts: 3452
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How to read motor's tach out open collector

Thu Aug 16, 2018 9:32 pm

bortek wrote:
Thu Aug 16, 2018 8:56 pm
My bad. It turns out the readings were correct. I wasn't actually getting full speed as I though. I am controlling the motor using PWM and when I set it to 100% it not really a full speed. I found it out when I controlled it with potentiometer then setting to max it just goes like crazy and I got 2500 something rpm.

so with PWM controll and at 100% pwm signal the motor actually get up to 30% of its max speed. I need to find out why. Any ideas are welcome.
What are you using to switch the motor current? I assume a transistor. If that isn't driven to saturation voltage will be dropped across the transistor, the motor will run slow ans the transistor may get warm.
If you are using a bipolar transistor check that it is getting enough base current so that base current * hFE (gain of the transistor) is well above the desired motor current.
If using a FET make sure the gate voltage is high enough to fully turn on the device.


For a comparison you can connect the base resistor or gate to 3V and see if the motor runs as fast as when you connect the motor supply direct to the motor. If not your problem lies there. You might need to change the resistor value or use a different transistor with more suitable specifications.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Thu Aug 16, 2018 9:32 pm

What are you using to generate the PWM signals. And what is the frequency of your PWM signal?

Edit
I assume you use the correct schematic that is provided in you datasheet.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Fri Aug 17, 2018 11:24 am

I use yello(tacho9 and blue (GND) pins to control the motor speed using PWM signal from pi zero. I connect them to pins 12 (BCM18/PWM0) and 14(GND) . Then I use the following script to send the PWM signal out on pin 12. It starts at 50% PWM and goes up to 100% which is 970rpm of possible 2580.

I have tried different PWM freqs like 2000hz , 5000hz and even sub-1000Hz.

Code: Select all

#!/usr/bin/env python

import time
import pigpio

pi = pigpio.pi()
freq=5000

if not pi.connected:
   exit()

for pwm in range(500000, 1100000, 200000): # start from 50% and go up to 110% PWM
   pi.hardware_PWM(18, freq, pwm)
   print("\n12 set {} got {} pwm={}%".format(
     freq, pi.get_PWM_frequency(18),pwm/10000))
   time.sleep(5)

pi.hardware_PWM(18, 0, 0)

pi.stop()
~
~


Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Fri Aug 17, 2018 12:16 pm

I think you need to add a transistor and resistor to the output of your pi, as shown in the schematic below (customer circuit):
emea_pwm.PNG
emea_pwm.PNG (14.12 KiB) Viewed 1664 times
And "15V" is probably connection (3).

edit
bortek wrote:
Fri Aug 17, 2018 11:24 am
100% which is 970rpm of possible 2580.
To confirm if you read the correct max speed. You could try this:
emea_pwm_max.png
emea_pwm_max.png (9.71 KiB) Viewed 1640 times
Than the motor will run at 2580 rpm, according to the datasheet. And this give you te possibility to check if you can read / calculate the speed correct.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Fri Aug 17, 2018 8:23 pm

Yes thats what I actually tested and reported in the previous posts. If I short pins 2 and 3 of the motor I get a full blow and RPM reported is something above 2500.

And you might be right now :) when I look at the diagram it might look like they want transistor, resistor and diod to be connected in front of pins 1 and 2. Why is the base of transistor not connected?

What do you mean by this
And "15V" is probably connection (3).
Getting 15V will be kind of tricky since I only have 5V to pi. I would need some sort of step-up.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Fri Aug 17, 2018 8:40 pm

bortek wrote:
Fri Aug 17, 2018 8:23 pm
What do you mean by this
And "15V" is probably connection (3).
Getting 15V will be kind of tricky since I only have 5V to pi. I would need some sort of step-up.
The fan give you acces to a 10V power supply. And you could use this instead of the 15V they are recommend to you. However it's possible that you wouldn't get the full speed. But that something you could try out.

The base is connected, via a resistor, to one one of you output of you pi. And they assume that the "device" that you are connecting to the fan has this kind of circuit to control it.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Sat Aug 18, 2018 3:31 am

Ok let me try jt iut. Any suggestions on which transistor, resistance and diodeti choose?

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Sat Aug 18, 2018 11:47 am

bortek wrote:
Sat Aug 18, 2018 3:31 am
Ok let me try jt iut. Any suggestions on which transistor, resistance and diodeti choose?
Do you have some transistors lie around, that you could use (BC547, ect..)

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Mon Aug 20, 2018 7:07 pm

No I don't have any but I can order some online. Which one ?

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Mon Aug 20, 2018 9:10 pm

Hello,

You could use the schematic below. I think you don't need to place the 12 Zener diode, because your supply is only 10V. But it doesn't hurt if you want to place it. If you "don't" trust yourself with connection something to you pi, you could use a optocouple instead. (If the 10V touch you gpio pin, you pi is dead).
sim bc547 fan.jpg
sim bc547 fan.jpg (182.06 KiB) Viewed 1486 times
If you have any question, please let me know.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Sat Sep 08, 2018 8:51 pm

An update. Now I am at the country house where the fan is located. I built everything according to the schematic and also added zener diod. I connected V2 on your schematic to pin3 of the motor where it supplies with 10v from motor.

Now what happens is that motor goes into full blow at 10% pwm and i measure 9v between pin2 and pin3.
At 70%pwm I measure 3v and lower rpm, at 80%pwm i measure 2v, at 90% measure 1v and low rpms. In other words rpm decrease when pmw increase, it kinda works but the other way around.

I triple checked connections and they are according to the schematic you drawn.

What have I done wrong?

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Sat Sep 08, 2018 9:27 pm

Good to hear your feedback.

Well, as I read you feedback. It's is working as it should. Because one transistor in this setup will invert your signal. I thought it would work like that, because of the information in there diagram. But apparently it does not.

However it is a easy fix. You can add a extra transistor, or you can fix it in software.

For example, if you duty cycle value is from 0 - 100:

Code: Select all

duty_invert = 100 - duty_cycle


This will produce the correct duty cycle for you.

But, good to hear that you can control the motor.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Sun Sep 09, 2018 7:45 am

It works. :) Thanks again for your help. I can spin motor now from zero to its max rpm and even read rpm on tacho pin.

I learned something new during this little troubleshooting journey. 👍

Now I wonder how shall the inverter transistor be connected to invert the signal electronically (as
u suggested) insteadof programmatically?

Btw which soft do you use ti draw the circuit and test signals?

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Sun Sep 09, 2018 8:37 am

I use te program ltspice and it's a complete free to use :)
(Note: I changed the colours in the program itself.)

About the other transistor:
Maybe it's a good exercise in ltspice to get the signal inverterd. By adding a single transistor and a resistor. Or I can give you the answer, if you want.

Good to hear that you can control the motor :)

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Sun Sep 09, 2018 3:22 pm

So, I tryed something out.
If you pasted the code below into a new notepad file. And when you saved that file. Change the name into "simulation.asc". Than you can open that file in LTspice and you get the simulation I made previous.

Code: Select all

Version 4
SHEET 1 928 680
WIRE 320 -32 176 -32
WIRE 448 -32 320 -32
WIRE 176 0 176 -32
WIRE 448 80 448 -32
WIRE 176 96 176 80
WIRE 288 96 176 96
WIRE 176 112 176 96
WIRE -32 160 -320 160
WIRE 80 160 48 160
WIRE 112 160 80 160
WIRE -320 176 -320 160
WIRE -320 272 -320 256
WIRE 176 272 176 208
WIRE 448 272 448 160
FLAG 176 272 0
FLAG -320 272 0
FLAG 448 272 0
FLAG -320 160 Gpio
FLAG 80 160 Vbase
FLAG 288 96 Pin2
FLAG 320 -32 Pin1
FLAG 320 272 0
SYMBOL npn 112 112 R0
SYMATTR InstName Q1
SYMATTR Value BC547B
SYMBOL res 160 -16 R0
SYMATTR InstName R1
SYMATTR Value 1k
SYMBOL voltage -320 160 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V1
SYMATTR Value PULSE(0 3.3 0.1m 10u 10u 250u 500u)
SYMBOL res 64 144 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R2
SYMATTR Value 470
SYMBOL voltage 448 64 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V2
SYMATTR Value 10
TEXT -322 328 Left 2 !.tran 1m
TEXT 296 256 Left 2 ;Pin3

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Sun Sep 09, 2018 3:25 pm

Great. Will try it tonight. I hope this one is without extra transistor cause I want to find out myself how to invert the signal. 😂

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Sun Sep 09, 2018 3:32 pm

Yes, this is without the extra transistor.
It is the schematic from this post.
Brandon92 wrote:
Mon Aug 20, 2018 9:10 pm
You could use the schematic below.

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Tue Sep 11, 2018 8:30 pm

Hi

Here comes another update. :) thanks for the code first of all.

After many clicks in LTspice I was able to get the same view as you had on your pics. Then with the help of some googling and reading up on transistors I came up with these modification. According to simulation we have the inverted signal on PinX which is what I wanted. Is it correct and how would you place your transistor and resistor ? The diode is zener 1N4742A, not the one on the schematic.
sim.JPG
sim.JPG (136.84 KiB) Viewed 1212 times

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: How to read motor's tach out open collector

Wed Sep 12, 2018 8:22 pm

Good to see that you find the solution.
But, does the zener protect you input of your fan? If the voltage is higher than 12V. You can check it by adjusting the V2 voltage source to 15V and see what happens ;)

bortek
Posts: 14
Joined: Thu Feb 23, 2017 7:25 am

Re: How to read motor's tach out open collector

Fri Sep 14, 2018 6:48 pm

Hehe good catch. I forgot to move the diode of course :) Now this looks better. I have also tested as you suggested higher V2 and the simulation keeps it tight up to 12V :)

Perhaps I should rewire my PCB to this , just for fun ;)
sim2.JPG
sim2.JPG (137.28 KiB) Viewed 1170 times

Return to “Automation, sensing and robotics”