Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F877A - Dual H-bridge Motor Controller

Status
Not open for further replies.

NotSly

New Member
Hello everyone, I am rather new to programming and wanting to get general help.

The aim of my project is to make a Dual H - Bridge motor controller CODE with a L293Chip. Which is going to be used to control a "Aqua Drone" on the water. There will be 2 motors, which spin together, or individually depending which direction is chosen to go ( left motor spins = turns right , right motor spins = turns left , both motors spin = straight). For now only those 3 functions are needed to work ( im aware that you can also make them spin in different directions).

Electronically, i have connected everything for the L293, even made my own 433Mhz Wireless controllers to activate the motors (using the activation pins). The circuit works with the mechanic/electronic activation , however i am wanting to include a PIC16F877A chip to do the logic of activating the L293 chip and its motors for personal development.

Basic action i am wanting the PIC16877a to do (mplab 8.70), is to first recognize the wireless receivers inputs to the PIC (from the transmitter on the remote control, https://www.globalsources.com/gsol/I/RF-module/p/sm/1108582354.htm#1108582354 ). Once those inputs are activated on the PIC , using IF statements (and other? ) in the code - 2 out puts can be activated 1 at a time ( or 2 at a time in order to get both motors spinning.) So this will need 2 bits of code, assuming both the inputs can be held high at the same time to get both outputs going (ultimately powering on both motors at the same time). Those 2 PIC outputs would be connected to the L293 activation pins (any of the 2 from - pin 2 , 7, 15 or 10 ), so for example R01 is pressed the output will be R05 ( i dont know that the output pins could be ) so the left motor spins, when R02 is pressed the R04 goes high and the right motor spins, when both R01 and R02 are pressed then R04 and R05 are both active giving signal for both motors to spin.

ATTACHED FILE - The diagram presents a concept of how it could work , but ive decided not to use the PWM method as there is no need, so just left right and both at the same time method is fine ( as long as it spins ! haha ) . The digram presents simple function of how PWM is desired to work but i think that would be too much for me at this stage !

So yes, i want either 1 output or 2 outputs at the same time going in order to get the motors spinning to steer the Aqua Drone (boat) into desired direction.

I am no longer at Uni, graduating on the 16th. Unfortunately my course wasnt offering many programming papers and i just didnt have enough time to learn C++. Just wanting to complete this little Aquad Drone. Any help, such as related parts that could be used would be helpful. I know this is really easy to do, however i just dont know where to start! IF this is the wrong forum and you know any other forums which could help me better please let me know! Any help is highly appreciated.

Kind Regards
 

Attachments

  • Untitled.png
    Untitled.png
    507.8 KB · Views: 242
  • untitled2.png
    untitled2.png
    420.2 KB · Views: 212
If each motor is only going in one direction why do you need a H bridge? let alone 2? Why not just use a single mosfet on each motor?
 
Haha, well if you are wondering just why i didnt use a mosfet then its because i chose to use a single IC that can do the same job i guess ( it has enable pins as well and i dont have to use diodes for it and could use a single heatsink ) ? L293 is a single IC which is conviniet and saves space. I Could have also used any transistor at the cost of 10 cents probably. PROBLEM IS that i want to use some programming in order to control it , for the sake of learning programming. Any suggestions? Thanks.
 
Alot of mosfets have diodes in them, use the micro to twiddle the pin of the mosfet for speed, or maybe I am utterly missing something (probably)
 
I think i must have written the description wrong, all i want is help with coding . The aim of this thread was for me to get help with coding for such electronic setup , as i want to learn how to program micro and this is just a way for me to start. The circuit works already but i want to get the micro chip integrated into it just for the sake of it .. thanks
 
Alot of mosfets have diodes in them, use the micro to twiddle the pin of the mosfet for speed, or maybe I am utterly missing something (probably)
How do i "twidle" with the microprocrssor is the question lol. I know how to hook the micro processor up to the circuit , just wanting to learn how to code.
 
Ok have you ever written any code? if so what language? I hate to say it but if you havnt then drop the pic and get arduino (yuk) it will be quicker and easier.
But in the simplest form pin on/ pin off repeat as needed.
Do you have any code at all? if not do a google for the chip and pwm c code. otherwise its time to meet the datasheet :D
 
I have had experience with coding but the teacher didn't explain anything and just gave us the theory books -_- ... I know, what do they even get paid for haha. Adruino i would like to keep away from, ive heard its not ideal to code with (prefer something that could be useful in a job situation ). Yes, used to.. code that turned on 1 motor at the same speed but it was for a different 690 PIC . Is there any books or material that could get me a better learning experience do you think? as i really dont know where im looking at in the data sheet its got over 200 pages! Maybe some sort of code examples specifically for PICF877A that i could learn/follow from ??
 
I have an example of using the PWM on a PIC16F876 (Which is very similar to the PIC16F877) that is written in assembler. If you are interested I will put the source file on dropbox and post a public link.

Les.
 
NVMND
 
A quick google found This Page. All you need to change is to wire the enable to RB2 and then wire your second 293 to some other pins.

Edit, if you have the L293 instead of the L293D then you will need flyback diodes as they are not on the chip.

Mike.
 
Hello, thanks for reminding me Pommie . I think its the L293D (will check). So far i edited Saeeds code from his google blog. Could someone tell me if this could work for 2 input and 2 outputs ( as well as simultaneous input ). I am really a beginner so please tell me with /comments what to edit! thanks.
 

Attachments

  • Main.c
    1.3 KB · Views: 217
Pommie , thanks for that tutorial! It is actually what i really need (ideally), will get to that at later stage once i can get the simple one to run! Thanks :)
 
