Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Two pics 16f877a connection and code for steppee motors

Status
Not open for further replies.

Solar000

Member level 2
Member level 2
Joined
Feb 6, 2013
Messages
49
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Greece
Visit site
Activity points
1,649
Two pics 16f877a connection and code for stepper motors

Hello, i am controlling stepper motors with pic 16f877a but i want to connect a second same pic to
be able to use more ports and control more motors.

1.To connect a pic with another i only need Rx and Tx of both connected together ? Do i need a crystal for the second pic?
The first pic has a max232

2.How can i set different values to a port of the second pic with micro c?

For example now i have a function like this


Code:
void Move(){
TrisB = 0x00;
PortB = 0x00; 


PORTB=0b00000110;
Delay_ms(50);
PORTB=0b00000101;

}

I want to do this


Code:
void Move(){
TrisB = 0x00;
PortB = 0x00; 


PORTB=0b00000110;   // portB from second pic
Delay_ms(50);
PORTB=0b00000101;  // portB from second pic

}

or another port of second pic

Code:
PORTC=0b00000110;   // portC from second pic
Delay_ms(50);
PORTC=0b00000101;  // portC from second pic

PORTD=0b00000110;   // portD from second pic
Delay_ms(50);
PORTD=0b00000101;  // portD from second pic


and choose the port i like of the second pic to move
 
Last edited by a moderator:

Sometimes, it's not a good idea to add microcontrollers like this, because now you've just moved the problem to how to co-ordinate comms between/to multiple processors.
Of course, a distributed approach is sometimes better, but possibly not in this case.

You only need 4 outputs max to drive a conventional bipolar stepper motor, so why not find a microcontroller with 4 additional pins.

If you are using the other pins for different purposes, you could try to optimize elsewhere to remove the requirement for so many pins.
I/O expanders are a possibility if you're using many pins for switches, LEDs, etc.

By the way, a dedicated stepper motor control IC is way better, but often those ICs require quite a few inputs too (but an I/O expander
would solve that).

If you really want to use two microcontrollers, then technically I suppose you could connect the two Rx pins together, and have each
microcontroller listen for it's own instructions simultaneously. Obviously, you can't connect the two Tx pins together (think about why).
 

You only need 4 outputs max to drive a conventional bipolar stepper motor, so why not find a microcontroller with 4 additional pins.


If you really want to use two microcontrollers, then technically I suppose you could connect the two Rx pins together, and have each
microcontroller listen for it's own instructions simultaneously. Obviously, you can't connect the two Tx pins together (think about why).


Thanks for the reply.
I don't need only 4 more pins.I want to control 5-6 more motors.So it's 20-24 more pins.

For connection,i connect the Rx pin (26) of the first pic with the Rx of the second directly and nothing else ???
or through the max232 ???


Do i need a crystal also for the second pic??
 

I want to control 5-6 more motors.
In that case, a distributed approach will need to be used. Highly worth considering dedicated stepper motor controllers, unless you're implementing some novel motor control in your PIC.
The dedicated controllers have important features that you'll find hard to implement on the PIC.
Replace the single crystal with an oscillator, and you could possibly fan out to multiple microcontrollers, depending how far apart they are. Or you could use a crystal and investigate if you can
feed the oscillator output to another device, but you'd need to check the datasheet to check if the output supports the load.
You can tie Rx pins on the microcontroller together. It's not a great approach, but should work.
 


You said you wanted to connect the PICs together, and that you had MAX232, but you didn't say you wanted to communicate from one PIC to the other, or if you wanted to send
instructions from a PC to them.
If your requirement is the former, then you need to do a lot of thinking (and reading).
If you also need to retain PC comms as well as satisfying the former, you may conclude that you need to rethink the whole design.
 

Thanks for all the help and excuse me, i am studying and i don't know very well.

I want the pic i have to communicate with a second pic for example to set portB of the second a value and move the motor.
It's like the first pic tells the second to set portB= 0b00000110;

Something like that i want

