CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help in programming between pic16f877 and motion controller

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Elorie



Joined: 31 Jan 2005
Posts: 3
Location: Singapore

View user's profile Send private message

Help in programming between pic16f877 and motion controller
PostPosted: Mon Jan 31, 2005 7:23 am     Reply with quote

I am just a student starting out on c programming,currently work on a robot which uses pic16f877 as well as motion controller mcdc2805. But ran aground as the motion controller does not respond to the commands in the programe below. Can anyone help me pinpoint my mistakes and the programme is supposed to send ascII command to the motion controller.

#include <16F877.H>
#use delay (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#define mc1_enable PIN_C0 /* Take mc1 enable as right motor controller */
#define mc2_enable PIN_D1 /* Take mc2 enable as left motor controller */
#define outerleftsensor PIN_D4
#define innerleftsensor PIN_C5
#define innerrightsensor PIN_D3
#define outerrightsensor PIN_D2
#define LED1 PIN_A0
#define LED2 PIN_A1
#define _FASTIO


void main()
{

output_bit(mc1_enable,1);
puts("en")
puts("sp6000");
puts("ac5000");
output_bit(mc2_enable,1);
puts("en")
puts("sp6000");
puts("ac5000");


while (1)
{


if ((INPUT(outerleftsensor)==1)&&(INPUT(innerleftsensor)==0)&&(INPUT(innerrightsensor)==0)&&(INPUT(outerrightsensor)==0))

{
output_bit(mc1_enable,1);
puts("v6000");
output_bit(mc2_enable,1);
puts("v5500");
}

else if ((INPUT(outerleftsensor)==0)&&(INPUT(innerleftsensor)==1)&&(INPUT(innerrightsensor)==0)&&(INPUT(outerrightsensor)==0))

{
output_bit(mc1_enable,1);
puts("v6000");
output_bit(mc2_enable,1);
puts("v5800");
}

else if ((INPUT(outerleftsensor)==1)&&(INPUT(innerleftsensor)==1)&&(INPUT(innerrightsensor)==0)&&(INPUT(outerrightsensor)==0))

{
output_bit(mc1_enable,1);
puts("v6000");
output_bit(mc2_enable,1);
puts("v4500");
}

else if ((INPUT(outerleftsensor)==0)&&(INPUT(innerleftsensor)==0)&&(INPUT(innerrightsensor)==0)&&(INPUT(outerrightsensor)==1))

{
output_bit(mc1_enable,1);
puts("v5500");
output_bit(mc2_enable,1);
puts("v6000");
}

else if ((INPUT(outerleftsensor)==0)&&(INPUT(innerleftsensor)==0)&&(INPUT(innerrightsensor)==1)&&(INPUT(outerrightsensor)==0))

{
output_bit(mc1_enable,1);
puts("v5800");
output_bit(mc2_enable,1);
puts("v6000");
}

else if ((INPUT(outerleftsensor)==0)&&(INPUT(innerleftsensor)==0)&&(INPUT(innerrightsensor)==1)&&(INPUT(outerrightsensor)==1))

{
output_bit(mc1_enable,1);
puts("v4500");
output_bit(mc2_enable,1);
puts("v6000");
}

else

{
output_bit(mc1_enable,1);
puts("v5000");
output_bit(mc2_enable,1);
puts("v5000");
}

}
}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 31, 2005 9:01 am     Reply with quote

Some quick observations:

0) What compiler version are you using?
1) Didn't see a #fuse statement near the top of your code. You should probably have at least
Code:
#fuse NOWDT, HS, NOLVP, NODEBUG

2) Add the "ERRORS" directive to your #use rs232 statement
3) Your if() tests are probably creating a lot more code than necessary. Instead of
Code:
if ((INPUT(outerleftsensor)==1)&&(INPUT(innerleftsensor)==0)&&(INPUT(innerrightsensor)==0)&&(INPUT(outerrightsensor)==0))

try
Code:
if ( INPUT(outerleftsensor) && !INPUT(innerleftsensor) && !INPUT(innerrightsensor) && !INPUT(outerrightsensor))

Depending on your compiler version, you will get conversion from type int1 to type int8 and then the comparison. The second version should keep the comparisons as type int1.
4) Look at the #use fast_io() statement and set_tris commands to preconfigure the direction on your I/O lines. I don't recognize the #define _FASIO you included as something the CCS compiler or preprocessor would use but I could be wrong.
5) You may need a bit more set-up code prior to your while(1) loop to be sure that the PIC16F877 is properly configured (timers, ADC, etc are in non-active modes or otherwise not interferring with the desired operation on shared I/O pins).

And now some questions for you:

If you use a terminal program on your PC (Hyperterminal or similar) do you see the data coming and going through the serial port?

Is your cable between the PIC and your motion controller wired correctly?

Does it need to be a NULL cable or a straight through serial cable?

Do you need a TTL to RS232 level converter (MAX232, etc)?

If you have one, is it working correctly?

If you don't need one, do you need the INVERT directive in your #use rs232 command?[/code]
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Elorie



Joined: 31 Jan 2005
Posts: 3
Location: Singapore

View user's profile Send private message

Help again
PostPosted: Tue Feb 01, 2005 2:57 am     Reply with quote

I am currently using a program called motion manager to control the speed and it was a success if I remember my firend was using an rs232 crossover cable.

The cable between the pic and motion controller are connected properly as i constuct a program to send an ascII char to the motion contoller. After comparing both the waveforms from the oscilloscope,both of them are the sam.

Yes i have used the ttl the chip that you mentioned above the max232 and it is working.

Currently I am using mplab with the ccs complier version 3.212
Elorie



Joined: 31 Jan 2005
Posts: 3
Location: Singapore

View user's profile Send private message

Help again
PostPosted: Tue Feb 01, 2005 2:57 am     Reply with quote

I am currently using a program called motion manager to control the speed and it was a success if I remember my firend was using an rs232 crossover cable to control the motion controller.

The cable between the pic and motion controller are connected properly as i constuct a program to send an ascII char to the motion contoller. After comparing both the waveforms from the oscilloscope,both of them are the sam.

Yes i have used the ttl the chip that you mentioned above the max232 and it is working.

Currently I am using mplab with the ccs complier version 3.212
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group