This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BOOSTXL-PGA460: Cannot Get Energia "GetDistance" to Display Same Distance Values as GUI

Part Number: BOOSTXL-PGA460
Other Parts Discussed in Thread: PGA460, ENERGIA

Hello,

I've been working with these boards on a project for a little while now, but I still cannot get Energia to give me the same distance values as the GUI. To keep it simple, I'll just show the mismatch through the GetDistance sketch instead of BusDemo. I'll talk through each prompt and what I've done in the PGA460_USSC.cpp file to try to get them to match. I am using the transformer-driven closed-top transducer. I am using OWU (set up according to the busdemo video that Akeem has sent to me previously). I have the board set to address 0. I always program EEPROM before switching to Energia.

First, here's what the Data Monitor in the GUI gives me for my small object at an easy position to detect:

Unit 0 Object at Midpoint

As you can see, I can get a very consistent 0.380-0.381m distance value. The noise floor is sufficiently below the constant threshold line that I never get a false positive when my object is at that position. Everything is perfect for what I need.

Next, I wanted to make sure I put the values used in the GUI into Energia, through PGA460_USSC.cpp. I read the values from the memory map in the GUI (attached below), then used those values in presets in the .cpp file. I changed case 0 of the .cpp file for threshold and TVG to make things easy.

Here is the memory map from GUI:

;GRID_USER_MEMSPACE
00 (USER_DATA1),88
01 (USER_DATA2),88
02 (USER_DATA3),88
03 (USER_DATA4),88
04 (USER_DATA5),88
05 (USER_DATA6),88
06 (USER_DATA7),39
07 (USER_DATA8),CE
08 (USER_DATA9),73
09 (USER_DATA10),C2
0A (USER_DATA11),10
0B (USER_DATA12),80
0C (USER_DATA13),80
0D (USER_DATA14),80
0E (USER_DATA15),80
0F (USER_DATA16),00
10 (USER_DATA17),00
11 (USER_DATA18),00
12 (USER_DATA19),00
13 (USER_DATA20),00
14 (TVGAIN0),60
15 (TVGAIN1),12
16 (TVGAIN2),8A
17 (TVGAIN3),00
18 (TVGAIN4),0E
19 (TVGAIN5),FD
1A (TVGAIN6),FC
1B (INIT_GAIN),F3
1C (FREQUENCY),90
1D (DEADTIME),00
1E (PULSE_P1),85
1F (PULSE_P2),12
20 (CURR_LIM_P1),7F
21 (CURR_LIM_P2),FF
22 (REC_LENGTH),0C
23 (FREQ_DIAG),00
24 (SAT_FDIAG_TH),EE
25 (FVOLT_DEC),7C
26 (DECPL_TEMP),0A
27 (DSP_SCALE),00
28 (TEMP_TRIM),00
29 (P1_GAIN_CTRL),00
2A (P2_GAIN_CTRL),00
2B (EE_CRC),7E
40 (EE_CNTRL),04
41 (BPF_A2_MSB),8B
42 (BPF_A2_LSB),86
43 (BPF_A3_MSB),F3
44 (BPF_A3_LSB),72
45 (BPF_B1_MSB),06
46 (BPF_B1_LSB),47
47 (LPF_A2_MSB),7C
48 (LPF_A2_LSB),D3
49 (LPF_B1_MSB),01
4A (LPF_B1_LSB),97
4B (TEST_MUX),00
4C (DEV_STAT0),80
4D (DEV_STAT1),00
5F (P1_THR_0),88
60 (P1_THR_1),88
61 (P1_THR_2),88
62 (P1_THR_3),88
63 (P1_THR_4),88
64 (P1_THR_5),88
65 (P1_THR_6),39
66 (P1_THR_7),CE
67 (P1_THR_8),73
68 (P1_THR_9),C2
69 (P1_THR_10),10
6A (P1_THR_11),80
6B (P1_THR_12),80
6C (P1_THR_13),80
6D (P1_THR_14),80
6E (P1_THR_15),00
6F (P2_THR_0),88
70 (P2_THR_1),88
71 (P2_THR_2),88
72 (P2_THR_3),88
73 (P2_THR_4),88
74 (P2_THR_5),88
75 (P2_THR_6),39
76 (P2_THR_7),CE
77 (P2_THR_8),73
78 (P2_THR_9),C2
79 (P2_THR_10),10
7A (P2_THR_11),80
7B (P2_THR_12),80
7C (P2_THR_13),80
7D (P2_THR_14),80
7E (P2_THR_15),00
7F (THR_CRC),9A
EOF

And here is the threshold preset 0 in the .cpp file. As you can see, I copied these values to both preset 1 and 2, since I just need the system to work with these specific values reliably.

