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.

PGA460: coding procedure

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

Hi 

I have built a shield for the arduino mega using the PGA 460 ultrasonic transducer chip. I am having trouble with the exact coding procedure for both pga460 and arduino.

Any help in this matter would be great..

  • Hi Mick,
    Have you viewed both the PGA460 Energia Library and Code Example ( www.ti.com/.../slac741 ) and PGA460 Software Development Guide ( www.ti.com/.../slaa730 )? These two in combination will explain the software flow and provide real examples.

    Which communication mode are you attempting leverage: UART, SPI, OWU, or TCI?
    Arduino uses 5V logic levels for UART and SPI, so be sure to place a 100kOhm pull-up resistor from the PGA460's TEST pin to a 5V rail.
    If you are creating your own checksum calculator, and need to verify your checksum values, you can use the PGA460 EVM GUI ( www.ti.com/.../slac739 ) without the actual EVM hardware. There is an Interface Mode page with a UART tab, which will allow you to input a USART string into the terminal, and generate/append the checksum.
  • Hi Akeem,

    I have looked at the examples, It seems very complex for what I am trying to accomplish. I am having trouble understanding all the code in the software development guide. I am just trying to set up the device to listen and then if it receives to burst and listen. I am just trying to to accomplish the first step of the pga 460 initialisation.
    Regards

    Mick
  • Hi Mick,

    For the most basic test to determine if your PGA460 circuit is operational, execute the following command sequence:
    (Note, these examples assume your device is using the factory settings at UART_ADDR=0, you are using a transformer driven transducer, and using UART to communicate.)
    1) Power-on device
    2) Master transmit a threshold bulk write command (CMD16): 0x{55 10 88 88 88 88 88 88 84 21 08 42 10 80 80 80 80 00 88 88 88 88 88 88 84 21 08 42 10 80 80 80 80 00 85}
    3) Master transmit a Preset 1 burst and listen command for 1 object (CMD 1): 0x{55 00 01 FE}
    4) Master waits the equivalent of Preset 1's record length time of 8.192ms (factory default time)
    5) Master requests slave to return the ultrasonic measurement results (CMD5): 0x{55 05}

    If you want to read the echo data dump profile instead of the ultrasonic measurement results, perform the following instead:
    1) Power-on device
    2) Master transmit a threshold bulk write command (CMD16): 0x{10 52 98 5B 00 A1 D0 90 87 4D 1C C3 FE 89 24 5A D7 6D AD B9 D1 95 D5 5D 7C 57 31 13 A7 D6 51 42 56 23}
    3) Master transmit a register write command (CMD10) to EE_CNTRL to set DATADUMP_EN=1: 0x{55 0A 40 80 35}
    4) Master transmit a Preset 1 burst and listen command for 1 object (CMD 1): 0x{55 00 01 FE}
    5) Master waits the equivalent of Preset 1's record length time of 8.192ms (factory default time)
    6) Master requests slave to return the 128 bytes of echo data dump results (CMD5): 0x{55 07}
  • Hi Akeem,

    I am using the a direct drive topology using external high-side FETs. Can I still use this code to determine if your PGA460 circuit is operational.

    Regards

    Mick

  • Hi Mick,
    Yes, you can use the same UART sequence for the direct drive topology. The default current limit for Preset 1 is 100mA, which is acceptable for the direct drive mode. After you are able to confirm that the device is operation and communication is working, you should set the preset driver current limit to 50mA when using direct-drive mode.
  • Hi Akeem

    Can you please send me the code as a file/folder so I can test the circuit, I am still not quite sure on how to code the chip, with the arduino.

    Regards

    Mick
  • Hi Mick,

    The PGA460 Energia Library and Code Example ( www.ti.com/.../slac741 ) is already downloadable in the format of a zip. You can import this zip into Energia or Arduino by navigating to the menu bar "Sketch --> Include Library --> Add .ZIP Library..."

    You will then be able to open the GetDistance.INO sketch from the menu bar "File --> Examples --> PGA460_USSC".
    Try Verifying the sketch to check for errors.
    You will need to modify the PGA460_USSC.cpp library file to be pin compatible with the Arduino and PGA460 shield you've created.
    The PGA460 Software Development Guide ( www.ti.com/.../slaa730 ) is a PDF that explains how to interpret the GetDistance sketch.

    What specific step of the software implementation are you having trouble with? The code import, Energia-to-Arduino conversion, resolving errors, the lack of a device response, or invalid return data?
  • Hi Akeem,

    I have imported the code and looking through the code it is based on user input. I am trying to specifically hard write the code to just perform one task. I also am having trouble with the resolving of errors. I am unsure of the whole set up of the code to make the chip work. 

    Regards

    Mick

  • Hi Mick,

    If you want to run the USSC_PGA460 Energia examples in standalone (bypass the user COM port inputs), then you must comment out #define userInputMode. This will bypass the user input stage, and refer directly to the initialized values set in the configuration variables section of the .ino sketch.

    I have created a basic Energia hard coded example (non user input based and non USCC_PGA460 library based) to one-time write the threshold mid-code values and loop-run a P1 burst+listen command based on the LaunchPad's button press. If you monitor the OUTA/B pins, you will notice them toggle every time buf17 is executed. Similarly, the DECPL pin will toggle logic high during the burst+listen command to indicate the transducer is being excited. I have not yet enabled the UART read of the measurement results because this code is intended to be limited example of hardcoded commands.

    You can copy this code directly into an Energia sketch to run:

    //*** BEGIN CODE ***///
    //cmd 0 - p1 burst listen
    byte buf0[4] = {0x55, 0x00, 0x01, 0xFE};
    //cmd 1 - p2 burst listen
    byte buf1[4] = {0x55, 0x01, 0x01, 0xFD};
    //cmd 10 - register write decple to time of 4.096ms
    byte buf10[5] = {0x55, 0x0A, 0x26, 0x00, 0xCF};
    //cmd 17 - broadcast p1 burst listen
    byte buf17[4] = {0x55, 0x11, 0x01, 0xED};
    //cmd 19 - broadcast p1 listen only
    byte buf19[4] = {0x55, 0x13, 0x01, 0xEB};
    //cmd 25 - broadcast bulk threshold write
    byte buf25[35] = {0x55, 0x19, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x21, 0x08, 0x42, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x21, 0x08, 0x42, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x7C};

    const int buttonPin = PUSH2; // the number of the pushbutton pin
    const int ledPin = RED_LED; // the number of the LED pin
    int buttonState = 0; // variable for reading the pushbutton status

    void setup() {

    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT_PULLUP);
    delay(1000);

    // put your setup code here, to run once:
    Serial1.begin(19200); // initialize PGA460 UART serial channel
    delay(1000);

    //assume UART_ADDR=0
    //bulk threshold write mid-code values to clear THR_CRC_ERR
    Serial1.write(buf25, sizeof(buf25));
    delay(100);

    // [TODO] set p1 rec length to 4.096ms

    // set UART_ADDR=0's time decouple to 4.096ms
    Serial1.write(buf10, sizeof(buf10));
    delay(100);
    }

    void loop() {
    // put your main code here, to run repeatedly:

    // check if the pushbutton is pressed.
    while (digitalRead(buttonPin) == HIGH){}

    // broadcast p1 burst+listen (non-dependent on UART_ADDR)
    Serial1.write(buf17, sizeof(buf17));

    // delay by 100ms
    delay(100);

    //[TODO] read back ultrasonic measurement results

    // toggle red LED
    digitalWrite(ledPin, !(digitalRead(ledPin))); // turn the LED on (HIGH is the voltage level)

    // repeat loop every second
    delay (1000);
    }
    //*** END CODE ***//