User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Pool Pump and PWM/GPIO speed control

Sun Sep 30, 2012 1:29 pm

Hi

I'm currently using a Raspberry Pi to control my pool pump (NTP means it'll always turn on at the right time... and it's easily programmable).

I was wondering, would it be possible to use the Pi to control the speed of the pump ? The pump is a 750w, single phase device. It has a capacitor on it.

What if I were to use the Pi to turn it on and off very quickly ? Perhaps 500Hz and then every 5th cycle turn the pump off and back on ? I'd probably have a relay to remove the capacitor from the circuit ? Would this be okay for the pump ? Would a relay be suitable for this or will it fail to handle the high switching speed ? Any advice is appreciated.

And on this note... can anyone recommend how I should go about directly accessing the GPIOs through Debian/Raspbian's /dev/mem device (what bit at what address controls the state of the GPIO, direction, etc.) .

Thanks :D
EOF

janek
Posts: 8
Joined: Sun Aug 05, 2012 4:10 pm

Re: Pool Pump and PWM/GPIO speed control

Mon Oct 01, 2012 6:39 pm

Hi, although I'm using pump of lower powr (~50W) I've done some reading about this subject and the best solution I could get was to turn pump on and off again every X seconds.
So if I would like to run it at 20% speed: 4s wait, 1s work.
This way triac circuit (220V switch in my solution) will not go too hot and pump motor windings also stay cool.

This is originally not my idea, but someone's with great experience in solar collector pump driving.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 11:04 am

Hi Janek

Thanks for the thought, but it would be damaging and highly inefficient to turn a pool pump (single phase, 240VAC induction motor) on and off for seconds at a time.

However, you mentioned a magical word : "triac"

And this has got me thinking; Triacs can turn loads on and off very quickly, they're basically solid state relays. So my plan is to use a small triac, under the influence of a gpio on the Pi to supply power at the correct time to an array of triacs in parallel which in turn will turn the pool pump on and off very quickly. "Very quickly" is at least 3kHz.

This is essentially what I want to create : http://www.freescale.com/webapp/sps/sit ... RDHC08ACIM

I still need to work out whether or not the capacitor for the pump should be disconnected before PWM is applied to the line... and I need to work out/find out how to use hardware PWM on the Pi's "special" GPIO pin (as opposed to running this in softwate).

I'm going to go and buy some triacs today yay :) .
EOF

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 2:57 pm

Here's a thought... PWM... on the audio output... ? 44.1kHz sample rate... :D :D :D
EOF

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 2:59 pm

That is a thought!
Ostendo ignarus addo scientia.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 3:18 pm

I just found a programme I wrote 4 years ago that used the audio output as an Software Defined Radio (emulated DCF77 time signals)... gonna quickly hack it to do PWM.
EOF

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 5:36 pm

The result of a square wave output to the audio interface :
Image
Image
The core chunk of code that generated this (Java) :

Code: Select all

for (int i = 0; i < buf.length; i++) {
                        if(i % 2 == 0)
                        {
                                buf[i] = (byte) 255;
                        }
                        else
                        {
                            buf[i] = (byte) 0;
                        }
                    }
All this with a load average of 0.04!
EOF

User avatar
gordon@drogon.net
Posts: 2023
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website Twitter

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 8:47 pm

aquarat wrote:I just found a programme I wrote 4 years ago that used the audio output as an Software Defined Radio (emulated DCF77 time signals)... gonna quickly hack it to do PWM.
You might want to look at:

https://projects.drogon.net/raspberry-p ... m-library/

it's probably not suitable for speed control of an AC motor though.

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 9:12 pm

Hi Gordon

I found your wiringPi library when I first started looking for PWM-related stuff. I was/am specifically after hardware PWM (which is available on GPIO18?) because I hoped that 1) it'd provide higher sampling rates 2) it'd be less prone to multi-tasking related timing error and 3) it'd use less cpu time. So far I can't find anything that demonstrates the use of GPIO18's hardware PWM functions, especially in a BASH format. The fact that the audio output can act as a pseudo-PWM output, especially at 44.1kHz will certainly suffice for my requirements. The triacs I've bought only require 0.5V to trigger them and Vmax from the audio output on the Pi is roughly 0.9V while outputting a 5:1 PWM output (5 on, 1 off).

Thanks for the effort though, your library is very cool and I found a diagram you made (that showed the wiringPi, GPIO number and header pin numbers) to be very useful when I first started experimenting with GPIOs.
EOF

User avatar
gordon@drogon.net
Posts: 2023
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website Twitter