void pga460::initThresholds(byte thr)
{
	switch (thr)
	{
		case 0: //Copy of Custom from GUI (Old was 25%)
		   P1_THR_0 = 0x88;
		   P1_THR_1 = 0x88;
		   P1_THR_2 = 0x88;
		   P1_THR_3 = 0x88;
		   P1_THR_4 = 0x88;
		   P1_THR_5 = 0x88;
		   P1_THR_6 = 0x39;
		   P1_THR_7 = 0xCE;
		   P1_THR_8 = 0x73;
		   P1_THR_9 = 0xC2;
		   P1_THR_10 = 0x10;
		   P1_THR_11 = 0x80;
		   P1_THR_12 = 0x80;
		   P1_THR_13 = 0x80;
		   P1_THR_14 = 0x80;
		   P1_THR_15 = 0x00;
		   P2_THR_0 = 0x88;
		   P2_THR_1 = 0x88;
		   P2_THR_2 = 0x88;
		   P2_THR_3 = 0x88;
		   P2_THR_4 = 0x88;
		   P2_THR_5 = 0x88;
		   P2_THR_6 = 0x39;
		   P2_THR_7 = 0xCE;
		   P2_THR_8 = 0x73;
		   P2_THR_9 = 0xC2;
		   P2_THR_10 = 0x10;
		   P2_THR_11 = 0x80;
		   P2_THR_12 = 0x80;
		   P2_THR_13 = 0x80;
		   P2_THR_14 = 0x80;
		   P2_THR_15 = 0x00;
		break;

For the prompts:

I am using OWU and so prompt 1 is 2.

Prompt 2 is 9.6kbaud to match the serial monitor.

Prompt 3 is 0 to use the Threshold preset I showed above.

I skip prompt 4 since I prefer to use my own settings set in the GUI (currently 58.8kHz, 5 pulses, 500mA). Are these values not being used by Energia? I'm just trying to think where things might go wrong, and I know all 3 of these values get reset when I re-flash the board in the GUI.

For prompt 5, I use 3 since that is the same range displayed in the GUI.

Prompt 6, I do the same as for the threshold values and choose preset 0. Below is the rewritten preset 0:

//Set fixed AFE gain value
	switch (tvg)
	{
		case 0:  //CUSTOM FROM GUI	 OLD:25% Level
		   TVGAIN0 = 0x60;
		   TVGAIN1 = 0x12;
		   TVGAIN2 = 0x8A;
		   TVGAIN3 = 0x00;
		   TVGAIN4 = 0x0E;
		   TVGAIN5 = 0xFD;
		   TVGAIN6 = 0xFC;		
		break;
		

For prompt 7, I choose 2 just to avoid the transmission burst giving me a false positive.

Prompt 8 is 0.

Prompt 9 is 0.

Prompt 10 is 0.

Prompt 11 is 5 for some arbitrary delay.

Prompt 12 is 1.

Prompt 13 is 0.

I then receive these very strange distance values in the serial monitor. The object and transducer/board have not been moved at all.

Getdistance Output at Midpoint

Any idea why P1 is not displaying anything, and P2 is giving varying distances?

The code shows that P1 is used first, then P2 is run if nothing is detected. However, both of my threshold presets use the exact same values now (copied from the GUI). Or am I misunderstanding what P1 and P2 mean here? Are P1 and P2 not the threshold presets? Are some other values than just threshold values being changed depending on which preset is used? If that is the case, how can I go about matching what the GUI does?

My goal is simply to replicate what I get through the GUI (hopefully soon on 4 boards using BusDemo). Again, I copied the GUI threshold values to both P1 and P2 of preset 0, since those are the only values I will need for now (constant 56).

Are the threshold/gain values I input not being used? Is the 58.8kHz, 5 pulse count, and 500mA from the GUI not being used? Any other ideas?

  • Some information from any additional tests I could think to run:

    I replaced the muRata MA58MF14-7N values in the .cpp file with the values from the GUI memory map for my unit 0 above. I have noticed that even though the distances reported are still not as consistent as with the GUI, they are still slightly better than before. They don't vary quite as much, and I have fewer "no object..." messages. Here is a copy of the new serial monitor output. As you can see, I chose option 0 for prompt 4 to use those GUI memory map values. Also, I edited the number of values shown for more precision. Nothing else was changed.

    Using Custom Transducer Settings

    I also ran an EDD from GetDistance for P1BL and then P2BL, and compared the curve to one from the GUI. All 3 were almost identical. I forgot to save the two comparison pictures, however, so I won't have those to show unless you ask me to repeat it. In any case, just like the same problem months ago, it seems the problem is with Energia not using my GUI settings somewhere.

    Another note. A while back I changed Energia's digitalDelay equation on Akeem's recommendation, in order to make it compensate for pulse count and frequency like the GUI does. I only use 5 pulses and 58.8kHz on my transducers for this application. Here's what it looks like:

    double digitalDelay = (5/58800)*343/2;	//For now, assuming 5 pulses and 58.8kHz for every transducer

    Thanks in advance!

  • Hi Joseph,

    Your approach of loading the GUI settings into the Energia code is correct. You've forced your threshold and time varying gain cases of 0 to match the GUI's; however, I should note that you can skip the time varying gain step since these settings are already in EEPROM. Assuming your EEPROM settings are programmed with the desired values, you should only have to run the threshold step in the Energia code. If you skip the other settings in the Energia sketch such as the driver frequency and strength or the receiver DSP values, then the EEPROM values will be used.

    One recommendation I have is to compare the raw time of flight values the ultrasonic measurement result command returns. This will eliminate any GUI vs Energia differences caused by the time of flight to distance conversion. To get the raw time of flight in the GUI, navigate to the Data Monitor page --> Export tab --> and check the "Log UMR" box. This will print the time of flight as a hex value in the Datalog box in the Utilities tab on the right column.

    To pull the time of flight from the Energia code, you can either create a new function, or comment out the ToF to distance conversion code, and only pass the 

    case 0: //Obj1 Distance (m)
    {
         objDist = (ultraMeasResult[1]<<8) + ultraMeasResult[2];
         objReturn = objDist; // SKIP TOF to DISTANCE CONVERSION //(objDist/2*0.000001*speedSound) - digitalDelay;
         break;
    }

    The raw ToF should be the same in both the GUI and Energia codes.

    I don't have an answer as to why Preset 1 is not running/returning a result as expected, unless your alwaysLong boolean is set to true in the Energia code.

    The quickest check to ensure consistency between your GUI and Energia settings is to run the Energia sketch for a couple of burst/listen loops, then, without power cycling the device, use the GUI to read back all EEPROM and threshold register values.

  • Hi Akeem,

    Once again thank you very much for the continued assistance.

    I ran some burst/listen cycles in the GUI using the exact same settings as before. All EEPROM values were kept intact and the both threshold presets are the same as in the Energia code.

    I ran the GUI cycle five times and got the following TOF data from the utilities tab:

    O1 TOF: 08A2

    O1 TOF: 08AA

    O1 TOF: 08AA

    O1 TOF: 08A4

    O1 TOF: 08A5

    I then changed the case 0: //Obj1 Distance code in the PGA460_USSC.cpp file to the same as your raw TOF equation above:

    case 0: //Obj1 Distance (m)
    {
    objDist = (ultraMeasResult[1]<<8) + ultraMeasResult[2];
    objReturn = objDist; //SKIP TOF TO DISTANCE CONVERSION (objDist/2*0.000001*speedSound) - digitalDelay;
    break;
    }

    Then I run Energia and use the same settings as before, which match perfectly with all values from EEPROM and the threshold map used in the GUI. (I did check that the values stored in EEPROM from Energia were being kept when returning to the GUI, as well).

    I made sure Energia was only passing case 0 for this objReturn data, as shown below. The only thing changed from default in this BusDemo sketch is that I am displaying 5 distance digits.

    if(successMeas == true){distance = ussc.printUltrasonicMeasResult(0);}
    else{distance = 0.00;} //UMR command fail, force print 0.00m


    I then get the following distance measurements:

    0.32516
    0.32516
    0.32551
    0.32516
    0.32516
    0.32516
    0.32482

    If I revert the objReturn equation in the .cpp file back to the original and reupload the code, I get the following distances:

    0.32551
    0.32551
    0.32585
    0.32516
    0.32516
    0.32516
    0.32551

    Which are almost identical to the ones with the "raw TOF" data above.
    Am I messing something up here? Any idea why the raw TOF data matches the converted one?
    I'm also not sure why the raw TOF data from the GUI is so different than its reported distances (0x08AA is 2218 in decimal, vs. 0.395m reported distance in GUI).
    Is the raw TOF data from the GUI obtained differently than in Energia?


    Here's some additional info that may or may not help:
    I tested 20 points in a 15x20cm grid and found that the difference between physically-measured and Energia-reported distances (from BusDemo) is somewhat constant over all the points for an individual board, but not across boards, even though both boards are almost exactly the same distance from the test grid (reference photo shown below).

    physical setup for reference


    Board 0 (closest in photo) gives a required offset that's between +0.04m and 0.055m depending on the point, and board 1's offset is between +0.018m and 0.035m.

    And again, in the GUI both boards give roughly the expected distance values regardless of the point.

    I know these boards weren't exactly intended to be used for such a small-scale application, but I'm hoping I can get this working for my current setup.

    Ideally I'd be able to get the Energia distances reported to be as accurate as from the GUI without having to do the manual offsets in the sketch for each point, which I am currently doing, so that it could be used outside this exact grid or between points on the grid as well.

    If you have any other suggestions that might help with that, I really appreciate it.

    Regards,

    Joseph Summers

  • Hi Joseph,

    The reason why capturing the raw TOF is important is because this is what the PGA460 reports via UART command 5 "Ultrasonic measurement result". This value is not passed through any equation or conversion in the GUI, so it should match the Energia's output if no register values are changing.

    I will need to update the Energia project to include a sketch to output the time-of-flight and/or distance to help with this debug.