PDA

View Full Version : Problem with 16F88 controlling h-bridges



silentwol
- 4th March 2007, 15:29
Hi,

I'm using PBP to create a pen plotter. I have made 6 h-bridges to control 3 stepper motors all of which seem to be functioning correctly. I had 4 of the h-bridges plotting when driven by a PICAXE (using an 18X - which is a pre-programed 16F88). I have since switched over to PBP and added an extra two bridges for pen up and down control.

I developed the PIC software using a breadboard and a set of LED's, making sure that the LEDs blink in the right order... this is now finished and working well, receiving data from the computer serial port and flashing accordingly.

However, when I come to plug the PIC into the circuit with the h-bridges, nothing happens. I've checked for shorts over and over again and can't seem to come up with anything... The only differences between the breadboard and veroboard with the h-bridges is that I have 100uF decoupling capacitor and a 4.7K pullup on RA5 on the veroboard. I can't think that these are the problem, and I added a cap and resistor to the breadboard and things seemed to be OK. However, I do remember that the first time I added the decoupling cap to the breadboard, the PIC behaved badly for a few seconds beforing settling down.

Any ideas what the problem could be? I've tried preprograming a routine of pulses so that the PIC isn't depending on the serial input. That still didn't work. It's as if the PIC simply isn't starting up.

Final question is with pin RA5. I wanted to use it as an input for the serial comms, but I couldn't get it working. I've set MCLR off, but it doesn't want to play ball. Any ideas what I could be doing wrong?

Thanks for your help... I'll go back to checking for shorts for the hundredth time :)

sougata
- 4th March 2007, 15:45
Hi,

Disable MCLR and LVP (Low Voltage Programming) from the config. Burn the PIC and re-read it to make sure that the config fuses are being set okay. I remember someone mentioning that it was the programmer that was not setting the config fuses properly. As far as the BreadBoard to the VeroBoard transition: Try a little led blinky program to test that your PIC is properly reset and booting. A schematic post alongwith code would be nice.

silentwol
- 5th March 2007, 15:49
Thanks for your reply :)

I've read the chip again and can confirm that the config fuses are set correctly. I'm using a homemade RCD programmer if that info helps. Linked below is the full version of the program (including the little test sequence at the start) This works perfectly on the breadboard but doesn't work on the veroboard.

http://clowt.com/printer.bas

I don't have any schematics (apart from some scribblings on a piece of paper that I have long thrown away!). It's a fairly simple circuit using TIP122's and 125's (NPN and PNP)... It was based off a project I found on the internet a while ago. I might draw one up later, but I'd rather avoid all that work if it can be avoided!

What do you mean by 'properly reset and booting'? I have the feeling the problem is that it isn't booting properly. What are the causes for a chip failing to boot? As far as my limited knowledge of PICs go, all you need is 5V across VCC and GND and a fairly stable power supply. Checking the veroboard with a voltmeter shows that the pins are getting 5 volts, which makes me think that maybe something is causing noise.

My only idea at the moment is removing the decoupling cap and 4.7 pull up resistor (making it exactly the same as the breadboard) and testing that. If that fails, I will try isolating the power to the chip (disconnecting VCC and GND) and powering it with a seperate source like a battery, which I know to be good. If that still doesn't work, then it means that something connected to one of the other pins is causing the PIC to not boot... which leaves me pretty flummoxed!

Does this seem like a good plan, or is there a more glaringly obvious problem that the trained mind can see? :D

sougata
- 5th March 2007, 17:32
Hi,

You mentioned that you tested the PIC on the breadboard using LEDs. Now you have hooked up Totem Pole output stages (I presume). So my questions are :

1. If you connect LEDs only and not the Transistor Driver What Happens ?

2. Are you powering the motors from the same supply as the PIC ?

3. Do the motors require higher than 5 volts ?

4. if the above is yes, then how have you translated the level.

Get some schematic (scans from the dustbin).

Your code seems okay. At least compiles okay. Although you have not set the TRISA bits as inputs it should be automatically handled by SERIN.

silentwol
- 5th March 2007, 19:28
(I've never heard of Totem Pole output stages, and a quick google makes me think I don't have anything like that in my circuitry)

1. With just LED's it works properly. Interestingly, I conected it up to the transistor driver (without the motor connected) and it worked as it should, making one wire to the motor high. However, upon conecting the motor it fails. I then disconected the motor and left the PIC conected to the transistor driver and the PIC started overheating. Conecting the PIC up to LEDs again made it work.