Re: Pool Pump and PWM/GPIO speed control

Tue Oct 02, 2012 9:20 pm

aquarat wrote:Hi Gordon

I found your wiringPi library when I first started looking for PWM-related stuff. I was/am specifically after hardware PWM (which is available on GPIO18?) because I hoped that 1) it'd provide higher sampling rates 2) it'd be less prone to multi-tasking related timing error and 3) it'd use less cpu time. So far I can't find anything that demonstrates the use of GPIO18's hardware PWM functions, especially in a BASH format. The fact that the audio output can act as a pseudo-PWM output, especially at 44.1kHz will certainly suffice for my requirements. The triacs I've bought only require 0.5V to trigger them and Vmax from the audio output on the Pi is roughly 0.9V while outputting a 5:1 PWM output (5 on, 1 off).

Thanks for the effort though, your library is very cool and I found a diagram you made (that showed the wiringPi, GPIO number and header pin numbers) to be very useful when I first started experimenting with GPIOs.
If you want command-line stuff (ie. from bash or csh, etc.), then install wiringPi:

git clone git://git.drogon.net/wiringPi
cd wiringPi
./build

then:

gpio mode 1 pwm
gpio pwm 1 500
gpio -h

you can change the range and mode and frequency using the gpio command. (which is part of wiringPi) Default range is 1024. Default mode is 'balanced'. To get traditional mark:space ratio, then

gpio pwm-ms

change the range:

gpio range 512

change the clock divider:

gpio pwmc 16 #default is 32

If you want to use the other pin numbers, then:

gpio -g mode 18 pwm
gpio -g pwm 1 200
etc.

I'd not personally connect a triac directly to a Pi - but I would do it via an opto isolator. And remember you're switching something that's only running at 50Hz - you probably need to use a zero-crossing detector.

-Gordon
--
Gordons projects: https://projects.drogon.net/

janek
Posts: 8
Joined: Sun Aug 05, 2012 4:10 pm

Re: Pool Pump and PWM/GPIO speed control

Wed Oct 03, 2012 5:45 pm

