4 years, 8 months ago.

How can I synchronize 3 LPC1768 ?

Hello everyone,

I would like to synchronize 3 ARMs LPC1768. I tried with an external interrupt linked to the 3 ARMs but I have IF statement in my interrupt and the 3 ARMs don't make it at the same speed... Also, maybe it is the ADC of each ARM who does not make it at the same speed...

Here is my interrupt code

include the mbed library with this snippet

void ISR2()   //this is the response to interrupt, i.e. the ISR
{
    __disable_irq();
    
   device.baud(19200);
     wake_up=0;  
   if (A==1) {
               
       ADCDATA=ain.read_u16();              
       ADCDATA= ADCDATA >> 11;
       ADCDATA= ADCDATA <<3;
       device.putc(ADCDATA);
         // }
       }
 
   if (A==0) {
        cnt=0;
        digital=Input.read();       // Digital input
        device.putc(digital);       // Send digital value
       }
   
    __enable_irq();
}

I hope someone could help me :)

2 Answers

4 years, 8 months ago.

Hi Antoine. Only a few comments:

a) IRQ routines should be tightly written and quick to perform the required task. Enter and exit the routine quickly.

b) noting this, do you really require the device.baud(19200) inside the IRQ routine ? Serial ports only need to be primed one time during first power up and then left alone. Unless you are switching baud rates (UART communication speed) through out the code execution ?

c) try to re-code the IRQ routine to remove the device,putc calls - they will consume far too much time to belong inside such routines. Keep thinking - quick work and exit

Perhaps consider to set a global flag with a global variable that when enabled, you can sample the same global flag and then print / send as required.

Hi Sanjiv,

Thank you for your answer. I have already changed my code for this one : ( infact, I removed the baud() function )

IRQ

void ISR2()   //this is the response to interrupt, i.e. the ISR
{
    __disable_irq();
    
   
       wake_up=0;  
          
       ADCDATA=ain.read_u16();              
       ADCDATA = ADCDATA >> 12;
       ADCDATA= ADCDATA <<4; 
       device.putc(ADCDATA);
 
    __enable_irq();
}

I know the time spend with function like "putc" is critical but that is the only way I found to synchronize my 3 ARMs... So in your example, you mean that the send is in the main ? How can I synchronize my ARMs ? I don't think I get it.. In fact, I have to send information at almost the same time.

Thank you for your help and sorry for my poor english.

posted by Antoine Bostem 10 Nov 2016

Antoine - may I ask for more details on your project ? Do you need 3 processors to perform your task(s) ? Perhaps there are other solutions / ideas to share. Yes on using the send in the main (anywhere outside the IRQ routine which is time critical as a general rule).

Also:

       ADCDATA = ADCDATA >> 12;
       ADCDATA= ADCDATA <<4; 

could be reduced to the following ?

       ADCDATA = ADCDATA >> 8;
posted by Sanjiv Bhatia 10 Nov 2016

I have to send the same thing with 3 ARMs. The synchronization between the 3 ARMs is inevitable... At the beginning I put ADCDATA = ADCDATA >> 8; but my (other) problem is the ADC accuracy of each ARM so I rounded down each value, but it is not very effective..

Can I use an mbed port to put the same clock to each ARM ? And is that work to synchronize them ?

posted by Antoine Bostem 11 Nov 2016
4 years, 8 months ago.

Dont use putc inside an interrupt.

Declare a global variable as volatile as a flag, and then in another thread create a loop to check this flag.

something like :

volatile int flag=0;
volatile char myData;

void ISR2()   //this is the response to interrupt, i.e. the ISR
{
    __disable_irq();
    
   
       wake_up=0;  
          
       ADCDATA=ain.read_u16();              
       ADCDATA = ADCDATA >> 12;
       ADCDATA= ADCDATA <<4; 
 /*      device.putc(ADCDATA);  remove this */

       myData = ADCDATA;
       flag++;
 
    __enable_irq();
}
 
void MyCheckThread()
{
  while(true)
  {
      if (flag)
      {
           device.putc(myData);    // Send data to the device
           flag--;                            // if all is ok and enogh speed, now flag must be equal to 0
           
           if (flag)                           // if flag is still>0, it means we miss some interrupt calls... 
               printf("oops, we miss %d calls from interrupt", flag);
      }
 }
}

Thank you for your answer Raph ! Ok, so I need to use RTOS to synchro my ARMs ? I didn't use it yet.

posted by Antoine Bostem 11 Nov 2016