Interface with MCU using FTDI UART

Bluetooth, USB, UART, Storage, etc.
ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Mon Nov 14, 2016 5:05 pm

Sorry for the delay, back on that project now. Thanks for the hint regarding the flow control settings, I can connect and read out the firmware version now.

However, reading data I see strange results. This is basically the code from the api test with the blinking LED (no sensors are connected):

Code: Select all

7 : 1 1 0 0 ; 0 0 0 0 0 0
11 : 1 1 1 0 ; 0 0 0 0 0 0
15 : 1 1 0 0 ; 0 0 0 0 0 0
0 : 0 0 0 0 ; 0 233 768 0 0 0
0 : 0 0 0 0 ; 0 35 896 0 0 0
0 : 0 0 0 0 ; 0 111 896 0 0 0
0 : 0 0 0 0 ; 0 165 768 0 0 0
0 : 0 0 0 0 ; 0 228 896 0 0 0
9 : 1 1 1 0 ; 0 0 0 0 0 0
13 : 1 1 0 0 ; 0 0 0 0 0 0
1 : 1 1 0 0 ; 0 0 0 0 0 0
5 : 1 1 1 0 ; 0 0 0 0 0 0
9 : 1 1 0 0 ; 0 0 0 0 0 0
0 : 0 1 1 1 ; 112 0 0 0 0 0
0 : 1 0 1 1 ; 760 0 0 0 0 0
0 : 1 1 1 1 ; 504 0 0 0 0 0
0 : 0 0 1 1 ; 880 0 0 0 0 0
0 : 0 1 1 1 ; 824 0 0 0 0 0
0 : 0 1 0 1 ; 696 0 0 0 0 0
0 : 1 0 0 1 ; 48 0 0 0 0 0
0 : 1 1 0 1 ; 816 0 0 0 0 0
0 : 0 0 0 1 ; 752 0 0 0 0 0
0 : 0 1 0 1 ; 496 0 0 0 0 0
0 : 0 1 1 1 ; 112 0 0 0 0 0
0 : 1 0 1 1 ; 760 0 0 0 0 0
0 : 1 1 1 1 ; 504 0 0 0 0 0
0 : 0 0 1 1 ; 880 0 0 0 0 0
0 : 0 1 1 1 ; 824 0 0 0 0 0
7 : 1 1 1 0 ; 0 0 0 0 0 0
11 : 1 1 0 0 ; 0 0 0 0 0 0
15 : 1 1 0 0 ; 0 0 0 0 0 0
3 : 1 1 1 0 ; 0 0 0 0 0 0
7 : 1 1 0 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 1 0 ; 0 0 0 0 0 0
4 : 1 1 0 0 ; 0 0 0 0 0 0
5 : 1 1 1 0 ; 0 0 0 0 0 0
9 : 1 1 1 0 ; 0 0 0 0 0 0
13 : 1 1 0 0 ; 0 0 0 0 0 0
1 : 1 1 0 0 ; 0 0 0 0 0 0
5 : 1 1 1 0 ; 0 0 0 0 0 0
12 : 1 1 0 0 ; 0 0 0 0 0 0


I also cannot pass 4 digital output values any more. Anything more than 2 and I get a "Invalid parameter" message.

Is the board broken now?

ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Thu Nov 17, 2016 6:21 pm

Any ideas left?

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Interface with MCU using FTDI UART

Postby BITalino » Thu Nov 17, 2016 7:54 pm

Hi there,

Regarding the 4 digital output values, please confirm the version of your BITalino device. The lastest BITalino version only has 2 digital outputs, which would explain the "Invalid parameter" message when you try to trigger 4 outputs.

As for the data, it is indeed strange to see multiple samples with sequence number 0. Also, the gaps in the sequence number of the other samples are not consistent with a regular data unpacking process.

What sampling rate are you using? Can you please confirm that you are not obtaining error messages related with loss of samples?

Best regards,
The BITalino Team

ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Fri Nov 18, 2016 10:04 am

@ 2 vs. 4 digital outputs: Seems that I only tried this code with our old board. Surprises me, but this can be the only explanation then. Good!

@ sequence gaps: Sampling runs at 1000 Hz and the output code (from your 'test.cpp') displays every 100th line.

EDIT: Ok, you are right. This should create something like [0,4,8,12,0,4,8,12] or a similarly regular sequence.

@ sequence number 0: I do not receive any error messages; the code runs within a try/catch sequence which has been triggered by other BITalino exceptions before, but not in this case.

It is not only the missing sequence number that worries me, but also the strange measurement values occurring only then on the right side.
Last edited by ole.traupe on Fri Nov 18, 2016 10:31 am, edited 1 time in total.

ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Fri Nov 18, 2016 10:20 am

Ok, seems to run stable at 100 Hz:

Code: Select all

0 : 1 1 1 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 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1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0
4 : 1 1 1 0 ; 0 0 0 0 0 0
8 : 1 1 0 0 ; 0 0 0 0 0 0
12 : 1 1 1 0 ; 0 0 0 0 0 0
0 : 1 1 0 0 ; 0 0 0 0 0 0


