Avatar for user101931

user101931

Member since Jul 2019 • Last active Dec 2019
  • 2 conversations
  • 17 comments

Most recent activity

  • Avatar for user101931

    I just tried 3 and it looks like the same output as 0.02 that I have before

    is there a way to check the data without using print? and another way to call the function repeatedly if we want to call it fast? for visualizing the data, one other method I can think of is writes file, I believe the write file should be faster than console.log(), but I am concerning if write file write it to the flash memory? if so, i am afraid I do not have enough flash for the data in espruino .

    Yes, I will try that inline c, I tried the one with adding "complied" in the code and it did not work, but does increase a bit speed.

    OHHHHH no, if gettime return in second, that proof the 833 Hz is impossible with javascript

  • Avatar for user101931

    Haha ^ ^

    and I thought gettime() returns in ms. Isn't 0.003 is in ms?

  • Avatar for user101931

    The FIFO mode provides the correct data but I have to reset every time to get another round of FIFO data, since it will stop filling after it full. The reset process clear everything that might stall in the FIFO and results in missing some data (because timestamp incremented a lot ), so it is not very ideal

    So ideally, I would like to save the program in flash memory in Epsurino, and when I supply the power to Epsurino or turn on some switch, it will start to fetch data

    So this is how I would use those data:

    For now,
    I will integrate the gyro over that timestamp that's outputting at 833Hz, then use UART to pass the integrated gyro data and accelerometer to the data handling unit.

    So I would prefer to integrate every set of data at every 833Hz = 0.0012s

    I just realized you edit #24 I am gonna look at those links now

  • Avatar for user101931

    I will integrate the gyro over that time period, so I think I will every single set of data that output at 833Hz,
    then I will use UART to pass the integrated data and accelerometer to the data handling unit.

    "Is so, the FIFO buffer is probably filling up before each data item is removed from the buffer and the device is cramming in bytes until errors in output are seen. Could this be a possibility?"

    I think this is possible. but if this is true, wouldn't it make it very hard to pull the data in high frequency?

    Haha have a good time

  • Avatar for user101931

    Haha, no problem. I am in the mountain time zone

  • Avatar for user101931

    I just tried setInterval(extraction,150);
    but it is only outputting one correct data set this time.

    8539 -645 -18294 -256 126 4104 -668 4262111 0.02233409881
    11 15 15 229 225 227 -669 3328 0.02214241027
    11 11 19 229 227 223 -653 4864 0.02214145660
    

    Oh sorry, on page 57/114 FIFO ODR can be 833Hz frequency range from 12.5 to 6.6kHz. so we choose 833Hz because it is a nice frequency for the algorithm that we are developing for processing the data

  • Avatar for user101931

    Hi Robin,

    Thank you for helping me so much

    Sorry if I misunderstand, I am not so sure how to measure the repeated part if you mean measure how fast the interval is running.

    I put the measure time in the all read_FIFO, read_Normal, and read_Time and this is my output

    Read FIFO 0.00033950805 946686551.91729545593
    elapsed 0.00323581695
    Read FIFO 0.00033664703 946686551.92159366607
    elapsed 0.00324440002
    Read FIFO 0.00037765502 946686551.92586135864
    elapsed 0.00328826904
    Read FIFO 0.00033760070 946686551.93021202087
    elapsed 0.00324249267
    Read FIFO 0.00037860870 946686551.93448162078
    elapsed 0.00328826904
    Read FIFO 0.00033855438 946686551.93883323669
    elapsed 0.00324440002
    Read Normal 0.00038623809 946686551.94312000274
    elapsed 0.00335884094
    Read Time 0.00034713745 946686551.94751930236
    elapsed 0.00702095031
    8793 -567 -18040 -23 -102 4237 undefined 3902886 0.03861045837
    Read FIFO 0.00034427642 946686551.95695877075
    elapsed 0.00325965881
    Read FIFO 0.00038528442 946686551.96123790740
    elapsed 0.00331974029
    Read FIFO 0.00034427642 946686551.96561431884
    elapsed 0.00326347351
    Read FIFO 0.00038528442 946686551.96989727020
    elapsed 0.00330162048
    Read FIFO 0.00034523010 946686551.97425270080
    elapsed 0.00325775146
    Read FIFO 0.00034427642 946686551.97857093811
    elapsed 0.00325298309
    Read Normal 0.00034999847 946686551.98289966583
    elapsed 0.00330257415
    Read Time 0.00035190582 946686551.98722839355
    elapsed 0.00691509246
    8029 -1069 -14708 -24 -117 4237 undefined 3902939 0.03862571716
    

    and the code looks like this

    //Read timestamp function
    
    function readtime(ss)
    {
            var t = getTime();
            var elapsed = 0;
            console.log( "Read Time " + (getTime()-t) + " " + t );
            hi = SPI_read(FIFO_DATA_OUT_L,ss);
            hi2 = SPI_read(FIFO_DATA_OUT_H,ss);
            non = SPI_read(FIFO_DATA_OUT_L,ss);
            lo = SPI_read(FIFO_DATA_OUT_H,ss);
            step = SPI_read(FIFO_DATA_OUT_L,ss);
            step = SPI_read(FIFO_DATA_OUT_H,ss);
            hi2 = hi2 << 16;
            hi = hi << 8;
            Value = hi2 | hi | lo;
            elapsed = getTime()-t;
            console.log( "elapsed " + elapsed );
            return Value;
    }
    
    
    var st = 0;
    //var s2 = 0;
    //print( "OMX", "OMY", "OMZ","AX", "AY", "AZ",,"TEMP","TimeStamps");
    //var start = getTime();
    
    function extraction()
    {
           // "compiled";
              //print(Ntotaldata());
              st = getTime();
              //if(((SPI_read(FIFO_STATUS2,ss))&0b0001­0000) != 0b00010000)
              //{
                 console.log( 
                  omx  = read_FIFO(ss),
                  omy  = read_FIFO(ss),
                  omz  = read_FIFO(ss),
                  ax   = read_FIFO(ss),
                  ay   = read_FIFO(ss),
                  az   = read_FIFO(ss),
                  temp = read_normal(ss),
                  tm   = readtime(ss), 
                   getTime()-st);
             // }
    }
    
    
    setInterval(extraction,0.002);
    

    ss

    
    function read_FIFO(ss)
    {
      var test;
      var t = getTime();
      var elapsed = 0;
      console.log( "Read FIFO " + (getTime()-t) + " " + t );
      
      test = signshort(SPI_read(FIFO_DATA_OUT_H,ss)<<­8|SPI_read(FIFO_DATA_OUT_L,ss));
    
      elapsed = getTime()-t;
      console.log( "elapsed " + elapsed );
      return test
    }
    
    function read_normal(ss)
    {
      var test1;
      var t = getTime();
      var elapsed = 0;
      console.log( "Read Normal " + (getTime()-t) + " " + t );
      test = signshort(SPI_read(TEMP_OUT_H,ss)<<8 | SPI_read(TEMP_OUT_L,ss));
      elapsed = getTime()-t;
      console.log( "elapsed " + elapsed );
      return test1;
    }
    

    I believe the time I measure is in millisecond, and I also measure the clock frequency of the SPI is running correctly at 10 MHz, so I think both system and SPI should techninilly running fast enough? and thank you again : )

    yes, that is the IMU datasheet.

    I configured FIFO as continuous mode so I can keep the data from the IMU with a set timestamp and it can keep running for hours.

    The goal is to do the data collection at 833 Hz for hours and the output timestamps gap should be fixed (increment by 48 or 49 each timestamp). The FIFO mode provides the correct data but I have to reset every time to get the new set of data since it will stop filling after it full. The reset process result in missing some data, so it is not very ideal

    Attached is the SPI clock frequency measured from the oscilloscope

  • Avatar for user101931

    Hi Robin and AkosLukacs,

    Thank you for taking your time helping me.

    Here is my code and output for measuring one read_FIFO, (compare with 1/833Hz = 0.0012s). I just realized getTime() was actually returning million seconds (Correct me if I am wrong), the speed is actually very fast if the value that return is ms. (500-1000 times fast than the data generated).

    I am concerning if that's my IMU's configuration, I will double-check that.

    However, when I decrease the speed to 52Hz or 26 Hz, the data was actually generated properly. and when I optimize the code, a couple more correct data set will appear before it gets messed up.

    Not really sure what might be the issue now.

    var t = getTime();
    var elapsed = 0;
    console.log( "start of SPI call " + (getTime()-t) + " " + t );
    //extraction();
    
    omx  = read_FIFO(ss);
    
    elapsed = getTime()-t;
    console.log( "elapsed " + elapsed );
    
    

    And the corresponding output is:

    start of SPI call 0.00700378417 946685774.25032615661
    elapsed 0.01593494415
    

    Enable extraction and disable read_FIFO() in the code

    start of SPI call 0.00715160369 946686294.47058963775
    elapsed 0.02543163299
    

    The code to run one complete extraction() with no print

    var t = getTime();
    var elapsed = 0;
    console.log( "start of SPI call " + (getTime()-t) + " " + t );
    
    
    
    function extraction()
    {
                  omx  = read_FIFO(ss),
                  omy  = read_FIFO(ss),
                  omz  = read_FIFO(ss),
                  ax   = read_FIFO(ss),
                  ay   = read_FIFO(ss),
                  az   = read_FIFO(ss),
                  temp = read_normal(ss),
                  tm   = readtime(ss)
    }
    
    extraction();
    
    elapsed = getTime()-t;
    console.log( "elapsed " + elapsed );
    
    

    Output

    start of SPI call 0.00709629058 946686935.69506931304
    elapsed 0.04530811309
    

    Here is my read_FIFO code, I am calling two SPI_read in this function, FIFO_DATA_OUT_H/L are two registers to store the generated FIFO data

    function read_FIFO(ss)
    {
      return signshort(SPI_read(FIFO_DATA_OUT_H,ss)<<­8|SPI_read(FIFO_DATA_OUT_L,ss));
    }
    

    Thank you very much.

  • Avatar for user101931

    Hi Robin,

    Thank you very for replying and helping.

    I set them to setInterval and that error does not occur anymore.

    I believe I am using the hardware SPI and this is my SPI set up

    function SPI_setup()
    {
      SPI1.setup
      ({sck:A5,
         miso:A6,
         mosi:A7,
         baud: 10000000,
         mode: 0,
         order:'msb',
         bits:8
        });
    }
    

    The read time is to read the timestampes from the IMU, which is part of the data collection from the IMU.
    the readtime Code looks like this:

    function readtime(ss)
    {
            hi = SPI_read(FIFO_DATA_OUT_L,ss);
            hi2 = SPI_read(FIFO_DATA_OUT_H,ss);
            non = SPI_read(FIFO_DATA_OUT_L,ss);
            lo = SPI_read(FIFO_DATA_OUT_H,ss);
            step = SPI_read(FIFO_DATA_OUT_L,ss);
            step = SPI_read(FIFO_DATA_OUT_H,ss);
            hi2 = hi2 << 16;
            hi = hi << 8;
            Value = hi2 | hi | lo;
            return Value;
    }
    

    I checked the time needed to collect one set of data is fixed at .029ms, IMU generate each set of data at 833Hz = 1/833 ~=0.0012, the time for the IMU to generate one set the data is a lot faster than the program excution. I think the problem is when the FIFO is full, the pattern will be messed up.

    I am not very sure why PICO takes so long to read a set of data. I tried to look up the default system clock rate and it seems 84MHz already based on this E.setClock(Correct me if I am wrong), is there a way to improve the program execution/reading speed?

    Changed version code

    function extraction()
    {
              st = getTime();
              s2 = SPI_read(FIFO_STATUS2,ss);
              if(((s2)&0b00010000) != 0b00010000)
              {
                 console.log( omx = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_­L,ss),
                  omy = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_­L,ss),
                  omz = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_­L,ss),
                  ax  = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_­L,ss),
                  ay  = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_­L,ss),
                  az  = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_­L,ss),
                  temp = read_FIFO(TEMP_OUT_H, TEMP_OUT_L, ss),
                  tm = readtime(ss), getTime()-st);
              }
    }
    
    setInterval(extraction,0.00000000001);
    

    Output:

    ///////////////The last number is the excution time//////////////
    8273 -829 -15075 -77 -53 4231 -562 7840166 0.02954864501
    6509 -2139 -9095 -88 -57 4253 -513 7840215 0.02941513061
    5273 -2745 -8939 -86 -61 4244 -548 7840264 0.02940368652
    4831 -2701 -8543 -84 -57 4250 -548 7840312 0.02936649322
    4447 -2693 -8315 -89 -64 4251 -553 7840361 0.02934265136
    4105 -2713 -7793 -85 -55 4250 -527 7840409 0.02941608428
    3779 -2715 -6983 -86 -63 4240 -541 7840458 0.02939796447
    3465 -2695 -5959 -90 -56 4245 -542 7840506 0.02937698364
    ////////////Data start to have wrong pattern//////////////
    ////////////Data start to have wrong pattern//////////////
    3191 -2637 343 -267 -337 -45 -548 16699391 0.02938270568
    -21 21 53 -9 255 43 -548 5888 0.02933788299
    29 21 3 17 5 17 -541 4864 0.02938842773
    -249 9 15 255 5 15 -535 4352 0.02937221527
    

    Spi:

    function SPI_write(addr,data,ss)
    {
      SPI1.send([WRITE|addr,data],ss);       //write to address
    }
    
    
    function SPI_read(addr,ss)
    {
      result=SPI1.send([addr|READ,0x00],ss)[1]­;
      return result;
    }
    
Actions