Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

PGA460-Q1: INTERFACING PGA460Q-1 WITH ARDUINO

$
0
0

Part Number:PGA460-Q1

Hello everyone ,

I'm working with PGA460-Q1to interface with ARDUINO-UNO . I'hv prepared a command sequence as per data sheet and software development guide provided by TI. However I am unable to communicate with PGA460-Q1.

i have tried the following approach:

The IO_IF_SEL is set to 0 and IO_DIS = 0 in PULSE_P1 register. UART address is set to 0 (default)

The CLK pin is connected to ground to enable UART mode

Transmitted the command sequence as per attached flow chart and software code. The transmitted commands from Arduino are read on a storage oscilloscope and found correct. However, there is no response at the Tx pin of PGA460-Q1.

Could you please give feedback if there is any issue with the command sequence / code/ any further modifications to the code required.?

I would like to first establish communication using UART. TCI is not yet being used.

NOTE :- EEPROM FACTORY SETTINGS BEING USED .

KINDLY revert back ASAP with valuable input !!!!

Thanks and regards!!

#ARDUINO CODE

// This code is taken from software development guide avaialble in TI website. Modified to simplify the operation with no EEPROM related commands as EEPROM factory default values are considered.

// P1 and P2 threshold values
#define P1_THR_0 0xB0
#define P1_THR_1 0x88
#define P1_THR_2 0x88
#define P1_THR_3 0x88
#define P1_THR_4 0x88
#define P1_THR_5 0x88
#define P1_THR_6 0xF9
#define P1_THR_7 0xCE
#define P1_THR_8 0x73
#define P1_THR_9 0x9C
#define P1_THR_10 0xE7
#define P1_THR_11 0x3F
#define P1_THR_12 0x3F
#define P1_THR_13 0x3F
#define P1_THR_14 0x3F
#define P1_THR_15 0x07
#define P2_THR_0 0xB0
#define P2_THR_1 0x88
#define P2_THR_2 0x88
#define P2_THR_3 0x88
#define P2_THR_4 0x88
#define P2_THR_5 0x88
#define P2_THR_6 0xF9
#define P2_THR_7 0xCE
#define P2_THR_8 0x73
#define P2_THR_9 0x9C
#define P2_THR_10 0xE7
#define P2_THR_11 0x3F
#define P2_THR_12 0x3F
#define P2_THR_13 0x3F
#define P2_THR_14 0x3F
#define P2_THR_15 0x07

#define syncByte 0x55 // Synch byte
#define THRBW 0x80 // Threshold bulk write command
#define SRW 0x50 // Serial write command
#define AFEGAINRANGE 0x0F // AFEGAINRANGE ,holds range Ox0F
#define TVGBW 0x70 // Threshold voltage gain bulk write
#define TVGAIN0 0x88 // TVG commands
#define TVGAIN1 0x88 //TVG commands
#define TVGAIN2 0x88 //TVG commands
#define TVGAIN3 0x41 //TVG commands
#define TVGAIN4 0x04 //TVG commands
#define TVGAIN5 0x10 //TVG commands
#define TVGAIN6 0x40 //TVG commands
#define P1BL 0x00 //Preset and busrt listen command
#define numObj 0x01 //To define object number
//#define SD 0x40
#define UMR 0x28 //Ultrasonic measurement command
#define DECPL_TEMP 0x26

unsigned char calcChecksum(unsigned char); // calcchecksum function 
unsigned char ChecksumInput[35]; //checksum array to hold values 
unsigned char THBUFF[35]; //Threshold buffer array for P1 and P2 
unsigned char AFEGAIN[5]; //AFEGAIN array
unsigned char cmd; //cmd denotes command in checksum function
unsigned char TVG[10]; //Threshold voltage gain array
unsigned char PRE1_BUR_LIS[4]; //Preset and burst listen array
unsigned char ULTRA_MEAS[3]; //Ultrasonic measurement array
unsigned char UMRData[35]; //holds Ultrasonic measurement data i:e data,width,amplitude
unsigned char byte1; //Denotes Object distance byte1+byte2 
unsigned char byte2; 
unsigned char byte3; //Object width measurement
unsigned char byte4; //Peak amplitude measurement


