Active Cooling soft PWM follow-on fan motor speed controller driver
#1
(for schematic diagram and in-line wiring harness, see this link)

edit:  I changed the default soft-pwm to GPIO23, pin(16).

   

The PWM (pulse width modulation) is 'soft' because it does not use a hardware oscillator. The Python codes turn the transistor on and off ( 16ms on,  4ms off) about 50 pps. The base-emitter pulls only about 2ma from the GPIO pin, while the collector current takes the main motor drive current (about 140ma for this fan).

The following two pics are my 'double' controller one half driving the PI 3B, and the other half driving the PineA64. In each case the Python code is the same; posted below:

   

   

In the pic above I also have my ada fruit gps (746) breakout mounted on the ttyS4 uart4 on the PineA64 euler bus.

fan_motor.sh
Code:
#!/usr/bin/python
#
# fan_motor.sh
#*****************************************************************
#  author:     Mark H. Harris      
# license:     GPLv3
#
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
#   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
#   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#   MECHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENCIAL DAMAGES (INCLUDING, BUT
#   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERUPTION)
#   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE
#   EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#*****************************************************************
## Import the necessary header modules
from time import sleep
import signal as SIGNAL
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

## SOFTWARE PWM GPIO23 pin(16)
soft_pwm = 23
GPIO.setup(soft_pwm, GPIO.OUT)

ms_on = .016
ms_off = .004
hup_flag = False

## FUNCTION DEFINITIONS

def motor_duty_on(m_pin, t_delay):
    GPIO.output(m_pin, True)
    sleep(t_delay)
    
def motor_duty_off(m_pin, t_delay):
    GPIO.output(m_pin, False)
    sleep(t_delay)

def end():
    GPIO.cleanup()
    quit()

def ssighup(signum, frame):
    global hup_flag
    global ms_on
    global ms_off
    if (hup_flag):
        ms_on = .016
        hup_flag=False
    else:
        ms_on = .250
        hup_flag=True
    print(" ")
    print("HUP: duty_cycle toggled value: "+str(ms_on))

SIGNAL.signal(SIGNAL.SIGHUP, ssighup)

kb_interrupt = False

while(not kb_interrupt):
    try:
        motor_duty_on(soft_pwm, ms_on)
        motor_duty_off(soft_pwm, ms_off)
    except KeyboardInterrupt:
        kb_interrupt = True
        print(" ")
        print("motor controller ended by interrupt, bye!")

end()


marcus

edit:  I changed the default soft-pwm to GPIO23, pin(16).
  Reply
#2
   

In this pic I have the LED lab pinouts coming off the back-side of the Sparkfun cobbler, which frees up room on the half breadboard for the PN2222 motor speed controller transistor. 

Both sides of the Sparkfun breakout are labeled;  the advantage to this board is that the engineers have placed all of the GPIO pins in sequence by BCM GP number. My lab is using GPIO 20-27  which are in sequence on the Sparkfun breakout which facilitates using ribbon cables for system wiring (as in my robot design).  Also, the breakout board eliminates the unused (and useless) extra ground pins (eight of them) !

Notice the 40 wire ribbon runs under the PineA64 board which is supported on steel feet; this gets both bus sets on one side of the board.  My robotics enclosure (not pictured) has a slot on the same side which facilitates access for the breakout board. 

marcus
  Reply
#3
cheers mate ! will make this happen
You can find me on IRC, Discord and Twitter


  Reply
#4
edit:  I changed the default soft-pwm to GPIO23, pin(16).
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Controlling a Servo Motor casmiguefl 3 6,797 07-13-2017, 11:14 PM
Last Post: MarkHaysHarris777
  Active Cooling 5v brushless fan with Motor Speed Controller soft PWM MarkHaysHarris777 14 24,787 06-26-2017, 03:16 PM
Last Post: ishwest
  High-speed GPIOs dsnyder 3 5,569 05-05-2016, 09:07 PM
Last Post: martinayotte

Forum Jump:


Users browsing this thread: 1 Guest(s)