Author Topic: Fast sampling via BlueTooth  (Read 439 times)

Kimwo

  • Newbie
  • *
  • Posts: 7
Fast sampling via BlueTooth
« on: March 03, 2019, 12:26:14 PM »
Since I don't have a fancy storage scope to capture the 50ms lorawan transmission current I am trying to measure, I have been trying to get the BT logging to go as quickly as possible.  Using the recent github .ino I changed line 99:

#define BT_REFRESH_INTERVAL 200 //ms  - from 200 to 20ms and that seemed to work just fine.

Now I would like to go faster so I am looking at lines 478/479:

//ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_16 | ADC_AVGCTRL_ADJRES(0x4ul); //take 16 samples adjust by 4
  ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_1024 | ADC_AVGCTRL_ADJRES(0x4ul); //take 1024 samples adjust by 4


I uncommented 478 and commented out 479.  Figuring it was now going 16 times faster I changed the 200 ms to 13.
That also seemed to work better.

If I want to go even faster I seem to need to change line 480:

ADC->SAMPCTRL.reg = 0b100; //0x00 fastest

This ties up with the datasheet, but I don't know whether I can just reduce this 0b100 progressively - and if so what to do with the avgctrl.reg above (there is a line 478 which shows just one sample - but I suspect using that may affect accuracy).
Also I presume I have to keep reducing the BT report interval or I won't see the effect.

If anyone has any guidance it would be most appreciated.
« Last Edit: March 03, 2019, 12:59:50 PM by Kimwo »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5813
  • Country: us
    • LowPowerLab
Re: Fast sampling via BlueTooth
« Reply #1 on: March 04, 2019, 06:53:26 PM »
You're on the right track.
The ADC sampling speed and averaging is described in chapter 33 of the SAMD21 datasheet.
If you sample faster, you get more noise. More averaging = less noise but also less bandwidth.
avgctrl.reg just defined how many samples you want to average before getting a result.
If you want to deep dive, I suggest reading through chapter 33 to get more familiar with how the SAMD21 ADC works.

Kimwo

  • Newbie
  • *
  • Posts: 7
Re: Fast sampling via BlueTooth
« Reply #2 on: March 06, 2019, 06:11:33 AM »
Thank you for your reassurance, although I have never seen a chip datasheet with 1200+ pages before!  I think I need
a bathysphere for my dive.  I may be some time - don't hold your breath (sic). 

I have found various good youtube videos - apparently to get to the 350 ksamples/sec in the spec you need all sorts of windowing and interrupts which I shall not be trying.  I just want to see if I can get a sample reported via BT about every msec (or so).

Kimwo

  • Newbie
  • *
  • Posts: 7
Re: Fast sampling via BlueTooth
« Reply #3 on: April 29, 2019, 12:01:00 PM »
Well in the short term I changed strategy:  programmed a one wire oscilloscope using an Arduino mini pro and the
following instructable: https://www.instructables.com/id/Another-Arduino-Oscilloscope/
Works well provided you note the update in the comments about setting the comm port.  My arduino runs at 8mhz
but it still works (via an 11 year old imac running windows 10 even). 
Attachment shows screen shot of a 62msec lorawan pulse.

I shall return to the BT option - since I think it will provide more accurate data.