PDA

View Full Version : Serious Serial Situation Setbacks...



Dansdog
- 6th February 2007, 01:50
Sorry I thought it would be a catchy title.... maybe not.... :(

But really now, I want to say thanks in advance for any/everyone whom may assist me in my dilema.

My project is really kind of simple. All I'm looking to do is control a robot (two small dc motors) to drive it like a tank/bulldozer. Using relays I can reverse the motor direction and have made it operate with pushbutton switches. I have two 16F84A's, PBP, and an Epic Programmer. I can compile/program the chips to test I/O and everything worked fine until I tried to establish serial comms. Eventually I intend to make the comms wireless but for now I have them hardwired together. I'm pretty confident in the hardware aspect of the project. My code compiles/programs fine but when I power up the majic never happens. I get erratic behavior on the recieving end (like a high speed chattering on the relays) and there is sometimes a response to changing the inputs but nothing close to being considered operational.

I have tried every baud rate in the PBP manual and have also added/removed qualifiers but I've had no change in operation.

My limited experience has led to a temporary roadblock which hopefully one of you can help me pass. I fear my error is something spelled out clearly in a reference I haven't came across yet. I have done a lot of looking around but cannot figure out what I'm doing wrong. Hopefully my post isn't to trivial due to my short commings.

Again thanks for any assistance!!!

Dan



Here is my code for the tx:

Include "modedefs.bas" ' Include serial modes
INPUT PORTB.2 ' Right Forward output
INPUT PORTB.3 ' Right Reverse output
INPUT PORTB.4 ' Left Forward output
INPUT PORTB.5 ' Left Reverse output
OUTPUT PORTA.0 ' Serial Output Pin
A0 VAR BYTE
DEFINE OSC 4


loop:


' -----(READ ALL THE INPUTS)----- '

IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 0) THEN ' "STOPPED"
SEROUT PORTA.0 , T2400 ,[1]
ELSE
endif
IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) THEN ' "RR ONLY"
SEROUT PORTA.0 , T2400 ,[2]
ELSE
endif
IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 0) THEN ' "RF ONLY"
SEROUT PORTA.0 , T2400 ,[3]
ELSE
endif
IF (PORTB.2 = 0) AND (PORTB.3 = 1) AND (PORTB.4 = 0) AND (PORTB.5 = 0) THEN ' "LR ONLY"
SEROUT PORTA.0 , T2400 ,[4]
ELSE
endif
IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 0) THEN ' "LF ONLY"
SEROUT PORTA.0 , T2400 ,[5]
ELSE
endif
IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 0) THEN ' "RF AND LF"
SEROUT PORTA.0 , T2400 ,[6]
ELSE
endif
IF (PORTB.2 = 0) AND (PORTB.3 = 1) AND (PORTB.4 = 1) AND (PORTB.5 = 0) THEN ' "RF AND LR"
SEROUT PORTA.0 , T2400 ,[7]
ELSE
endif
IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) THEN ' "RR AND LF"
SEROUT PORTA.0 , T2400 ,[8]
ELSE
endif
IF (PORTB.2 = 0) AND (PORTB.3 = 1) AND (PORTB.4 = 0) AND (PORTB.5 = 1) THEN ' "RR AND LR"
SEROUT PORTA.0 , T2400 ,[9]
ELSE
endif

GOTO LOOP;

END
__________________________________________________ ______

Here is my code for the rx:

Include "modedefs.bas" ' Include serial modes
OUTput PORTB.0 ' Right Forward output
OUTput PORTB.1 ' Right Reverse output
OUTput PORTB.2 ' Left Forward output
OUTput PORTB.3 ' Left Reverse output
input PORTA.0
A0 VAR BYTE
DEFINE OSC 4

LOOP:

SERIN PORTA.0 , T2400 ,A0

if A0 = 1 then STOPPED ' "STOPPED"
if A0 = 2 then RR_ONLY ' "RR ONLY"
if A0 = 3 then RF_ONLY ' "RF ONLY"
if A0 = 4 then LR_ONLY ' "LR ONLY"
if A0 = 5 then LF_ONLY ' "LF ONLY"
if A0 = 6 then RF_AND_LF ' "RF AND LF"
if A0 = 7 then RF_AND_LR ' "RF AND LR"
if A0 = 8 then RR_AND_LF ' "RR AND LF"
if A0 = 9 then RR_AND_LR ' "RR AND LR"
goto loop;

