HELP - PIC16F84A Based Serial Port Servo Controller

Electronics Computer Programming Q&A
Post Reply
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

HELP - PIC16F84A Based Serial Port Servo Controller

Post by makubo »

Hello to all, i have asking many electronic community site yet i still cant solve my problem. Since this board about servo so i will try my luck here.

Here the situation:

I have build PIC servo controller by following all instruction at this site:

Code: Select all

http://www.digitalnemesis.com/info/projects/picservo/
all programing, hex file and PCB is include in this site.

The problem is when i testing the circuit my PIC didnt have any respond...i have problem at the last part of testing where my PIC should send back message to terminal program. I have check all components and everything is ok. All setting at computer is correct. No other hard/software at serial port. Other things weird is when i run simulation using ISIS (Proteus ) it work.

For testing circuit(look at last part where PIC should send message to terminal):

Code: Select all

http://www.digitalnemesis.com/info/projects/picservo/article.aspx

Any ideas or suggestion are welcome. Thank in advance.
User avatar
jaem
Posts: 148
Joined: Thu Feb 15, 2007 3:36 pm
Location: BC, Canada
Contact:

Post by jaem »

Can you tell us a bit more? What terminal program/settings are you using? You say that you're not receiving any response to your terminal, but is it connecting and accepting commands *from* the terminal? Are the servos operational? And, no offense, but if it's not working, then despite your checking, there must be *something* wrong with your software or hardware - it's often hard to see your own mistakes (I've done that many times), so if you tell us how you have it set up, that would help us more than telling us that it looks right. I'm not good enough with PICmicro Assembly to be of too much help, but if I get some free time (yeah right :P), I'll try to see what I can do.

Oh, and for the record, this board isn't specifically about Servos. I'm actually subscribed to the other magazine (Nuts & Volts), but I as far as I know, the "Servo" in its name is just a reference to their use in robotics. That said, questions like this *are* what this board is for, so don't worry about it.
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

Post by makubo »

Thank for replying.

Terminal program that i use is the one that come with windows xp (Hyperterminal). My setting is 2400 baudrate, 8 data bits, parity none, stop bit 1, hardware flow control.

When connect the power, the PIC will send a message to the computer, which should come up in the terminal window. It should send "PIC Servo Controller" then "Reset". But I dont get any message at my terminal.

GetPWROnMsg
ADDWF PCL, f
DT "PIC Servo Controller\r\n", 0
GetResetMsg
ADDWF PCL, f
DT "Reset\r\n", 0
SETEC_Astronomy
Posts: 582
Joined: Tue May 09, 2006 12:44 am
Contact:

Post by SETEC_Astronomy »

jaem had an important question you didn't answer. Does the circuit work except for the fact your computer isn't receiving commands/data from the PIC? Do the servos operate correctly? Are you using the proper baud rate? Did the project you built specify hardware control or is it Xon/Xoff or no control? I don't see many PIC projects that use hardware flow control. Is your cable setup for transmit and receive? Is anything setup to "echo" commands? How many wires are connected to your serial port? On both ends? Did you remember to connect the ground wires? etc......
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

Post by makubo »

Servo operate correctly. Yes im using proper baudrate(oscillator 4MHz) Yes this project using hardware control. Yes my cable setup for transmit and receive. No setup to "echo" commands. Yes all ground is ground together.

4 wires are connected to serial port on both ends.
my circuit schematic:
http://www.digitalnemesis.com/info/proj ... ematic.pdf



Figure 1 (pdf) shows the complete schematic for the servo controller, there is not much to it as all the hard work is done in the PIC software.

Power for the circuit is derived from a 9V dc plug pack and regulated down to 5V by the 7805. The centre connector of the plug is positive but diode D1 provides reverse polarity protection just in case. C9 bypasses the supply and helps stabilise the regulator while C6, the 47uF capacitor, helps filter the power from the plug pack.

The interface to the host computer's serial port begins at P1, a female DB9 connector. Pins 1, 4 and 6 (CD, DTR and DSR) are connected together to ensure the host computer will accept serial data from the PIC at any time. The signal ground (Pin 5) is connected to the circuit ground and the remaining signals are sent to the MAX232.

The MAX232 is a single power rail RS232 interface circuit. It takes care of converting the RS232 signal voltages to CMOS logic levels that the PIC can use. It has two receivers that convert RS232 levels to CMOS levels and two transmitters that convert CMOS to RS232 levels. It uses an on chip dc-dc converter and the five 10uF capacitors C1, C2, C3, C4 and C5 to generate +10 volts and –10 volts. C3 is also used to smooth the 5 volt power rail.

The RX line (data going to the host computer) from the serial port is connected to the first transmitter's output, which is driven by the 'SerialOut' signal from the PIC's RA0 pin. The TX line (data coming from the host) is connected to the second receiver, which then drives the 'SerialIn' signal connected to RA3 on the PIC. Similarly the incoming RTS signal is routed via the first receiver to RA1 and the CTS signal is sent from RA2 to the second transmitter and on to the host's serial port.

All of Port B on the PIC is dedicated to driving the servos and digital outputs. RB0 to RB3 drive the digital outputs 0 to 3 respectively, RB4 to RB7 drive servo outputs 0 to 3. You may note that the connectors for the digital outputs and the servos are wired identically; this is so you can add more servos by simply changing the PIC code. It would also be possible to convert some of the pins to inputs that can report status of other sensors to the host computer.

The 4 MHz crystal Y1 and the two 22pF ceramic capacitors are connected to the PIC to form its clock oscillator. The clock signal is divided by four internally to derive the PIC's instruction clock resulting in a 1ns execution time for each instruction. This is important for the timing of both the serial communications and the servo control pulses.

D2, an LED is connected to RA4 on the PIC and to the power rail via R1 a 1K current limiting resistor. The PIC software lights the LED whenever a data byte is received from the host. It is lit when RA4 is driven low. The 100K resistor R2 apparently shorting it out is very important! RA4 is an 'Open Drain' output meaning that is can only pull the pin low and cannot make the pin positive, it relies on external components to do this. This is important when modifying the value of individual bits on the Port as the PIC will first read the state of all the pins, do the modification on the one it is interested in and write back state for all the pins.

If R2 weren't there the value of the pin would be 'floating' when the pin is supposed to be high (LED off) so when the PIC reads the value of the pin it could read low which when written back would turn on the LED. A long and fruitless night was spent trying to debug the PIC code only to read about this in the PIC datasheet hours later.

The remaining connections to the PIC are C10, a supply bypass capacitor and tying the MCLR (reset) pin of the PIC high, so it actually runs.
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Re: HELP - PIC16F84A Based Serial Port Servo Controller

Post by Sambuchi »

Looking over some of the posts.. the issue is still in the setup... since you are not getting your PIC to communicate to the Hypertem.. I could write something for you to verify the PIC is working, but lets look at your setup.


where is this document that you are looking at.. can we see it?
makubo wrote:The problem is when i testing the circuit my PIC didnt have any respond...i have problem at the last part of testing where my PIC should send back message to terminal program.
Power LED on for servo board?

Does your computer see the COM port in the hardware setup?

Did you scope the crystal?

Check the cable...
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

Post by makubo »

Testing

You will need a 9V dc power supply with a 2.5mm power plug, centre positive and a serial cable to connect the controller to your computer. You will also need a serial communications (sometimes called a 'Terminal') program. I used 'HyperTerminal' as it comes with Windows.

First, without the serial cable or ICs plugged in, power up the board and measure the voltage across pins 5 and 14 on the PIC and across pins 15 and 16 on the MAX232. They should both be around 5 volts.

Remove the power and insert the MAX232, pin 1 faces the DB9 connector. Connect the power again and test the voltage between ground (pin 15) and pin 2 of the MAX232. You should read close to 10 volts. Now check between ground (pin 15) and pin 6 and you should get –10 volts. If not, check you inserted all the 10uF capacitors the correct way. If all is well, we know the dc-dc converter is working in the MAX232 so we can move on to testing the serial port.

Without the PIC installed, put a jumper wire between pins 3 and 5 of the PIC socket, the LED should light. If not, check you installed it the correct way around. Remove the jumper.

Now put a jumper between pins 1 and 5 and between pins 2 and 17 of the PIC socket. This loops the serial data back to the host and sets the CTS signal active (low) so the host is allowed to send data. Plug in the serial cable to the computer and the DB9 connector and apply power to the controller board again.

Run your terminal program and open the serial port that you connected to the controller. Set the serial port speed to 2400 baud, eight data bits, and one stop bit, no parity and 'Hardware' flow control.

You should now be able to type into the terminal program and see the characters appear as you type. Try moving the link from pins 1 to 5 and placing it from 1 to 14 and type a few characters. You shouldn't get any characters displayed as the serial port is buffering them because the CTS line is inactive. If you move the link back to pins 1 to 5 again what you typed should appear. This means that your serial port, the MAX232 and the hardware flow control are working properly.

If moving the link from pins 1 to 5 doesn't seem to stop you seeing the characters you type, you probably haven't set the port to use hardware flow control. Sometimes it is labelled CTS/RTS flow control.

Remove the power, unplug the serial cable from the controller and remove the links in the PIC socket then insert the PIC. Again pin 1 faces the DB9 connector.

Connect a servo to the servo 0 output, remembering that the white wire on the servo lead is the control signal and goes closest to the PIC. Connect the serial cable and open your serial port in your terminal program again.

When you connect the power, the PIC will send a message to the computer, which should come up in the terminal window. It should send "PIC Servo Controller" then "Reset". You may also notice the servo twitches a little when you first connect the power. You should be able to turn the servo with your fingers and it won't resist or return to a point. This means it is not getting any position signals.

Lets send it some commands while we're here. Type a '0' (zero), this is actually the command to enable the output of servo 0, so the servo should move with a satisfying whirr! It should also resist your attempts to move it, but don't use too much force.