Only that 100 Hz is a bit low for a sound EMG analysis...

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Interface with MCU using FTDI UART

Postby BITalino » Fri Nov 18, 2016 11:51 am

Apologies for any inconvenience that the change in the number of digital IOS may have caused. We had to make some compromises in order to have free pins on the MCU to introduce other convenient features.

In particular now the battery level monitoring has an independent analog input (before you had to choose to use A6 either for battery level or sensor data input). Also, there is now a DAC pin, which opens further possibilities.

Regarding the sampling issue. Another parameter that can influence the result is the number of samples you are reading (in each call to the read() function). If you request too few samples it may explain the sample gaps.

You can test this by requesting 100 samples each time, which may already work well with 1kHz sampling rate. Let us know if you can make progress in this way.

Best regards,
The BITalino Team

ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Fri Nov 18, 2016 4:37 pm

Apologies for any inconvenience that the change in the number of digital IOS may have caused. We had to make some compromises in order to have free pins on the MCU to introduce other convenient features.


No problem at all. Maybe I did know this at some point.

Regarding the sampling issue. Another parameter that can influence the result is the number of samples you are reading (in each call to the read() function). If you request too few samples it may explain the sample gaps.

You can test this by requesting 100 samples each time, which may already work well with 1kHz sampling rate. Let us know if you can make progress in this way.


That is exactly what I am doing, either @ 100 Hz (works) or 1000 Hz (does ot work). As I said, this is the code from the BITalino C++ API example.


EDIT: Maybe the serial interface is insufficient for this data rate?

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Interface with MCU using FTDI UART

Postby BITalino » Fri Nov 18, 2016 6:01 pm

Apologies for perhaps not providing the most complete details, but there are two different aspects... one is the sampling rate (which you so very well mentioned to have tested with 100Hz and 1000Hz), and another is the number of samples obtained from the device.

The sampling rate is defined in the API call to the start(...) method, and you can select 1, 10, 100 or 1000Hz.

The number of samples obtained from the device is an input parameter to the read(...) method. For example if you call read(200) with a sampling rate of 1000Hz, the device should buffer 200 milliseconds worth of data and then send it.

Given that this is a time critical operation, reading too few samples may affect the performance of your setup.

Best regards,
The BITalino Team

ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Mon Nov 21, 2016 12:43 pm

Thank you for the additional information!

With our old board (Plugged) via Bluetooth the very same (!) code runs fine at 100 or 1000 Hz. The sequence channel always reads [0,4,8,12,0,4,8,12,0...] in this example (displayed every 100th frame).

Or new (R)evolution Plugged BT runs into problems at 1000 Hz (see above). To make things clearer I post the data collection loop code here:

Code: Select all

   try
   {
      
      // connect to device
      BITalino dev("COM21");

      // get firmware version
      std::string ver = dev.version();
      printf("Connected to %s, press ESCAPE to exit data acquisition.\n\n", ver.c_str());

      // set battery threshold (optional)
      dev.battery(10);
      //printf("Battery set.\n");
      
      // start acquisition of all channels at 1000 Hz
      BITalino::Vint chans;
      for (int c=0;c<nChans;c++) {
         chans.push_back(c);
      }
      dev.start(sRate, chans);
      
      
      // prepare LED toggle
      bool ledState = false;

      BITalino::VFrame frames(100); // initialize the frames vector with 100 frames
      do {

         // toggle LED state
         ledState = !ledState;
         BITalino::Vbool outputs;
         outputs.push_back(ledState);
         outputs.push_back(false);
         //outputs.push_back(false);      //(R)evolution only offers 2 DOs
         //outputs.push_back(false);
         dev.trigger(outputs);
         
         // read from device
         dev.read(frames); // get 100 frames from device
         BITalino::Frame &f = frames[0];  // get a reference to the first frame of each 100 frames block
         printf("%d : %d %d %d %d ; %d %d %d %d %d %d\n",   // dump the first frame to console
               f.seq,
               f.digital[0], f.digital[1], f.digital[2], f.digital[3],
               f.analog[0], f.analog[1], f.analog[2], f.analog[3], f.analog[4], f.analog[5]);
         

      } while (!keypressed(27)); // until a Escape  is pressed

      // stop acquisition
      dev.stop();

   } // dev is destroyed here (it goes out of scope)

   catch(BITalino::Exception &e) {
      printf("BITalino exception: %s\n", e.getDescription());
   }


sRate and nChans are read from a config file. nChans is always 6, sRate is 100 or 1000. The result is the same if these parameters are hardcoded in the above snippet.

Does this code work for you with a (R)evolution board via FTDI at 1000 Hz?

ole.traupe
Posts: 43
Joined: Tue Jun 17, 2014 10:50 am

Re: Interface with MCU using FTDI UART

Postby ole.traupe » Mon Nov 21, 2016 1:36 pm

Ok, FTDI @ 1000 Hz works fine if 1000 samples are pulled at a time (vs. 100 as in the above code).


EDIT: I think it would be good advice to give out to your customers using the FTDI interface to keep chunk size defined the very same as samples/s.


Return to “I/O”




cron