Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Hardware synchronization for different sensors with different output rates

  1. #1
    Junior Member
    Join Date
    Apr 2019

    Hardware synchronization for different sensors with different output rates

    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.
    Click image for larger version. 

Name:	hw_synced.png 
Views:	3 
Size:	56.9 KB 
ID:	16514

    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 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!

  2. #2
    Junior Member
    Join Date
    Apr 2019
    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.
    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_triggered = LOW;
    void trigger_cam(){
      if(cam_triggered == LOW){
        cam_triggered = HIGH;
        cam_triggered = LOW;
    void loop() {
     unsigned long frame_count;
     //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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts