7 Replies Latest reply on Jun 4, 2020 3:06 AM by RashiV_61

    Implementing a hardware trigger for each frame using GPIO (OV2740)

    PhMi_4136011

      Hi,

      I am currently working with a CX3 and an OV2740 10 bit Raw camera. Stream 10 bit raw bw sensor with active pixel array of 1928 x 1088

       

      The image stream is working fine, even in different frame rates (30,15,10,6), so thanks for the previous support!

       

      Now i want to add an hardware trigger for each recorded image to trigger a projector. Currently i implemented an GPIO call (GPIO 17) at the end of the DMACallback function. This is working fine, but it skips the first recorded image and the timing for the projector is not optimal...I would eighter like to call the trigger before recording every image or several miliseconds after the DMA Callback, ist that possible? Where would i need to call the GPIO SetValue function?

       

      Kind regards,

      Philipp

        • 1. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
          RashiV_61

          Hello Philipp,

           

          From the firmware you shared, I understood that after every frame you are setting the value of the GPIO for the trigger.  Is this working as expected?

          Please let me know where else do you need the GPIO trigger except at the frame end.

           

          Please remove the CyU3PDebugPrint APIs from the callback as it is suggested not to use blocking APIs in the callback. This might improve the timing. You can use SET/GET events to communicate instead of the CyU3PDebugPrint API.

           

          Regards,

          Rashi

          • 2. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
            PhMi_4136011

            Hi Rashi,

            The trigger is working as expected. I have removed the debug prints by now, but the timing ist still the same.

             

            I would like to send a trigger before every image acquistion is started. It doesnt matter if it is exactly at the start of recording or 10 to 50 ms before (running at 6 fps there is an intervall of 166ms between each frame).

             

            Edit: If it is not possible to trigger before each frame, is there a way to delay the trigger even after the DMA Callback? For example in a different callback function or function call, where i could implement the gpio call? I think i didnt find the correct function to call the gpio for my setup.

             

            Kind regards,

            Philipp

            • 3. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
              RashiV_61

              Hello Philipp,

               

              For adding a trigger just before every frame valid signal, we would need to modify the CX3 state machine. As CX3 is having a fixed GPIF state machine the modifications cannot be done.

               

              If it is not possible to trigger before each frame, is there a way to delay the trigger even after the DMA Callback?

              >> This can be done by using a timer. After a frame ends the GPIO will be toggled. Along with the GPIO toggling a timer can be started.  The timer value can be according to the frame rate (6 fps in your case).

               

              In the CyCx3UvcAppInit function, the timer needs to be created 

              for example  CyU3PTimerCreate (&UvcTimer, CyCx3UvcAppProgressTimer, 0x00, TIMER_PERIOD, 0, CYU3P_NO_ACTIVATE);

              The second parameter CyCx3UvcAppProgressTimer is the callback function which is called when the timer overflows. In this call back function, you can trigger the GPIO (for the start of the frame).

               

              For the first start of the frame, the GPIO toggle can be done when the CyCx3UvcAppStart is called under CY_U3P_USB_EVENT_SETINTF USB event or just after the host application is opened

               

               

              Please let me know if any queries on this

               

              Regards,

              Rashi

              • 4. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
                PhMi_4136011

                Hi Rashi,

                i have followed your instructions and implemented additional timers.

                They are created at the end of CyCx3UvcAppInit. If i start the timers with rescheduleTicks, the triggering is working fine.

                 

                But to be more flexible, i would like to create a one-shot timer that can be called individualy. Best case scenario would be a one-shot call within the DMACallback function for each frame. But this doenst seem to work. (code attached)

                 

                Can a CyU3PTimerStart call be implemented within an other Callbackfuntion? If not, where else would i need to implement the timers to be called after each frame acquisition? Did i miss something or used the functions in an incorrect order?

                 

                Edit1: i tried several different locations of the CyU3PTimerStart function call and figured out, that if its called right at the end of the DMACallback function (see code), the trigger is behaving as expected, but the streaming already ended. Currently I dont know where to call the CyU3PTimerStart function, since i would like to have the correct trigger behaviour while streaming?

                 

                Edit2: After adding the CyU3PTimerStopp/Start function calls below the rest_timer_enable case within the DMA Callback, problem seems to be solved. Why is this the correct location, because of other callbacks with higher priority?

                 

                Kind regards,

                Philipp

                • 5. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
                  RashiV_61

                  Hello Philipp,

                   

                  Please let me know why do you use two timers under CY_U3P_DMA_CB_PROD_EVENT? Is this working fine?

                   

                  You can try this as well:

                  - Toggle GPIO (without timer) directly when you get the partial buffer in the DMA callback i.e the mark for frame end of the 1 st frame.

                  - After that start a timer which will trigger another toggle of GPIO for the start of a frame of the second frame

                  if (type == CY_U3P_DMA_CB_PROD_EVENT)

                      {

                  ........

                  .....

                   

                  if(dmaBuffer.count < CX3_UVC_DATA_BUF_SIZE)   //partial buffer // marks frame end

                              {

                                

                                // GPIO toggle  //marking frame end of current frame

                                CyU3PTimerStart  // for triggering the start of the frame for the next frame

                   

                              }

                  }

                   

                  For the first start of the frame, the GPIO toggle can be done when the CyCx3UvcAppStart is called under CY_U3P_USB_EVENT_SETINTF USB event or just after the host application is opened

                   

                  Please let me know if this works

                   

                  Regards,

                  Rashi

                  • 6. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
                    PhMi_4136011

                    Hi Rashi,

                    i was using two triggers (set gpio high/low) to ensure, that the signal can be detected by the oscilloscope... just for debuging purpose...

                     

                    I now implemented a single timer at your purposed location (if(dmaBuffer.count < CX3_UVC_DATA_BUF_SIZE)) and this is working fine.

                     

                    While oscilloscoping the timings of Framevalid, Linevalid and the generated Trigger at different frame rates (6,10,30 fps) and exposures (10, 15 20 ms) i run into two problems/questions.

                     

                    1. Does the duration of the readout of an image with constant exposure time change with varying frame rate? Probing the Linevalids shows me that the time of readout of an image corresponds to the complete interval time (6 fps equals 166ms, 10 fps equals 100ms, 30 fps equals 33ms). Is this continuous readout behaviour fixed due to the function of the cmos rolling shutter sensor? if not, is there a possibility to run the sensor in 6 fps mode while archiving the readout time of 30fps?

                     

                    2. Recording frames at different frame rates with the same exposure time, i realized that i.e. images taken at 6fps and 10ms exposure time are much brighter than the one at 30 fps and 10ms. Is there a way to probe real value of the exposure time? Does the setExposureTime  function needs to be configured frame rate dependent? Did i miss something while setting exposure times?

                     

                    Kind regards and thanks for the awesome support!

                    Philipp

                     

                     
                    • 7. Re: Implementing a hardware trigger for each frame using GPIO (OV2740)
                      RashiV_61

                      Hello Phillipp,

                       

                      Thanks for the update. We are glad to hear that the suggested idea worked.

                       

                      - The video data is read by CX3 only when the Frame valid and line valid are high ( might not be for the whole 33 ms when frame rate is 30 fps). During the vertical and horizontal blanking period, the video data is not sent by the image sensor as well as not read by the CX3

                      - Yes, I went through some of the web links which mentions that exposure time and frame rate are dependent. It is suggested to keep the exposure time twice the frame rate. SET_CUR request can be check to know the value of the exposure time set.

                      Frame rate vs. shutter speed, setting the record straight - Vimeo Blog

                       

                      Regards,

                      Rashi