Now type an 'at' sign (@) and the servo should be deactivated so you can move it again. You should notice the LED light and will remain on for about a quarter of a second after the each character. You won't get anything displayed in the terminal program however as the PIC is not echoing back the characters. It is in fact trying to read them as commands.

Power LED on for servo board? --->The PIC software lights the LED whenever a data byte is received from the host. But i already can just light the led with simple code.

Does your computer see the COM port in the hardware setup? --->yes, com1

Did you scope the crystal?--->not yet, i will do it tomorrow at lab. And let you know the result.
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

OK... Thats a good check list! :D

Well, Looks like during the setup they made you do a hardware loop back with the serial port. Seeing how that was an earlier step I am assuming that went well.
Now put a jumper between pins 1 and 5 and between pins 2 and 17 of the PIC socket. This loops the serial data back to the host and sets the CTS signal active (low) so the host is allowed to send data. Plug in the serial cable to the computer and the DB9 connector and apply power to the controller board again.
After verifying that it works... we want to do the following

link from pins 1 to 5
;because the CTS line needs to be active.
;Or make sure the line is low for communication

and

unlink from pins 2 to 17
;because we want the PIC to talk

was that done?

What type of programmer are you using to program the PIC?
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

Post by makubo »

Did you mean this step?
You should now be able to type into the terminal program and see the characters appear as you type. Try moving the link from pins 1 to 5 and placing it from 1 to 14 and type a few characters. You shouldn't get any characters displayed as the serial port is buffering them because the CTS line is inactive. If you move the link back to pins 1 to 5 again what you typed should appear. This means that your serial port, the MAX232 and the hardware flow control are working properly.
Yes i have done it. And everything working.

For program PIC i use PICStart Plus from microchips.


Is something wrong with my serial communication or PIC code?
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

Yes thats the step..

:x Grrrrrrrrr... :x

I hate that I cant help out more but I believe that this can only be a...

bad .hex file
or
bad PIC
or
bad crystal.

The hardware looks correct: right programmer for chip, right jumpers, power, etc.
Maybe check the RST line to the PIC make sure its high.

Keep us posted in what you find.

Tony
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

Post by makubo »

Thank Sambuchi for your great help.

I also hope only among this three cause this problem but

bad .hex file---> i have compile many .asm to .hex, using more than one programmer yet still doesnt work
or
bad PIC---> I have 7 new PIC from microchip so must not bad PIC
or
bad crystal---> actually i have done this circuit at PCB, breadboard and veraboard with different crystal and yet i still cant move the servo.


for your information i also have tested another two servo controller from:
http://home.planet.nl/~j_havinga/servo/servo.htm
and
http://www.rentron.com/SerialServo.htm

and none of them work.

Maybe my bad luck in using PIC16F84. If this still doesnt work i will just buy servo controller.
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

Wow... If I were you, I would simply do it myself!

You seem to have a great grasp on the tools... just write your own program that can control a servo.. its not that hard.

I made this link a long time ago when I first got my servos rolling
http://www.sambuchi.net/Projects/Roboti ... ontrol.htm

It may be how you are programing the chip too. I remember one time I had an ATMEL and it was the first time using the part. The hardware was fine, hex was fine crystal was fine but the ATMEL didnt work!?!?! Turned out that in the programming tool that I was using needed to set the XTAL frequency and fuse bits to get it to work.... not only that, but if I didnt do it the first time that I programmed the chip.. the chip would lock itself and I would not be able to reprogram it again! yeeks! what a pain.

Good luck and if you deiced to make your own there are lots of people here that can help you.
makubo
Posts: 7
Joined: Wed Mar 12, 2008 12:07 am
Contact:

Post by makubo »

My problem is i need to send report by next week. So i dont have much time for make new servo controller. If i have more time i will wor with PIC that have internal UART like PIC16F877 or PIC16F628

What actually i want to do is to develop one system that can detect and lock onto moving object. This servo controller will be interface with MATLAB image processing in real time control. I only need two servo for pan and tilt. I have done with image processing program and the last part is then integrate it with servo controller. I still didnt do hardware part for pan/tilt. My time wasted much for troubleshoot this servo controller. Sighhh... :sad:
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

You wouldnt have to make a different servo controller... just rewrite some code and you should be able to get something to work...

I think you have the capabilities if i remember correctly to run 8 servos. If I wanted to make a quick project what I would do is turn 4 of the "what would be servos" into 4 buttons.

2 buttons would would step up/down one servo.

and then do it again for the other servo.

You would be left w/ 2 open pins

Go up to radio skack pick up some buttons. and thats all the hardware you need.

Start banging out some code.. button debouncing, PWM and thats a good start on servos! Just an idea.
_________________
Tony

You can look at my projects here www.sambuchi.net
SETEC_Astronomy
Posts: 582
Joined: Tue May 09, 2006 12:44 am
Contact:

Post by SETEC_Astronomy »

edit: nevermind.
Post Reply

Who is online

Users browsing this forum: No registered users and 54 guests