'-------Read the Serial Data and decode into motion control --------'


STOPPED: ' "STOPPED"

PORTB.0 = 0 'Right Forward output
PORTB.1 = 0 'Right Reverse output
PORTB.2 = 0 'Left Forward output
PORTB.3 = 0 'Left Reverse output

GOTO LOOP;

RR_ONLY: ' "RR ONLY"

PORTB.0 = 0 'Right Forward output
PORTB.1 = 1 'Right Reverse output
PORTB.2 = 0 'Left Forward output
PORTB.3 = 0 'Left Reverse output

GOTO LOOP;

RF_ONLY: ' "RF ONLY"

PORTB.0 = 1 'Right Forward output
PORTB.1 = 0 'Right Reverse output
PORTB.2 = 0 'Left Forward output
PORTB.3 = 0 'Left Reverse output

GOTO LOOP;

LR_ONLY: ' "LR ONLY"

PORTB.0 = 0 'Right Forward output
PORTB.1 = 0 'Right Reverse output
PORTB.2 = 0 'Left Forward output
PORTB.3 = 1 'Left Reverse output

GOTO LOOP;

LF_ONLY: ' "LF ONLY"

PORTB.0 = 0 'Right Forward output
PORTB.1 = 0 'Right Reverse output
PORTB.2 = 1 'Left Forward output
PORTB.3 = 0 'Left Reverse output

GOTO LOOP;

RF_AND_LF: ' "RF AND LF"

PORTB.0 = 1 'Right Forward output
PORTB.1 = 0 'Right Reverse output
PORTB.2 = 1 'Left Forward output
PORTB.3 = 0 'Left Reverse output

GOTO LOOP;

RF_AND_LR: ' "RF AND LR"

PORTB.0 = 1 'Right Forward output
PORTB.1 = 0 'Right Reverse output
PORTB.2 = 0 'Left Forward output
PORTB.3 = 1 'Left Reverse output

GOTO LOOP;

RR_AND_LF: ' "RR AND LF"

PORTB.0 = 0 'Right Forward output
PORTB.1 = 1 'Right Reverse output
PORTB.2 = 1 'Left Forward output
PORTB.3 = 0 'Left Reverse output

GOTO LOOP;

RR_AND_LR: ' "RR AND LR"

PORTB.0 = 0 'Right Forward output
PORTB.1 = 1 'Right Reverse output
PORTB.2 = 0 'Left Forward output
PORTB.3 = 1 'Left Reverse output

GOTO LOOP;


END

HenrikOlsson
- 6th February 2007, 06:31
Hi,
Haven't looked much at your code yet, just the standard question first:
Do you use a proper X-tal on both the sending and receiving PIC's, not a ceramic resonator, and, if yes, are you sure it's 4Mhz?

/Henrik Olsson.

Archangel
- 6th February 2007, 07:21
G'Day Dan,
Ask the dog if he set the config fuses properly, or maybe you can set them in code for him :) Which compiler are you using, MPASM or the default PBP compiler?
Look at this thread: http://www.picbasic.co.uk/forum/showthread.php?t=543&highlight=config+fuses

Dansdog
- 7th February 2007, 03:05
I am using ceramic resonators. But I do have x-tal's and will switch them out. Out of curiosity why does it matter? I chose the ceramic's because they consume less space.

Fuses... That's something I've never heard or read about before (in PIC language).

I'm using MicroCode Studio 2,2,1,1 and PBP version 2.46.

When I select to "Compile and Program" the "meProg" initiates and I can select to view the configuration window. Do I have to do anything other than select the correct oscillator?

skimask
- 7th February 2007, 03:33
I am using ceramic resonators. But I do have x-tal's and will switch them out. Out of curiosity why does it matter? I chose the ceramic's because they consume less space.

Fuses... That's something I've never heard or read about before (in PIC language).

I'm using MicroCode Studio 2,2,1,1 and PBP version 2.46.

When I select to "Compile and Program" the "meProg" initiates and I can select to view the configuration window. Do I have to do anything other than select the correct oscillator?

Xtal vs resonator - xtal=tight tolerances, resonator=not quite so tight; required if you're using any kind of communications

fuses - see the PBP manual, page 8.

Dansdog
- 7th February 2007, 03:46
Thanks skimask!!!

Page 8 might become next favorite page....I'll let you know tomarrow.

Dan