I agree with Gordon, use optotriac (with zero crossing circuit build in, I'm using MOC3063 because of low power needed to drive internal LED) before "real" triac, this way You will save Your Raspberry Pi from damaging.

You've also mentioned 3kHz switching frequency. I don't know if that will be possible with 50/60Hz mains frequency.

What optotriac is doing is switching only in "0" state of AC, where voltage and current wave is crossing 0. This will prevent making noise and spikes on pump motor. That's why it can go really hot and inefficient without zero swithing circuit and switching mains voltage faster than 50/60 times a second.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: Pool Pump and PWM/GPIO speed control

Mon Oct 08, 2012 8:58 am

Thanks for all the advice. I haven't had a chance to work on this, hopefully I'll have time today.

I found this document : Ceiling Fan Speed Control - Single-Phase Motor Speed Control Using MC9RS08KA
Image

The document uses a microcontroller with a lower sampling frequency than what I had in mind, but the most important part of it, for me, is the circuit design. It implements what Gordon advised; an optical Triac which switches a secondary Triac. Of interest too is that the author didn't disconnect the capacitor on the motor's secondary winding.

janek wrote :
What optotriac is doing is switching only in "0" state of AC, where voltage and current wave is crossing 0.
The above circuit design (on the side of the ucontroller, which isn't illustrated in the pic but is present in the pdf) has a rectifier+transformer which allows the controller to synchronise to the AC supply for the purposes of switching at the zero-crossing. I could do the same with a GPIO or an audio-in interface. I suspect the GPIO option would be easier.

Gordon wrote :
you probably need to use a zero-crossing detector.
Thanks for the advice :) , I didn't understand any of this until I started researching it a few days ago haha (and I'm not being sarcastic, I've never had a need to switch AC loads quickly).
EOF

ciudadverde
Posts: 20
Joined: Mon Sep 03, 2012 11:46 am

Re: Pool Pump and PWM/GPIO speed control

Sat Oct 13, 2012 3:36 pm

Is the pump sincronous or asincronuos¿. If it is sincronuos all you said will not make possible because the speed is relative of the frecuency of the main power (50hz). If it's asincronuos will be posible

Maco1717
Posts: 28
Joined: Mon Jun 17, 2013 3:12 pm

Re: Pool Pump and PWM/GPIO speed control

Wed Sep 25, 2013 10:01 am

Hi, how to sync PWM with the mains Zero-crossing?

im using a triac and a opto-triac driver but i still have my doubts about how to make PWM go in sych with the mains line to be able to start the pwm and create as precise as posible power control...

thanks.

drgeoff
Posts: 11243
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pool Pump and PWM/GPIO speed control

Wed Sep 25, 2013 10:02 pm

It is extremely important to use an opto-triac and not an ordinary triac. There really needs to be good isolation between the AC mains and the RPi. Not for the safety of the RPi which is relatively expendable but for the safety of humans or animals who could touch the RPi or anything else plugged in to it. (And around the pump side, remember that electricity and water are a dangerous combination, so the highest safety standards must be observed.)
Quis custodiet ipsos custodes?

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

Re: Pool Pump and PWM/GPIO speed control

Wed Sep 25, 2013 10:26 pm

Some opto-triacs have zero-crossing detectors built-in.
e.g. http://uk.farnell.com/panasonic-ew/aqh1 ... dp/1867577

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Pool Pump and PWM/GPIO speed control

Thu Sep 26, 2013 1:38 am

my suggestion is to replace the single phase motor with a three phase asynchronous motor and purchase a motor drive that is powered from single phase. then you can control the speed of the motor and you save on the energy bill.

a single phase motor is quite inefficient. and I don't believe that you can come up with a way to control the speed of that motor without some very uncommon contraptions, and you will probably burn up your motor in the process..

Maco1717
Posts: 28
Joined: Mon Jun 17, 2013 3:12 pm

Re: Pool Pump and PWM/GPIO speed control

Thu Sep 26, 2013 7:30 am

im actually using. or was going to use...

standar triac and one of this

with in combination be exactly what you were pointing there. Im going to do some testing with some spare motors i have around this is not for a water pump but for a fan but in essence it a motor... going to test speed control and reverse (which i think it might be more complicated on a single phase one if not impossible...) also in id like to implement a current sensing and voltage to calculate the power factor but that in the coming future.

my question was and still is how do i sych the pwm pulse coming from the pi to the zero crossing point were the triac will change direction, the only thing i ca think of is and external circuitry that feeds this info to the pi resistor and maybe opto-isolation coming from the mains directly to a pin... :O

Thanks for all your replies.

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Pool Pump and PWM/GPIO speed control

Sun Sep 29, 2013 3:31 am

Good luck to you, and I hope you will keep us up to date on the progress. Single phase motors come in may different forms, and I am for sure no expert on this subject. I only speak my opinion based on what I know. And I have only briefly been involved in using speed control on single phase motors. Some appear to be more easy to control by means of voltage control than others. there are some fan motors that are designed so that you can control the speed by controlling the voltage but then you really need to know if the voltage you apply has to be a sine wave, or if it really is possible to use phase control with triacs or SCRs.
For an application where speed control is necessary I always would turn to three phase motors because they use less power and it is easy to control the speed and direction, compare to single phase motors that use a capacitor. you can get really low cost motor controller that connect to the single phase mains voltage and deliver three phase to the motor. you need to buy the controller and the motor at the same time, at least make sure that they match.

In the US where I live now, I am amazed at how rare it is to find three phase anywhere. so motors are usually single phase and running really hot and wasting energy for no reason. but we also have 120Vac instead of 230Vac, so what can you expect.

ductMonkey
Posts: 1
Joined: Sat Sep 21, 2013 2:01 am

Re: Pool Pump and PWM/GPIO speed control

Mon Sep 30, 2013 12:45 am

A ceiling fan is not a PSC motor with a start winding. A pool pump is something completely different from a ceiling fan or other "Shaded Pole" type motor. I am afraid you will damage your pool pump by attempting to monkey with either its on/off rate or frequency speed. If you will listen to the motor when it starts up you will notice that when it first comes on it hums and has a scrubbing like sound, then there is a slight click and the scrubbing sound goes away. That is a start assist and it kicks in when the amp draw is at its highest. If you turn the power on and off really fast, or mess with the incoming voltage you will damage the motor by leaving the starter engaged.

I did notice earlier that someone mentioned the three phase motor and a frequency drive. This would work quite well as it is a specialized setup typically found in water loop systems where the load in the loop changes as valves open or close in the system, for either cold/hot water plumbing fixtures etc...

I don't know what the advantage to having the pump run at a variable speed would be, but what you could do is put an Ohms meter on the electrical line and check the amperage while adjusting the various settings like, nozzle opening size, air mixture etc..., and determine what the lowest amperage is and how many hours per day it needs to run to keep the water clean.

And again you could have a pool pump motor that I am not familiar with and my advice would all be bunk. But it would be worth checking into before you burn out a motor. Good luck with the project!

Return to “Advanced users”