Other Parts Discussed in Thread: PGA460-Q1, PGA460
Thread 中讨论的其他器件: PGA460
大家好、
我正在为我的论文做一个项目、涉及距离测距。 所需的测量范围为6米、我选择了采用 Arduino Uno 的 PGA460-Q1作为微控制器。 Uno 和 PGA460-Q1通过 UART 连接。 单静态类型的 PROWAVE 空气耦合超声波传感器400EP14D 与 PROWAVE 变压器 K4000002 (3370)搭配使用。
上述电路由 PGA460-Q1 数据表的图136和表101进行了处理和引用。
- C (INN)和 C (INP)值根据表101中的公式计算得出、适用于40KHz 频率。 由于不可用、添加了接近计算值的电容器值。
- 根据 PGA460软件开发指南第4页的指示、引脚12 (SCLK)被拉高至5V 、以配置5V UART 逻辑电平。
- 引脚9 (测试引脚)通过150kE 电阻器上拉至5V 或3.3V、以根据 PGA460-Q1数据表的测试引脚功能部分(7.3.12)中的说明选择5V UART 逻辑电平。
变压器-换能器组合是从 SRM400应用电路获得的。 该电路处于工作状态、可检测长达1.5米的物体。
我尝试使用以下 Arduino sketch 在 PIN5 (OUTA)读取突发。 DEV_STAT0寄存器值被读取(128个值)、THR_CRC_ERR 参数为0 (即无错误)、VPWR_OV_TH 参数设置为00b (即12.3V)、VIN 设置为8.5V。 REGMAP 寄存器的读写 UART 命令工作正常、但两个预设(CMD 0和1)的突发和监听命令不会在 OUTA 提供突发。
请帮我提供一些宝贵的建议。 Arduino sketch 中的一些重要注释以粗体显示。
谢谢你。
Arduino 草图:
字节校验和输入[44];
字节 regAddr;
字节 regData;
int c;
int m;
字节数量对象= 0x02;
字节 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 = 0x42;
字节 P1_THR_7 = 0x10;
字节 P1_THR_8 = 0x84;
字节 P1_THR_9 = 0x21;
字节 P1_THR_10 = 0x08;
字节 P1_THR_11 = 0x40;
字节 P1_THR_12 = 0x40;
字节 P1_THR_13 = 0x40;
字节 P1_THR_14 = 0x40;
字节 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 = 0x42;
字节 P2_THR_7 = 0x10;
字节 P2_THR_8 = 0x84;
字节 P2_THR_9 = 0x21;
字节 P2_THR_10 = 0x08;
字节 P2_THR_11 = 0x40;
字节 P2_THR_12 = 0x40;
字节 P2_THR_13 = 0x40;
字节 P2_THR_14 = 0x40;
字节 P2_THR_15 = 0x00;
void setup()
{
Serial.begin(19200、serial_8N2);
延迟(10);
C = 1;
M = 1;
}
/*校验和函数*/
字节 calcChecksum (字节 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)//突发和监听(Preset1)命令
{
ChecksumInput[0]= cmd;
ChecksumInput[1]=数字对象;
校验和循环= 2;
}
if (cmd =9)//寄存器读取
{
ChecksumInput[0]= cmd;
ChecksumInput [1]= regAddr;
校验和循环= 2;
}
if (cmd == 10) //寄存器写入
{
ChecksumInput[0]= cmd;
ChecksumInput [1]= regAddr;
ChecksumInput[2]= regData;
校验和循环= 3;
}
uint16_t 进位= 0;
对于(int i = 0;i < checksumLoops;i++)
{
如果((ChecksumInput[i]+进位)<进位)
{
进位=进位+ ChecksumInput[i]+ 1;
}
其他
{
进位=进位+ ChecksumInput[i];
}
如果(进位> 0xFF)
{
进位=进位- 255;
}
}
进位=(~进位& 0x00FF);
回车;
}
/*主循环*/
void loop()
{
serial.flush();
如果(c)
{
字节 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 ("\n 写入阈值电阻器\n");
serial.write (buf16、sizeof (buf16));//无响应操作(阈值批量写入)
regAddr = 0x1c;//频率寄存器
regData = 0x32;//50
字节 buf[5]={0x55、0x0a、0x1c、0x32、calcChecksum (0x0a)};//85、10 (cmd-)、28、50
serial.println ("\n 写入频率电阻器\n");
serial.write (buf、sizeof (buf));//无响应操作(寄存器写入)
延迟(10);
{
regAddr = 0x1E;//PULSE_P1寄存器
regData = 0x30;//0011 0000
字节 buf1[5]={0x55、0x0a、regAddr、regData、calcChecksum (0x0a)};
serial.write (buf1、sizeof (buf1));//无响应操作(寄存器写入)
}
{
regAddr = 0x23;//FREQ_DIAG 寄存器
regData = 0x33;//0011 0011
字节 buf1[5]={0x55、0x0a、regAddr、regData、calcChecksum (0x0a)};
serial.write (buf1、sizeof (buf1));//无响应操作(寄存器写入)
}
{
regAddr = 0x25;//FVOLT_DEC 寄存器
regData = 0x1c;//0001 1100
字节 buf1[5]={0x55、0x0a、regAddr、regData、calcChecksum (0x0a)};
serial.write (buf1、sizeof (buf1));//无响应操作(寄存器写入)
}
{
regAddr = 0x1f;//PULSE_P2寄存器
regData = 0x10;//0001 0000
字节 buf1[5]={0x55、0x0a、regAddr、regData、calcChecksum (0x0a)};
serial.write (buf1、sizeof (buf1));//无响应操作(寄存器写入)
}
C = 0;
}
// 如果(m)
// {
// for (int l=0;l<6;l++)
// {
serial.flush();
延迟(10);
{
字节 buf2[4]={0x55、0x00、Numobjects、calcChecksum (0x00)};
serial.println ("\n 为预设1\n"\n 停止突发和监听命令);
serial.write (buf2、sizeof (buf2));//无响应操作(突发和监听(Preset1))
}
延迟(10);
serial.flush();
如果(m)
{
字节 sensorValue;
字节 buf4[2]={0x55、0x08};//、calcChecksum (0x08)};
serial.write (buf4、sizeof (buf4));//响应操作(除寄存器读取之外的所有操作)
//延迟(1);
for (int n=0;n<4;n++)
{
延迟(10);
如果(n = 1)
sensorValue = Serial.read();
其他
serial.read();
}
serial.println ("\n 为系统诊断命令读取响应帧的第二个字节\n");
serial.println (sensorValue);
M=0;
}
字节 sensorValue;
regAddr = 0x40;//输入 REGMAP 寄存器的任何地址以读取其值
字节 buf[4]={0x55、0x09、regAddr、calcChecksum (0x09)};
serial.write (buf、sizeof (buf));//响应操作(寄存器读取)
for (int n=0;n<3;n++)
{
延迟(10);
如果(n = 1)
sensorValue = Serial.read();
其他
serial.read();
}
serial.println ("\n 为寄存器读取命令读取响应帧的第二个字节\n");
serial.println (sensorValue);
// }
// m=0;
// }
}