PICAXE microcontroller with TA8050P H-Bridge
PICAXE microcontroller with TA8050P H-Bridge

by Lewis Loflin

  
  

Alternative schematic for PICAXE and TA8050P speed control works the same way - observe polarity on transistor!

Here we are going beyond PICAXE Controls TA8050P H-Bridge Motor with PORT Programming to not only stopping and changing direction of motor rotation, but to also control rotation in either direction. I'll cover only the speed control part here.

In the schematic above I've inserted an OPTO-coupler transistor circuit into the Vcc or GRD side of the in this case TA8050P h-bridge motor control. Reading the value of a 10K potentiometer on pin C.1 through the internal analog-digital converter I return a 10-bit value used the set the duty cycle on the PWM out on B.3. For more on PWM see Pulse-Width Modulation Tutorial.

Also see PIC12F683 Programming Circuits Tutorial

For example with a LED connected to B.3 when the potentiometer is adjusted the brightness of the LED varies based on position. The programming for this is very simple:


#picaxe 18m2 ; type chip used

;setfreq m4 ; All M2 parts internal k31, 
; k250, k500, m1, m2, m4, m8,m16,m32

symbol control = C.1
symbol val = w0 ; word (16-bit) user variable
symbol pwmPin = B.3 ; use only B.3 or B.6

init: ; setup PWM
pwmout pwmdiv4, pwmPin, 124, 1023

loop:
; readadc returns 8 MSB if used
readadc10 control, val  ; get 10-bit value
; read 10-bit ADC into variable w0

pwmduty pwmPin, val  ; set pwm duty
goto loop  ; loop back to start

That's the whole program which takes about 47 bytes. Here is the code integrating the earlier direction control only with speed control though the TIP120 Darlington.


Truth Table:
B.0 - 1; B.1 - 0 forward;
B.0 - 0; B.1 - 1 reverse;
B.0 - 0; B.1 - 0 stop.

Main program starts below:


; setfreq m4  ; All M2 parts internal k31, 
; k250, k500, m1, m2, m4, m8,m16,m32
; Use terminal at 9600 at 8 mHz
; if using 4 mHz set terminal 4800

; all HIGH when open
symbol SW0 = pinB.5
symbol SW1 = pinB.6 
symbol SW2 = pinB.7

symbol control = C.1
symbol val = w0 ; word (16-bit) user variable
symbol pwmPin = B.3 

init:
pwmout pwmdiv16, B.3, 124, 1023

let dirsB = %00001111 ; PB0-PB3 output

let pinsB = pinsB & 0xF0 ; all pins off

pullup on        ;enable pullups 
pullup %11110000 ; pullup only on PB5-PB7

loop:
if SW1 = 0 then goto REV1 ;endif
if SW2 = 0 then goto FOR1 ;endif
if SW0 = 0 then goto STOP1

readadc10 control, val  
; read 10-bit ADC into variable w0

pwmduty pwmPin, val  ; set pwm duty
pause 10 ; wait 10mS
goto loop

REV1: ; reverse
let pinsB = pinsB & 0xF0 ; motor off
pause 500
let pinsB = pinsB | %00000001 
; motor on B.0 HIGH, B.1 LOW
goto main

FOR1: ; forward
let pinsB = pinsB & 0xF0 ; motor off
pause 500
let pinsB = pinsB | %00000010 
; motor on B.1 HIGH, B.0 LOW
goto main

STOP1: ; stop
let pinsB = pinsB & 0xF0 
; motor off B.0 and B.1 LOW
pause 500
goto main
; end program

Related: Introduction PIC12F683 Programming Circuits Tutorial


Loading



Also related to this: Understanding Microcontroller IO Ports

See How I got into Electronics

 


donate