![]() |
![]() |
![]() |
|
|
|||||||
| Robotics Chat Specific to discussions about robots and the making of. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
As mentioned in my previous thread, I'm having real trouble with my photovore.I'm using a PIC16F54 connected to 2 h bridges made of BD139 and BD140s. When I tell the PIC to turn on both h bridges (ie, keep two pins high) it's all fine and dandy. When I load up code to take inputs from 2 LDR/resistor dividers and turn on the motors appropriately, nothing happens, although if I spin the motor shaft the motor will turn and run, but slowly. I've rewritten the code, changed pins, tried a BC337 pre amplifier and tried phototransistors as sensors all to no effect.
Boosting the h bridge voltage to 9v had some effect, but a Nicad 9v pack is far too large for my bot. The PIC is running at 5v, as is the LDR sensors. Trying PICKIT2 +5v and a regulated 5v supply from a PP3 made no difference. The hbridge is running at 3volts. I know it sounds childish, but I'm really beginning to regret ever starting this project. I've had lots of problems, but I've solved them. I've been working on this one for a day, and I've had no luck. It's the last thing in the way of this project, and it's getting to me. |
|
|
|
|
|
|
(permalink) |
|
Can you post the code? Put [code] before it and [/code] after it so it keeps it's format.
Mike. |
|
|
|
|
|
|
(permalink) |
|
Code:
;***** ;Alex E-S ;27/4/2008 ;Version 2 (original did not work at all) ;Revision 3 (reassigned ports to simplify full h-bridge implementation later) ;for PIC 16F54 ;Clock 2.4576MHz ;Function: control file for lightseeking robot. list P = 16F54 include "c:\PIC\P16F5X.inc" __config _XT_OSC&_WDT_OFF&_CP_OFF ;========== ;Declarations: rmotfor equ 00h rmotrev equ 01h lmotfor equ 00h lmotrev equ 01h rightldr equ 02h leftldr equ 03h porta equ 05h portb equ 06h org 1FFh goto Start org 0 ;========== ; Subroutines: Init clrf porta ;Resets porta clrf portb ;Resets portb movlw b'1100' ;Sets porta tris porta ;as outputs movlw b'00000000' ;sets portb tris portb ;as i/o retlw 0 ;resets working reg to 0 ;==========when dark sensors go low, when light sensors go high ;Program Start Start call Init Main bcf porta,rmotfor ;turns both bcf porta,lmotfor ;motors off btfsc portb,rightldr ;tests light on right LDR goto rightlight ;if light,goto rightlight btfsc portb,leftldr ;tests light on left LDR goto leftlight ;if light,goto left light goto Main rightlight btfsc portb,leftldr ;tests if light on left LDR too goto bothlight ;if there is,goto bothlight bsf porta,lmotfor ;if not turns on left motor to turn towards light goto Main leftlight btfsc portb,rightldr ;tests if light on left LDR too goto bothlight ;if there is,goto bothlight bsf porta,rmotfor ;if not turns on right motor to turn towards light goto Main ;nolight ;behaviour if no light (rotate set amount?(90 degrees?) ;goto Main ; bsf porta,rightmotor initially no action,call from Main when developed. bothlight ;behaviour if both light bsf porta,rmotfor ;turns on bsf porta,lmotfor ;both motors (later for set time?) goto Main END |
|
|
|
|
|
|
(permalink) |
|
For a start remove the pic entirely, and test the H-bridge - manually connect the inputs to 5V or 0V with a 1K resistor and see how the motor moves then.
|
|
|
|
|
|
|
(permalink) |
|
Done that-full operation, works off pickit supply too.
|
|
|
|
|
|
|
(permalink) |
|
You seem to have both the left and right motor forward signals on PortA,0 and the two reverse signals on PortA,1. How is your H-Bridge connected to your pic?
Mike. |
|
|
|
|
|
|
(permalink) |
|
Ah, that's a relic from troubleshooting, the left motor is connected to porta 0 and 1. Changing that makes no difference, it was merely something I was trying. H-bridge is connected directly to the PIC (was that what you were asking?)
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Just put your program on the Oshonsoft sim, had to use 16F84 for sim. You are setting PORTB as output, yet you are testing for LDR's on the PORTB inputs. I have had to move the 'org' 's as the program crashes with a stack fault.! Hope this helps.
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
Thanks. Where did you move the orgs to? I'll try it tomorrow probably, I've had enough for today.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Hi, org 0x0;1FFh goto Start org 0x04 The declarations are causing problems in the right/left. For test do this, use numbers in place of all these labels bsf porta,0; rmotfor ;turns on bsf porta,1; lmotfor ;both motors (later for set time?) And it all works OK...
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
So because I've defined two things as "01" and "00" it's having problems? Or shouldn't I be using equ for this stuff (I have no problems using numbers, it just helped me write and think about the code)
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
I didnt dig too deep why, but the problem was that A.0 was the output selected for both rmotfor and lmotfor. The correct subr was entered but it was always the A.0 bit that was set..? Likewise when it was the both subr it was still only A.0. When I changed these two labels to their numeric value, the prog worked OK. Does this help.? Dont forget to TRISB as 0xff, Inputs
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
Hmmm... I think I only changed that as a troubleshooting attempt, and then changed part of the program back. I'll try it, and change those orgs. I also need to reread my pic book it seems....
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Post the latest program and I will re-run it in the Oshonsoft Sim. As I have said, my Sim dosn't have a 16F54 in its options, but the 16F84 option seems to work OK.
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
Right, here we go. Still the same, LEDs connected to the outputs work perfectly, exactly how I programmed then. When I made a mistake in reworking the code, so one hbridge was on all the time, the motor behaved perfectly. It almost as if either a; The microcontroller is not giving full voltage when acting as a decision maker, or b; The code is acting as a very crude PWM, which is dropping the voltage supplied to the h-bridge, which I find unlikely. Anyway, here's the latest version of the code;
Code:
;***** ;Alex E-S ;27/4/2008 ;Version 2 (original did not work at all) ;Revision 4 (rework) ;for PIC 16F54 ;Clock 2.4576MHz ;Function: control file for lightseeking robot. list P = 16F54 include "c:\PIC\P16F5X.inc" __config _XT_OSC&_WDT_OFF&_CP_OFF ;========== ;Declarations: porta equ 05h portb equ 06h org 0x0;1FFh goto Start org 0x04 ;========== ; Subroutines: Init clrf porta ;Resets porta clrf portb ;Resets portb movlw b'1100' ;Sets porta tris porta ;as i/o movlw b'00000000' ;sets portb tris portb ;as outputs retlw 0 ;resets working reg to 0 ;==========when dark sensors go low, when light sensors go high ;Program Start Start call Init Main bcf porta,0 ;turns both bcf porta,1 bcf portb,0 ;motors off bcf portb,1 btfsc porta,2 ;tests light on right LDR goto rightlight ;if light,goto rightlight btfsc porta,3 ;tests light on left LDR goto leftlight ;if light,goto left light goto Main rightlight btfsc porta,3 ;tests if light on left LDR too goto bothlight ;if there is,goto bothlight bsf portb,0 ;if not turns on left motor to turn towards light goto Main leftlight btfsc porta,2 ;tests if light on right LDR too goto bothlight ;if there is,goto bothlight bsf porta,0 ;if not turns on right motor to turn towards light goto Main ;nolight ;behaviour if no light (rotate set amount?(90 degrees?) ;goto Main ; bsf porta,rightmotor initially no action,call from Main when developed. bothlight ;behaviour if both light bsf porta,0 ;turns on bsf portb,0 ;both motors (for set time?) goto Main END |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Magic: The Mini-magic Switchboard should I make it a kit? | blueroomelectronics | Electronic Projects Design/Ideas/Reviews | 213 | 29th August 2008 10:43 PM |
| Drive 33 Servos With One PIC + USART | wschroeder | Micro Controllers | 40 | 14th July 2008 02:22 PM |
| End my elevator nightmares | fearlesss | Electronic Projects Design/Ideas/Reviews | 20 | 29th March 2008 02:39 AM |
| need help... | imisendo_4036 | Micro Controllers | 0 | 20th February 2008 01:14 AM |
| Changing the hex code | anthony123 | Electronic Projects Design/Ideas/Reviews | 22 | 16th February 2008 04:11 AM |