void setup() 
{
// put your setup code here, to run once:
Serial.begin(9600); // Begin Serial communication


// Initialise Threshold values to an array
THBUFF[0]=syncByte;
THBUFF[1]=THRBW;
THBUFF[2]=P1_THR_0;
THBUFF[3]=P1_THR_1; 
THBUFF[4]=P1_THR_2; 
THBUFF[5]=P1_THR_3; 
THBUFF[6]=P1_THR_4; 
THBUFF[7]=P1_THR_5; 
THBUFF[8]=P1_THR_6; 
THBUFF[9]=P1_THR_7;
THBUFF[10]=P1_THR_8;
THBUFF[11]=P1_THR_9;
THBUFF[12]=P1_THR_10; 
THBUFF[13]=P1_THR_11;
THBUFF[14]=P1_THR_12; 
THBUFF[15]=P1_THR_13;
THBUFF[16]=P1_THR_14;
THBUFF[17]=P1_THR_15;
THBUFF[18]=P2_THR_0; 
THBUFF[19]=P2_THR_1; 
THBUFF[20]=P2_THR_2;
THBUFF[21]=P2_THR_3; 
THBUFF[22]=P2_THR_4; 
THBUFF[23]=P2_THR_5;
THBUFF[24]=P2_THR_6;
THBUFF[25]=P2_THR_7;
THBUFF[26]=P2_THR_8;
THBUFF[27]=P2_THR_9;
THBUFF[28]=P2_THR_10;
THBUFF[29]=P2_THR_11; 
THBUFF[30]=P2_THR_12;
THBUFF[31]=P2_THR_13;
THBUFF[32]=P2_THR_14;
THBUFF[33]=P2_THR_15;
THBUFF[34]= calcChecksum(THRBW);

// Initialise AFEGAIN values in array

AFEGAIN[0]=syncByte;
AFEGAIN[1]=SRW;
AFEGAIN[2]=DECPL_TEMP;
AFEGAIN[3]=AFEGAINRANGE;
AFEGAIN[4]=calcChecksum(SRW);

// Initialise TVG values in array

TVG[0]=syncByte;
TVG[1]=TVGBW;
TVG[2]=TVGAIN0;
TVG[3]=TVGAIN1;
TVG[4]=TVGAIN2;
TVG[5]=TVGAIN3;
TVG[6]=TVGAIN4;
TVG[7]=TVGAIN5;
TVG[8]=TVGAIN6;
TVG[9]=calcChecksum(TVGBW);

//ISSUE P1BL to initiate burst pulse to measure Real time of flight

PRE1_BUR_LIS[0]=syncByte;
PRE1_BUR_LIS[1]=P1BL;
PRE1_BUR_LIS[2]=numObj;
PRE1_BUR_LIS[3]=calcChecksum(P1BL);

//ULTRASONIC MEASUREMENT RESULT

ULTRA_MEAS[0]=syncByte;
ULTRA_MEAS[1]=UMR;
ULTRA_MEAS[2]=calcChecksum(UMR);

byte1=UMRData[0]; //Object distance byte1+byte2
byte2=UMRData[1]; 
byte3=UMRData[2]; //Object width measurement
byte4=UMRData[3]; //Peak amplitude measure


}

void loop() {

// delay of 4 seconds

delay(4000);

Serial.write(THBUFF, 35); // Write THRESHOLD BULK WRITE 
delay(50); // 50mS delay
Serial.write(AFEGAIN,5); //Write AFEGAIN 
delay(50); // 50mS delay
Serial.write(TVG, 10); //Write TVGAIN
delay(50); // 50mS delay

// issue burst pulse and read UMR value continuously

while(1u)
{
Serial.write(PRE1_BUR_LIS,4); //Issue preset and burst listen
delay(50); // delay 50mS
Serial.write(ULTRA_MEAS,3); //Issue ultrasonic measurement

if(Serial.available()> 0) // check if data received in the arduino UART buffer
{
byte1 = Serial.read(); //Reads object distance 
byte2 = Serial.read(); //Reads object distance
byte3 = Serial.read(); //Reads object width
byte4 = Serial.read(); //Reads object peak amplitude
}

}
}

