mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
CHG: 'hw tune' tuning antenna now can handle bigger antennas than 65v, with shifting 9, it can measure up to 130v.
CHG: 'hw tune' - command output and layout changes. I think this is easier to read.
This commit is contained in:
parent
b578e55d17
commit
eed271af5c
2 changed files with 49 additions and 50 deletions
|
@ -165,12 +165,6 @@ void Dbhexdump(int len, uint8_t *d, bool bAsci) {
|
||||||
// return that.
|
// return that.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
static int ReadAdc(int ch) {
|
static int ReadAdc(int ch) {
|
||||||
uint32_t d;
|
|
||||||
|
|
||||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
|
|
||||||
AT91C_BASE_ADC->ADC_MR = ADC_MODE_PRESCALE(63 /* was 32 */) | // ADC_CLK = MCK / ((63+1) * 2) = 48MHz / 128 = 375kHz
|
|
||||||
ADC_MODE_STARTUP_TIME(1 /* was 16 */) | // Startup Time = (1+1) * 8 / ADC_CLK = 16 / 375kHz = 42,7us Note: must be > 20us
|
|
||||||
ADC_MODE_SAMPLE_HOLD_TIME(15 /* was 8 */); // Sample & Hold Time SHTIM = 15 / ADC_CLK = 15 / 375kHz = 40us
|
|
||||||
|
|
||||||
// Note: ADC_MODE_PRESCALE and ADC_MODE_SAMPLE_HOLD_TIME are set to the maximum allowed value.
|
// Note: ADC_MODE_PRESCALE and ADC_MODE_SAMPLE_HOLD_TIME are set to the maximum allowed value.
|
||||||
// Both AMPL_LO and AMPL_HI are very high impedance (10MOhm) outputs, the input capacitance of the ADC is 12pF (typical). This results in a time constant
|
// Both AMPL_LO and AMPL_HI are very high impedance (10MOhm) outputs, the input capacitance of the ADC is 12pF (typical). This results in a time constant
|
||||||
|
@ -183,19 +177,24 @@ static int ReadAdc(int ch) {
|
||||||
//
|
//
|
||||||
// Note: with the "historic" values in the comments above, the error was 34% !!!
|
// Note: with the "historic" values in the comments above, the error was 34% !!!
|
||||||
|
|
||||||
AT91C_BASE_ADC->ADC_CHER = ADC_CHANNEL(ch);
|
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
|
||||||
|
AT91C_BASE_ADC->ADC_MR =
|
||||||
|
ADC_MODE_PRESCALE(63) // [was 32] ADC_CLK = MCK / ((63+1) * 2) = 48MHz / 128 = 375kHz
|
||||||
|
| ADC_MODE_STARTUP_TIME(1) // [was 16] Startup Time = (1+1) * 8 / ADC_CLK = 16 / 375kHz = 42,7us Note: must be > 20us
|
||||||
|
| ADC_MODE_SAMPLE_HOLD_TIME(15); // [was 8] Sample & Hold Time SHTIM = 15 / ADC_CLK = 15 / 375kHz = 40us
|
||||||
|
|
||||||
|
AT91C_BASE_ADC->ADC_CHER = ADC_CHANNEL(ch);
|
||||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||||
|
|
||||||
while (!(AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ch))) {};
|
while (!(AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ch))) {};
|
||||||
|
|
||||||
d = AT91C_BASE_ADC->ADC_CDR[ch];
|
return AT91C_BASE_ADC->ADC_CDR[ch];
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// was static - merlok
|
// was static - merlok
|
||||||
int AvgAdc(int ch) {
|
int AvgAdc(int ch) {
|
||||||
int i, a = 0;
|
uint8_t i;
|
||||||
|
int a = 0;
|
||||||
for(i = 0; i < 32; i++)
|
for(i = 0; i < 32; i++)
|
||||||
a += ReadAdc(ch);
|
a += ReadAdc(ch);
|
||||||
|
|
||||||
|
@ -205,8 +204,8 @@ int AvgAdc(int ch) {
|
||||||
void MeasureAntennaTuning(void) {
|
void MeasureAntennaTuning(void) {
|
||||||
|
|
||||||
uint8_t LF_Results[256];
|
uint8_t LF_Results[256];
|
||||||
int i, adcval = 0, peak = 0, peakv = 0, peakf = 0;
|
uint32_t i, adcval = 0, peak = 0, peakv = 0, peakf = 0;
|
||||||
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
uint32_t vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
||||||
|
|
||||||
memset(LF_Results, 0, sizeof(LF_Results));
|
memset(LF_Results, 0, sizeof(LF_Results));
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
|
@ -234,7 +233,7 @@ void MeasureAntennaTuning(void) {
|
||||||
if (i == 89)
|
if (i == 89)
|
||||||
vLf134 = adcval; // voltage at 134Khz
|
vLf134 = adcval; // voltage at 134Khz
|
||||||
|
|
||||||
LF_Results[i] = adcval >> 8; // scale int to fit in byte for graphing purposes
|
LF_Results[i] = adcval >> 9; // scale int to fit in byte for graphing purposes
|
||||||
if(LF_Results[i] > peak) {
|
if(LF_Results[i] > peak) {
|
||||||
peakv = adcval;
|
peakv = adcval;
|
||||||
peak = LF_Results[i];
|
peak = LF_Results[i];
|
||||||
|
@ -255,7 +254,7 @@ void MeasureAntennaTuning(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeasureAntennaTuningHf(void) {
|
void MeasureAntennaTuningHf(void) {
|
||||||
int vHf = 0; // in mV
|
uint16_t vHf = 0; // in mV
|
||||||
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
|
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||||
|
@ -263,8 +262,7 @@ void MeasureAntennaTuningHf(void) {
|
||||||
while( !BUTTON_PRESS() ){
|
while( !BUTTON_PRESS() ){
|
||||||
SpinDelay(20);
|
SpinDelay(20);
|
||||||
vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
||||||
//Dbprintf("%d mV",vHf);
|
DbprintfEx(CMD_MEASURE_ANTENNA_TUNING_HF, "%u mV",vHf);
|
||||||
DbprintfEx(CMD_MEASURE_ANTENNA_TUNING_HF, "%d mV",vHf);
|
|
||||||
}
|
}
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
DbpString("cancelled");
|
DbpString("cancelled");
|
||||||
|
|
|
@ -1396,8 +1396,13 @@ int CmdSamples(const char *Cmd)
|
||||||
return getSamples(n, false);
|
return getSamples(n, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdTuneSamples(const char *Cmd)
|
int CmdTuneSamples(const char *Cmd) {
|
||||||
{
|
#define NON_VOLTAGE 999
|
||||||
|
#define LF_UNUSABLE_V 2948 // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
|
||||||
|
#define LF_MARGINAL_V 14739 // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
|
||||||
|
#define HF_UNUSABLE_V 3167 // was 2000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
||||||
|
#define HF_MARGINAL_V 7917 // was 5000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
||||||
|
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
printf("\n[+] measuring antenna characteristics, please wait...");
|
printf("\n[+] measuring antenna characteristics, please wait...");
|
||||||
|
|
||||||
|
@ -1414,45 +1419,41 @@ int CmdTuneSamples(const char *Cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NON_VOLTAGE 999
|
uint32_t vLf125 = resp.arg[0] & 0xffff;
|
||||||
#define LF_UNUSABLE_V 2948 // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
|
uint32_t vLf134 = resp.arg[0] >> 16;
|
||||||
#define LF_MARGINAL_V 14739 // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
|
|
||||||
#define HF_UNUSABLE_V 3167 // was 2000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
uint32_t vHf = resp.arg[1] & 0xffff;;
|
||||||
#define HF_MARGINAL_V 7917 // was 5000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
uint32_t peakf = resp.arg[2] & 0xffff;
|
||||||
|
uint32_t peakv = resp.arg[2] >> 16;
|
||||||
|
|
||||||
|
PrintAndLog("\n");
|
||||||
|
|
||||||
int peakv, peakf;
|
|
||||||
int vLf125, vLf134, vHf;
|
|
||||||
vLf125 = resp.arg[0] & 0xffff;
|
|
||||||
vLf134 = resp.arg[0] >> 16;
|
|
||||||
vHf = resp.arg[1] & 0xffff;;
|
|
||||||
peakf = resp.arg[2] & 0xffff;
|
|
||||||
peakv = resp.arg[2] >> 16;
|
|
||||||
PrintAndLog("");
|
|
||||||
if ( vLf125 > NON_VOLTAGE )
|
if ( vLf125 > NON_VOLTAGE )
|
||||||
PrintAndLog("[+] LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);
|
PrintAndLog("[+] LF antenna: %5.2f V - 125.00 kHz", vLf125/1000.0);
|
||||||
if ( vLf134 > NON_VOLTAGE )
|
if ( vLf134 > NON_VOLTAGE )
|
||||||
PrintAndLog("[+] LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0);
|
PrintAndLog("[+] LF antenna: %5.2f V - 134.00 kHz", vLf134/1000.0);
|
||||||
if ( peakv > NON_VOLTAGE && peakf > 0 )
|
if ( peakv > NON_VOLTAGE && peakf > 0 )
|
||||||
PrintAndLog("[+] LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
|
PrintAndLog("[+] LF optimal: %5.2f V - %6.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
|
||||||
|
|
||||||
|
// LF judgement
|
||||||
|
if (peakv < LF_UNUSABLE_V) PrintAndLog("[!] LF antenna is unusable");
|
||||||
|
else if (peakv < LF_MARGINAL_V) PrintAndLog("[!] LF antenna is marginal");
|
||||||
|
else PrintAndLog("[+] LF antenna is ok");
|
||||||
|
|
||||||
|
PrintAndLog("");
|
||||||
if ( vHf > NON_VOLTAGE )
|
if ( vHf > NON_VOLTAGE )
|
||||||
PrintAndLog("[+] HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
|
PrintAndLog("[+] HF antenna: %5.2f V - 13.56 MHz", vHf/1000.0);
|
||||||
|
|
||||||
|
// HF judgement
|
||||||
|
if (vHf < HF_UNUSABLE_V) PrintAndLog("[!] HF antenna is unusable");
|
||||||
if (peakv < LF_UNUSABLE_V)
|
else if (vHf < HF_MARGINAL_V) PrintAndLog("[!] HF antenna is marginal");
|
||||||
PrintAndLog("[!] Your LF antenna is unusable.");
|
else PrintAndLog("[+] HF antenna is ok");
|
||||||
else if (peakv < LF_MARGINAL_V)
|
|
||||||
PrintAndLog("[!] Your LF antenna is marginal.");
|
|
||||||
if (vHf < HF_UNUSABLE_V)
|
|
||||||
PrintAndLog("[!] Your HF antenna is unusable.");
|
|
||||||
else if (vHf < HF_MARGINAL_V)
|
|
||||||
PrintAndLog("[!] Your HF antenna is marginal.");
|
|
||||||
|
|
||||||
if (peakv >= LF_UNUSABLE_V) {
|
if (peakv >= LF_UNUSABLE_V) {
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
GraphBuffer[i] = resp.d.asBytes[i] - 128;
|
GraphBuffer[i] = resp.d.asBytes[i] - 128;
|
||||||
}
|
}
|
||||||
PrintAndLog("[+] Displaying LF tuning graph. Divisor 89 is 134khz, 95 is 125khz.\n\n");
|
PrintAndLog("\n[+] Displaying LF tuning graph. Divisor 89 is 134khz, 95 is 125khz.\n\n");
|
||||||
GraphTraceLen = 256;
|
GraphTraceLen = 256;
|
||||||
ShowGraphWindow();
|
ShowGraphWindow();
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue