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 support@ccsinfo.com

Synchronising 2 dsPICs (or multiple PICs)

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



Joined: 22 Apr 2018
Posts: 13

View user's profile Send private message

Synchronising 2 dsPICs (or multiple PICs)
PostPosted: Wed Oct 03, 2018 12:42 am     Reply with quote

Hello;

I have a test bench concerning 2 dc motors. I need to run these motors in sync since they need to lift some weight from 2 opposite ends. In order to move them in sync, I suspect that the PIC controllers should be in Sync. I run these motors with dsPIC30F4011 microcontrollers since I use encoder readings.

I need to sync these 2 motors so that they both start at time= 0 Seconds and finish at Time=3.73 seconds(i.e). I use 2 dsPIC30F4011 with both internal 16x PLL.
(clocked at 117920000mhz) And the 2 PICs have exactly the same program. (only some reference position targets are different).

How can I sync the programs in these 2 PICs so that they both start at the same time and finish at the same time?

Thanks.
_________________
Regards;
Caner.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 3:51 am     Reply with quote

You're using encoders, I assume they are giving rotational data on the motors.

Don't you only need to sync the encoder outputs?

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 4:17 am     Reply with quote

There is sync, and sync....

A difference of (say) 1mSec between two motor controllers wouldn't matter at all. However a difference of (say) 0.5 seconds, would.

So just change your code a fraction, and have one controller assume the role of 'master', and the other 'slave, and when idle between the tasks, have the master do something like pulse an I/O line. Have the slave look for this, and set it's internal counter to zero when it sees this. If all tasks are then synchronised to this counter, the two systems will be basically synchronised.
However comment applies. What are the PIC's using for their master clock?. If they are relying on the internal RC oscillator, there can be significant drift between these. Better to have an external crystal oscillator, and clock both PIC's from the same source. Then once the counters are synchronised, the units should remain in sync.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 4:51 am     Reply with quote

Ok, I'll be the 'bay guy' and say while you can 'sync' them it will NOT be easy.

given :2 DC motors. What type BLDC, servo,stepper, old school? Identical motors? IE from the same batch? Same stall current,run current??

unknown : motor controller / interface. Simple FET or module make a difference !
unknown : weights. are they identical? both exactly 2.134Kg NOT 2.133 and 2.135Kg.

unknown: control loop. open (just 'go for xx seconds') or closed (with feedback) preferably with encoder ?

Every aspect and part of the two 'lifts' MUST be identical or known, so that you can 'trim' the control for them to be in sync.

As an example, friend built his own wall mounted CNC, 4' by 8'. Users 2 steppers for lift (X axis),good to .0001 position BUT one motor may rest 'low' the other 'high' by the notch of the pole of the armature. Take a stepper and 'feel' the 'notch' when you lightly rotate the shaft without power. That very small amount of distance is enough to offset the motors when in use!

Provided you use encoders for positional feedback and run a calibration routine before each use, yes you can 'sync' the two PICs.
Jay
canero



Joined: 22 Apr 2018
Posts: 13

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 5:24 am     Reply with quote

Hello;

Thank you for your quick responses. My 2 dsPICs have PID loops in cascade, both controlling speed and position in closed loop. The motors are small dc motors with optical encoders.

Ttelmah, thanks a lot for your suggestion seems very workable, but, these motors should start and stop at the same time making a synchronous motion while running. The delay should be max 1-2ms.
How will I make sure that, this synchronous motion keeps running while pulsing an IO? I could not generate the logic in my mind. So should I pulse an IO from master and make the slave wait for it and when it arrives, move the slave to the next reference point and so on?
Also, What is the point of counters while doing synchronization? Can you please expand that part a little?

Caner.
_________________
Regards;
Caner.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 6:36 am     Reply with quote

You don't. You synchronise before you start.

Assuming you run the two chips off the same oscillator, all their timings will be the same. So all you do is start the main 'timing loop' of your PID system, in sync between the chips. You can even get sneaky/complex:

Have a single I/O output line on one chip. Held high after boot.

Have this connect to an interrupt input on _both_ PIC's.

Have the interrupt handler reset the timer(s) you use for the PID loop.

Then one chip drops this line.
Both chips interrupt at the same time.
Both timer(s) are then reset at exactly the same point.

It is even possible to do this with no master/slave, by having the line resistor pulled up. Then both chips when they reach a certain point use output_drive to pull the line low. It doesn't matter which one actually operates the line, since both chips respond the same to this.
canero



Joined: 22 Apr 2018
Posts: 13

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 8:46 am     Reply with quote

OK got your point Thelmah but this only solves the problem "starting the operation at the same time".
How do you continue to be in sync mode after that until the end of operation, that was what I was asking. There should be somekind of a clockline where both of the pics should follow after start, isnt it? (like a 10ms heartbeat or sort)

Or do we rely on having the same main clock crystals? (Thinking that their PID timers are all the same and no need to be clocked again while driving the motors).
Caner.
_________________
Regards;
Caner.
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 8:54 am     Reply with quote

You're worrying too much. Sync, move the object (run your motors), stop. Synchronize again just prior to moving again. Or synchronize every 10s. Or every 500ms. Doesn't really matter as your separate clocks, even if running from the PIC's internal RC oscillator, aren't going to drift much in the timeframes you're concerned about.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 9:09 am     Reply with quote

Quote:

OK got your point Thelmah but this only solves the problem "starting the operation at the same time".
How do you continue to be in sync mode after that until the end of operation, that was what I was asking. There should be somekind of a clockline where both of the pics should follow after start, isnt it? (like a 10ms heartbeat or sort)

Or do we rely on having the same main clock crystals? (Thinking that their PID timers are all the same and no need to be clocked again while driving the motors).
Caner.


If you clock the chips from one master oscillator, then they will remain in sync.

I must admit I assumed you had a timer 'tick' operating the PID. Typically you would have a tick that actually operates the cycle of the PID, so it remains at a constant rate. Hence if this is synchronised, and everything times from this, the whole system will remain inherently synchronised.
canero



Joined: 22 Apr 2018
Posts: 13

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 2:25 pm     Reply with quote

Hello again.

I successfully made the synch with IO as Thelmah suggested. Thanks a lot. The difference is noticable in a slow motion cam.
Now I am trying to make 3 PIC synchronization since I will need it for other projects. I believe a daisy chain kind of connection would work with syncing multiple pics.

Caner.
_________________
Regards;
Caner.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 4:27 pm     Reply with quote

Actually 'daisy chaining' will be slower than a 'broadcast'.

Daisy chaining, to me, means a signa l(or token) gets passed from a master PIC to slave,which then passes it to another slave,which then passes it 'down the line'.... So, depending on the speed of transmission and how long the PIC takes to receive and retransmit the 'token', will affect the overall system. Say you had 5 PICs in the chain and a 10us 'process' time. PIC #5 will be 40us 'behind' the master.

Broadcsting, to me, means that ALL PICs receive the 'token' at the same time. Various ways to achieve this. I2C specs a 'special' adrs(00 ?) that all devices have so that all can be updated at the same time. In this method the only difference is the 'propagation delay' based upon length of wiring. Probably not a problem within the same house, but use 15 miles of cable and it add up !

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Oct 03, 2018 11:05 pm     Reply with quote

The 'wire or' pull down only sync, will work with multiple chips.
Generate the pulse with something like:

Code:

    output_low(SYNC_PIN);
    delay_us(10);
    output_float(SYNC_PIN);

So long as interrupts are enabled on all chips well in advance of this point, all the chips will interrupt on the falling edge.
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