//FUNCTION FOR CALCULATING CHECKSUM

unsigned char calcChecksum(unsigned char cmd)
{
unsigned char checksumLoops =0;
unsigned char DataCount =0;
unsigned int carry=0;


switch(cmd)
{
case P1BL : //P1BL // PRESET 1 BURST AND LISTEN - NUMOBJECT IS 1 CHECKSUM 
ChecksumInput[0] = cmd;
ChecksumInput[1] = numObj;
checksumLoops = 2;
break;

case UMR : //UMR // ULTRASONIC MEASUREMENT RESULT CHECKSUM 
//case 2 : //SD //SYSTEM DIAGNOSTICS
ChecksumInput[0] = cmd;
checksumLoops = 1;
break;

case SRW : //RW //REGISTER WRITE CHECKSUM

ChecksumInput[0] = cmd;
ChecksumInput[1] = DECPL_TEMP; //0x26
ChecksumInput[2] = AFEGAINRANGE; //gain_range=0x0F
checksumLoops = 3;
break;

case TVGBW : //TVGBW //TIME VARYING GAIN BULK WRITE CHECKSUM 
ChecksumInput[0] = cmd;
ChecksumInput[1] = TVGAIN0;
ChecksumInput[2] = TVGAIN1;
ChecksumInput[3] = TVGAIN2;
ChecksumInput[4] = TVGAIN3;
ChecksumInput[5] = TVGAIN4;
ChecksumInput[6] = TVGAIN5;
ChecksumInput[7] = TVGAIN6;
checksumLoops = 8;
break;

case THRBW : //THRBW //THRESHOLD BULK WRITE CHECKSUM 
ChecksumInput[0] = cmd;
ChecksumInput[1] = P1_THR_0;
ChecksumInput[2] = P1_THR_1;
ChecksumInput[3] = P1_THR_2;
ChecksumInput[4] = P1_THR_3;
ChecksumInput[5] = P1_THR_4;
ChecksumInput[6] = P1_THR_5;
ChecksumInput[7] = P1_THR_6;
ChecksumInput[8] = P1_THR_7;
ChecksumInput[9] = P1_THR_8;
ChecksumInput[10] = P1_THR_9;
ChecksumInput[11] = P1_THR_10;
ChecksumInput[12] = P1_THR_11;
ChecksumInput[13] = P1_THR_12;
ChecksumInput[14] = P1_THR_13;
ChecksumInput[15] = P1_THR_14;
ChecksumInput[16] = P1_THR_15;
ChecksumInput[17] = P2_THR_0;
ChecksumInput[18] = P2_THR_1;
ChecksumInput[19] = P2_THR_2;
ChecksumInput[20] = P2_THR_3;
ChecksumInput[21] = P2_THR_4;
ChecksumInput[22] = P2_THR_5;
ChecksumInput[23] = P2_THR_6;
ChecksumInput[24] = P2_THR_7;
ChecksumInput[25] = P2_THR_8;
ChecksumInput[26] = P2_THR_9;
ChecksumInput[27] = P2_THR_10;
ChecksumInput[28] = P2_THR_11;
ChecksumInput[29] = P2_THR_12;
ChecksumInput[30] = P2_THR_13;
ChecksumInput[31] = P2_THR_14;
ChecksumInput[32] = P2_THR_15;
checksumLoops = 33; 
break;

default: 
break;

}
carry = 0;

for ( DataCount = 0; DataCount < checksumLoops; DataCount++)
{
if ((ChecksumInput[DataCount] + carry) < carry)
{
carry = carry + ChecksumInput[DataCount] + 1;
}
else
{
carry = carry + ChecksumInput[DataCount];
}

if (carry > 0xFF)
{
carry = carry - 255;
}
}
carry = (~carry & 0x00FF);
return carry;
}

  


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>