Here is the Successfully Compiled/Built code. What do you think?
 

Attachments

  • Two Input Noob Code.c
    1.5 KB · Views: 170
Here is the code that deals with the PWM. (I think this is all you need to look at but it is 7 years since I wrote the code.)

;*** PWM initialization
clrf tmr2 ;Clear TMR2 register
movlw b'11111111' ;Max duty (low speed)
movwf ccpr1l ;Set CCPR1L register
bsf status,rp0 ;Change to Bank1
movlw d'255' ;Period=1638.4usec(610Hz)
movwf pr2 ;Set PR2 register
bcf status,rp0 ;Change to Bank0
movlw b'00000110' ;Pst=1:1 TMR2=ON Pre=1:16
movwf t2con ;Set T2CON register
movlw b'00001100' ;CCP1XY=0 CCP1M=1100(PWM)
movwf ccp1con ;Set CCP1CON register
MOVLW 0xFF
MOVWF ccpr1l

;*** Compare mode initialization
clrf tmr1h ;Clear TMR1H register
clrf tmr1l ;Clear TMR1L register
movlw HIGH Timer_constant ;H'61A8'=25000 (50000 = H'C350' for 20 ms)
movwf ccpr2h ;Set CCPR2H register
movlw LOW Timer_constant ;25000*0.4usec = 10msec (50000 = H'C350' for 20 ms)
movwf ccpr2l ;Set CCPR2L register
movlw b'00000001' ;Pre=1:1 TMR1=Int TMR1=ON
movwf t1con ;Set T1CON register
movlw b'00001011' ;CCP2M=1011(Compare)
movwf ccp2con ;Set CCP2CON register

; ---------------------------

; This sets the PWM value. (PWM_Val is the value that controls the output on the PWM)
PID_end

MOVLW 0xFF
XORWF PWM_Val,W ;Invert value to write to CCPR1L
movwf ccpr1l ;Now Write CCPR1L

;NOTE high value to CCPR1L register gives lowest speed


This is the link to the file in my Dropbox folder.
**broken link removed**
The zip file contains the schematic, the main .asm file and PC.inc
You do not need to look at PC.inc as all it does is deal with serial input and output for setting up the PID constants. (Proportional gain, integral gain and derivative gain.)
This is the design for the X axis table feed on my milling machine that I made in 2008

Les.
 
Status
Not open for further replies.

Latest threads

Back
Top