Furthermore, I did at one stage have it working with one motor. I left the other two motors disconected, hooked it up to the PC serial port and was able to control the motor. Afterwards I removed the decoupling cap (I'm pretty sure it was after, but I can't be sure... I should start writing this stuff down since my memory is appalling!) and everything seemed to go downhill to the current condition.

Also, if I use a wire connected to +ve and touch each socket (without the PIC installed, thus simulating the pins going high) I can make the motors step.

2. Yes, they are powered with the same supply. It's a fairly cheap and nasty supply (£15) - switching mode with selectable voltages. I've have it set to 4.5V, as it's either 4.5 or 6.

3. Motors are rated at 12V, but step perfectly well at 3V. Currently the output from the h-bridges are 4V after losses. I was planning on setting the power supply to 12V and then using a 5V regulator to power the PIC to give more torque, once I had got it working at 4.5V.

I will draw up some schematics tomorrow :) I will draw them up from the veroboard, checking each connection as it go to make sure you get exactly what I have on the board.

Last peice of info which may help: I remember that when I was running it with the PICAXE (driving just 2 stepper motors) it was somewhat flakey. It would ocassionally reset each time I sent serial data, if I remember correctly, and would have spells of simply refusing to work (for no apparent reason). The next day it would be fine though.

I'm now going to try powering the PIC with a battery and powering the rest of the circuit with the power supply.

Thanks again for your help :)


EDIT:
Did some digging - here is the schematic I used:
http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt-circuit.html
(Except I used TIP122's and TIP125's - the same but can't handle as much current).

However, I used no opto-isolators on the NPN's, but I did use some 2N3904's on the PNP's (instead of the isolators) as desribed here:
http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt-impl.html
(half way down the page, the author describes it as the 'the high side problem')

I could probably fix the problem by using opto-isolators (since I can flash LED's!) but I would like to find out why it isn't working at the moment :)

sougata
- 6th March 2007, 05:34
Hi,

If you are not overloading your PIC it should not heat up. Unless you are logically doing a short circuit. With the 1k resistors going to the base drive the PIC should be driving around 5ma and each port pin can drive something around 25ma.

I still need some info how you have hooked your half-bridge to the PIC. Taking your schematic into mind, if you cannot draw one please mention by text. Explain your half bridge as left part / right part and then the connection of the PIC to the NPN/PNP. I would draw up the schematic for you and then analyse.

You can also play with the TRIS bits to simulate a Z output (Tristate High Impedance style). Thus you get 3 states 1,0,Z.

Even if everything is electrically okay, motors can sometimes draw (they normally do) huge starting currents. This may trigger the brownout reset inside your PIC. One option is isolating the PIC supply from the motor. Or you may use (2+2) 4 general purpose diodes (say 1N4007) to power your PIC and Motor separately and having your PS at 6 volts. The two diodes approximately drops 1.2 volts so your PIC runs at around 4.8 volts. That means 2 diodes in series powers the PIC and the other two powers the driver. So your decoupling cap for the PIC is used for PIC only. (The drivers need them because if your driver is at 6 volts and your PIC outputs a 4.8 volt at logic 1 it is still going to fire your PNP transistor)

If you plan to use higher voltage for the motors then do use optos as they become your level translator.

This is not as complicated as it might look but I need to have the schematic exactly to understand possible cause.
(Temporary Variables in my mind are limited due to a faulty design by GOD):D

silentwol
- 6th March 2007, 17:57
It's working! :D

It turns out there were two problems. The first was a mistake with the circuitry - the 1K resistors for one of the half-bridges was bypassed when connected to the PIC. This meant that one pin was having to source too much current and destabalising the PIC. I imagine this is why the PICAXE was rather flakey.

The second was with the following code:


TRISA = %01100001
TRISB = 0

PORTA = 0
PORTB = 0


By setting the TRIS registers, all the pins defined as outputs are made high. I believe that in the few nanoseconds(!) between the registers being set and the ports being set to 0, the strain of setting everything high (and thus the motors sucking up all that current as you described) was causing the voltage to drop and the brownout detection to reset the PIC. It turns out that PICAXE's have brownout disabled, which is why the PICAXE worked but this PBP code wasn't working. Disabling brownout detection fixed everything :)

Thank you so much :) If it wasn't for your help (especially your mention of the brownout reset!) I don't think I would have ever got to a solution!

sougata
- 7th March 2007, 04:16
Hi Silentwol,

Congratulations that your project worked. This forum helps us all by providing pointers. So thanks to this forum and all the pros who helped me learn a lot. Keep it up.