Hardware synchronization for different sensors with different output rates

Status
Not open for further replies.

tuanle

New member
Hi,
I am a newbie with embedded systems so I greatly appreciate any help!

My project is to develop a hardware synchronized sensor suite, which contains one IMU and 2 cameras. The IMU runs at 200 Hz and both cameras run at 20 Hz.

I also have a PPS output from a master clock. What I have in mind is to use the PPS as an input to one pin to start sending triggered pulses (pwm?) from other 3 pins (imuPin, cameLeftPin,camRightPin), each to one sensor.

I need to record the both the timestamp at which the trigger occured and the number of times it has been activated (sequence number). The reason behind this is to correct the timestamp associated with each measurement by matching with the correct timestamp of the same sequence. This is illustrated in the picture below.
hw_synced.png

The timestamp correction is done at driver side on the host computer so you don't here to think about it.

What I want is to have all pulses, including the PPS input, are edge aligned with corresponding rate for each one. I am not totally sure if this is achievable.

I found this thread https://forum.pjrc.com/threads/42545-Synchronized-multi-frequency-PWM-outputs?highlight=synchronization is somewhat close to my system but it did not need to sync to an external PPS. My understanding is that the PWM outputs are synced against the sys_tick ?

I am not really sure how to start so any help is very much appreciated!
 
So after digging through a lot of posts, I've managed to use the IntervalTimer to generate pulse trains for IMU and one of my camera.
The code is below.
Code:
IntervalTimer imuTimer,camTimer;

const int imuOutPin = 9;
const int camLeftOutPin = 20;
volatile unsigned long imu_seq_count = 0;
int imu_triggered = LOW;
int cam_triggered = LOW;

void setup() {
  pinMode(imuOutPin, OUTPUT);
  pinMode(camLeftOutPin, OUTPUT);
  imuTimer.begin(trigger_imu,2500);//IMU freq @200Hz
  camTimer.begin(trigger_cam,25000);//Cam rate @20Hz
}

void trigger_imu(){
  if(imu_triggered == LOW){
    imu_triggered = HIGH;
    imu_seq_count++;
  }
  else 
    imu_triggered = LOW;
  digitalWriteFast(imuOutPin,imu_triggered);
}

void trigger_cam(){
  if(cam_triggered == LOW){
    cam_triggered = HIGH;
  }
  else 
    cam_triggered = LOW;
  digitalWriteFast(camLeftOutPin,cam_triggered);  
}
void loop() {
 unsigned long frame_count;
 noInterrupts();
 frame_count=imu_seq_count;
 interrupts();
 //need to send frame_count and pulse time to host PC
}

If I understand correctly, these 2 pulse trains should be edge-aligned. I will verify it with an oscilloscope.

However, I still got stuck with 2 things :

1) How can I record the time a pulse occurs in each timers? I need it for timestamp the meassage.

2) I don't know how to start my timers only when detecting a pulse on one of other pins?

I appreciate any help!
 
Status
Not open for further replies.
Back
Top