Code:
void main(void)
{
PORTB=0b00000110; //first pic
Delay_ms(50);
PORTB=0b00000101; //first pic

Delay_ms(50);
PORTC_OF_SECOND_PIC=0b00000101; //second pic
Delay_ms(50);

So i just want to send values from the first to second
What is the connection schematic for this
This it's ok?
First pic Tx ---> second pic Rx one wire ???
 

RS232 UART is a point-to-point technology, not a bus. Do you need to retain the ability to have PC communication to the PICs? If so, then no, you can't connect the Tx to the Rx because effectively you're trying
to create a network of many devices using a point-to-point technology, which is not possible.
 

Ok so this can be done
1
Pic 1 Tx ----> Rx Pic 2
Pic 1 Rx ----> Tx Pic 2

and no max232, no pc communication

2
And this

______________________ max232 (1) ________________ max232 (2)
Pic 1 Tx ---> T1IN max232 ---> T1OUT ----> R1IN max232 --->R1OUT ---> Pic 2 Rx
no pc communication



but no this ???
3

______ _______ max232 (1)
Pic 1 Tx ---> T1IN max232 ---> T1OUT ----> PC communication
_ _ |
_ _ |
_ _ |
Pic 2 Rx

Two wires from Pic 1 Tx one goes to max232 and output to pc and the other to Rx of second pic.

If you need to connect two or 3 pics and PC communication so that pics communicate
and one of them can communicate with pc what can you do?
 

If you need to connect two or 3 pics and PC communication so that pics communicate
and one of them can communicate with pc what can you do?
Depends what you mean by communicate - bidirectional? Or just from PC to PIC and not PIC to PC?

Basically, you can't connect multiple Tx lines together.
 

From what i understand and correct me if i am wrong

Without any pc communication, just two pics communication i can do this :

Pic 1 Tx ----> Rx Pic 2
Pic 1 Rx ----> Tx Pic 2


With pc communication bidirectional and two pics it can NOT be done and only i can do this one way communication

pc--> Rx pic1 --> Tx pic1 ---> Rx pic2 (and optionaly) Tx pic2---> Pc

So with this i can send data from pc to pic1(Tx1 not connected with pc) and then from pic 1 send data to pic2 (with Tx1 to Rx2)
and if i want to send data to pc i can use the Tx pic2 to send to pc.

And like that i can only send data to pic1 from pc and not receive from pic1 to pc
and pic2 can only receive from pic1 and not tranceive to pic1 because pc tranceiving to pic1,but if i want
i can tranceive from pic2 to pc.

Am i correct ???
 

Without any pc communication, just two pics communication i can do this :

Pic 1 Tx ----> Rx Pic 2
Pic 1 Rx ----> Tx Pic 2
Correct, this is fine.
With pc communication bidirectional and two pics it can NOT be done and only i can do this one way communication

pc--> Rx pic1 --> Tx pic1 ---> Rx pic2 (and optionaly) Tx pic2---> Pc
Correct, this is possible.
So with this i can send data from pc to pic1(Tx1 not connected with pc) and then from pic 1 send data to pic2 (with Tx1 to Rx2)
and if i want to send data to pc i can use the Tx pic2 to send to pc.
Agree
And like that i can only send data to pic1 from pc and not receive from pic1 to pc
and pic2 can only receive from pic1 and not tranceive to pic1 because pc tranceiving to pic1,but if i want
i can tranceive from pic2 to pc.
Yes, this is correct. (assuming you're using the MAX232 for the first and last legs of this chain, i.e. the connections to the PC - but I think you know this).
It's an ugly thing to program, so you may prefer to have a single larger microcontroller and multiple stepper motor control ics.
 
It's an ugly thing to program, so you may prefer to have a single larger microcontroller and multiple stepper motor control ics.

Thank you very much
I have to use a microchip pic because it's for a university project and we work with pics currently.
But is there a pic with so many pins?For about 10 motors?

And one last question for today
The second pic needs a crystal to work or not? just the first pic?
 

The number keeps changing, it was two motors, then 5-6, now 10.
Rather than RS232 UART, SPI or I2C could be considered. Although if they are not on the same board, then you've
got to reconsider (I2C is not ideal for off-board long distance).
Anyway, I'm sure there are microcontrollers with 40 I/O pins, maybe not PICs.
Another option would be a CPLD.
Or if you use stepper motor ICs, then you may have additional options (e.g. to use an
I/O expander for some of the control pins per stepper motor IC, e.g. connect all the
direction pins, and enable pins, to pins on the I/O expander - that would reduce from 20 pins down
to (say) 2 for an I2C I/O expander).

As for crystal, as mentioned, it may work but depends on distance (i.e. must be on the same board).
I wouldn't use a single crystal for 10 PICs. You could distribute an oscillator clock but safer to use separate ones.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top