[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Paparazzi-devel] module period accuracy ???

From: Christophe De Wagter
Subject: Re: [Paparazzi-devel] module period accuracy ???
Date: Wed, 17 Oct 2012 09:12:07 +0200

The exact timing of WHEN a module periodic is executed is not very accurate. e.g. when you click compute_local_magnetic_field or initialize_polygon_survey it might even be 20ms off. The amount of times per second it is executed is accurate.

If you have spare serial ports (lisa has pleanty) you could use a very low bitrate serial port (I don't know how low it can be: 300 bits/sec 10bits/sec?)

Or you could have a very small function be called in an interrupt routine / timer. 

But I think something else is the real problem and your module could do just fine even if the timing is sometimes slightly (usually not more than 1/500 of second) off.

How fast does the CHDK loop run versus your module loop? How do you know CHDK is not sampling exacly while the LED changes since the 2 loops are not time synced? In order to be observable, the CHDK loop needs to be at least twice as fast as the module, and you need to sample each bit twice to not miss a bit an even more like three times if you also need to know its peak level. -->

I know this reduces the speed again, but I believe it is the only way to get a certain data transfer. Even if paparazzi makes the pulses at perfect intervals, the CHDK loop might be slightly non-constant too, or clocks might drift in time a bit and then the problem remains. 

If you really need to boost the frequency to transfer commands faster, CHDK can read analog voltages, so you can encode several bits into 1 voltage. E.g. to encode 2 bits in 1 analog signal you can use 2 resistors: 

-LED1 <--->  20k  <--\
                     +----->  CHDK 
-LED2 <--->  10k  <--/

L1    L2    ->  CHDK
0     0         0V
3.3   0         1.1V
0     3.3       2.2V
3.3   3.3       3.3V


On Wed, Oct 17, 2012 at 8:15 AM, Chris <address@hidden> wrote:
I have made some tests using CHDK and a Canon SX230HS and it "almost" works ok but i do
have some small problems.
I want to ask anyone that might know if the module period is accurate enough or it might miss
or skip some cycles especially during intialization of the autopilot.
I have wrote the module code and the chdk script and it works flawlessly in pulse count mode
where the camera camera counts the number of pulses and decides what to do but it is a slow
process. In this mode module period accuracy does not matter thus it works fine.
In pulse duration mode which is very fast my pulses during the autopilot initialization
are all over the place but i haven't checked what happens during normal operation,
maybe during intialization some things take more time which would explain the inaccuracy.
Some times it works fine, other times some pulses get longer like the call to the module's
periodic function (@ 15 Hz) is delayed.
I am now searching of a way to use a spare autopilot timer otherwise there is always the I2C -> PW
converter option using a small AVR (attiny85) or a spare ppm encoder.
Here is the periodic function:

void chdk_periodic(void){

uint8_t x = 0;

if (chdk_command > 0){
   // Since this variable is ment for Joystick camera control where the operator
   // has visual confirmation of each command execution there is no need for a buffer.
   // If the buffer is completely empty execute the new command else try again...
   for (x=0; x<sizeof(cmd_buffer); x++){
       if (cmd_buffer[x] != 0){

       }else{ *cmd_buffer = chdk_command; }
   chdk_command = 0;

if (cmd_buffer[0] > 0){

   if (command_finished == TRUE){
      pulse_counter = *cmd_buffer;
      command_finished = FALSE;

   if (pulse_counter > 0){
      LED_OFF(12);  //LED_ON=Low. LED_OFF=High.

           if (reset_counter <= 0){
              // Shift left the whole buffer one position
              for (x=1; x<COMMAND_BUFFER_SIZE; x++){ cmd_buffer[x-1] = cmd_buffer[x]; }
              cmd_buffer[COMMAND_BUFFER_SIZE-1] = 0; // set last buffer slot to 0
              command_finished = TRUE;

           }else{ reset_counter--; }


uint8_t chdk_cmd(uint8_t cam_cmd)
uint8_t x = 0;

if (cam_cmd == CHDK_CLEAR_BUFFER){
   for (x=0; x<COMMAND_BUFFER_SIZE; x++){
   pulse_counter = 0;
   reset_counter = 0;
   command_finished = TRUE;

           // Find an empty slot in the buffer
           for (x=0; x<COMMAND_BUFFER_SIZE; x++){
               if (cmd_buffer[x]==0){ break; }
           if(x != COMMAND_BUFFER_SIZE){ cmd_buffer[x] = cam_cmd; } // register the command


Paparazzi-devel mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]