Other Parts Discussed in Thread: PGA460
Hello All,
I am working on a project for my thesis involving distance ranging. The measurement range required is 6 meters and I have chosen the PGA460-Q1 with Arduino Uno as the microcontroller. The Uno and PGA460-Q1 are interfaced through UART. The PROWAVE Air-coupled Ultrasonic transducer 400EP14D which is of mono-static type is used along with the PROWAVE transformer K4000002 (3370).
The above circuit was rigged and referred from Figure 136 and Table 101 of PGA460-Q1 datasheet.
- C(INN) and C(INP) values were calculated according to the formula in Table 101 for 40KHz frequency. Capacitor values close to the calculated values were added due to immediate unavailability.
- PIN 12 (SCLK) was pulled HIGH with 5V as instructed in the Page 4 of the PGA460 Software Development Guide to configured 5V UART logic level.
- PIN 9 (TEST PIN) is pulled HIGH to 5V or 3.3V through a 150kE resistor to select 5V UART logic level as instructed in the TEST Pin Functionality section (7.3.12) of the PGA460-Q1 datasheet.
The Transformer-Transducer combination was obtained from the SRM400 Application Circuit. This circuit is in working status and detects objects upto 1.5 meter.
I am trying to read bursts at PIN5 (OUTA) with the following Arduino sketch. The DEV_STAT0 Register value is read (128 value) and the THR_CRC_ERR parameter is 0 (i.e., No Error) and the VPWR_OV_TH parameter is set to 00b (i.e., 12.3V) and VIN is at 8.5V. The REGMAP register read and write UART Commands are working properly, but the Burst and Listen command for both Presets (CMD 0 and 1) don't give bursts at OUTA.
Please help me out with some valuable suggestions. Some important comments in the Arduino sketch are in bold.
Thank you.
Arduino Sketch:
byte ChecksumInput[44];
byte regAddr;
byte regData;
int c;
int m;
byte Numobjects = 0x02;
byte P1_THR_0 = 0x88;
byte P1_THR_1 = 0x88;
byte P1_THR_2 = 0x88;
byte P1_THR_3 = 0x88;
byte P1_THR_4 = 0x88;
byte P1_THR_5 = 0x88;
byte P1_THR_6 = 0x42;
byte P1_THR_7 = 0x10;
byte P1_THR_8 = 0x84;
byte P1_THR_9 = 0x21;
byte P1_THR_10 = 0x08;
byte P1_THR_11 = 0x40;
byte P1_THR_12 = 0x40;
byte P1_THR_13 = 0x40;
byte P1_THR_14 = 0x40;
byte P1_THR_15 = 0x00;
byte P2_THR_0 = 0x88;
byte P2_THR_1 = 0x88;
byte P2_THR_2 = 0x88;
byte P2_THR_3 = 0x88;
byte P2_THR_4 = 0x88;
byte P2_THR_5 = 0x88;
byte P2_THR_6 = 0x42;
byte P2_THR_7 = 0x10;
byte P2_THR_8 = 0x84;
byte P2_THR_9 = 0x21;
byte P2_THR_10 = 0x08;
byte P2_THR_11 = 0x40;
byte P2_THR_12 = 0x40;
byte P2_THR_13 = 0x40;
byte P2_THR_14 = 0x40;
byte P2_THR_15 = 0x00;
void setup()
{
Serial.begin(19200, SERIAL_8N2);
delay(10);
c = 1;
m = 1;
}
/*CHECKSUM FUNCTION*/
byte calcChecksum(byte cmd)
{
int checksumLoops = 0;
cmd = cmd & 0x001F;
if(cmd == 16)
{
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;
}
if (cmd == 0) // Burst and listen (Preset1) command
{
ChecksumInput[0] = cmd;
ChecksumInput[1] = Numobjects;
checksumLoops = 2;
}
if( cmd == 9) // Register Read
{
ChecksumInput[0] = cmd;
ChecksumInput[1] = regAddr;
checksumLoops = 2;
}
if (cmd == 10) // Register write
{
ChecksumInput[0] = cmd;
ChecksumInput[1] = regAddr;
ChecksumInput[2] = regData;
checksumLoops = 3;
}
uint16_t carry = 0;
for (int i = 0; i < checksumLoops; i++)
{
if ((ChecksumInput[i] + carry) < carry)
{
carry = carry + ChecksumInput[i] + 1;
}
else
{
carry = carry + ChecksumInput[i];
}
if (carry > 0xFF)
{
carry = carry - 255;
}
}
carry = (~carry & 0x00FF);
return carry;
}
/*MAIN LOOP*/
void loop()
{
Serial.flush();
if (c)
{
byte buf16[35] = {0x55, 0x10, P1_THR_0, P1_THR_1, P1_THR_2, P1_THR_3, P1_THR_4,P1_THR_5, P1_THR_6,P1_THR_7, P1_THR_8, P1_THR_9, P1_THR_10, P1_THR_11, P1_THR_12, P1_THR_13,P1_THR_14, P1_THR_15,P2_THR_0, P2_THR_1, P2_THR_2, P2_THR_3, P2_THR_4, P2_THR_5, P2_THR_6,P2_THR_7, P2_THR_8, P2_THR_9, P2_THR_10, P2_THR_11, P2_THR_12, P2_THR_13,P2_THR_14, P2_THR_15,calcChecksum(0x10)};
Serial.println("\nWrite Threshold Resistors\n");
Serial.write(buf16,sizeof(buf16));// No Response Operation (Threshold Bulk Write)
regAddr = 0x1c; //Frequency register
regData = 0x32;//50
byte buf[5] = {0x55, 0x0a, 0x1c, 0x32, calcChecksum(0x0a)};//85,10(cmd-),28,50
Serial.println("\nWrite Frequency Resistor\n");
Serial.write(buf,sizeof(buf));// No Response Operation (Register Write)
delay(10);
{
regAddr = 0x1e; //PULSE_P1 Register
regData = 0x30;//0011 0000
byte buf1[5] = {0x55, 0x0a, regAddr, regData, calcChecksum(0x0a)};
Serial.write(buf1,sizeof(buf1));// No Response Operation (Register Write)
}
{
regAddr = 0x23;//FREQ_DIAG Register
regData = 0x33;//0011 0011
byte buf1[5] = {0x55, 0x0a, regAddr, regData, calcChecksum(0x0a)};
Serial.write(buf1,sizeof(buf1));// No Response Operation (Register Write)
}
{
regAddr = 0x25;//FVOLT_DEC Register
regData = 0x1c;//0001 1100
byte buf1[5] = {0x55, 0x0a, regAddr, regData, calcChecksum(0x0a)};
Serial.write(buf1,sizeof(buf1)); // No Response Operation (Register Write)
}
{
regAddr = 0x1f;//PULSE_P2 Register
regData = 0x10;//0001 0000
byte buf1[5] = {0x55, 0x0a, regAddr, regData, calcChecksum(0x0a)};
Serial.write(buf1,sizeof(buf1)); // No Response Operation (Register Write)
}
c = 0;
}
// if (m)
// {
// for (int l=0;l<6;l++)
// {
Serial.flush();
delay(10);
{
byte buf2[4] = {0x55, 0x00, Numobjects, calcChecksum(0x00)};
Serial.println("\nSending Burst and Listen Command for Preset 1\n");
Serial.write(buf2,sizeof(buf2)); // No Response Operation (Burst and listen (Preset1))
}
delay(10);
Serial.flush();
if(m)
{
byte sensorValue;
byte buf4[2] = {0x55, 0x08};//, calcChecksum(0x08)};
Serial.write(buf4,sizeof(buf4)); //Response Operation (All Except Register Read)
//delay(1);
for(int n=0;n<4;n++)
{
delay(10);
if (n ==1)
sensorValue = Serial.read();
else
Serial.read();
}
Serial.println("\nReading the second byte of response frame for System Diagnostics command\n");
Serial.println(sensorValue);
m=0;
}
byte sensorValue;
regAddr = 0x40; //Enter any address of a REGMAP Register to read its value
byte buf[4] = {0x55, 0x09, regAddr, calcChecksum(0x09)};
Serial.write(buf,sizeof(buf)); //Response Operation (Register Read)
for(int n=0;n<3;n++)
{
delay(10);
if (n == 1)
sensorValue = Serial.read();
else
Serial.read();
}
Serial.println("\nReading the second byte of response frame for Register Read command\n");
Serial.println(sensorValue);
// }
// m=0;
// }
}