mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -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.
|
||||
//-----------------------------------------------------------------------------
|
||||
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.
|
||||
// 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
|
||||
|
@ -182,20 +176,25 @@ static int ReadAdc(int ch) {
|
|||
// v_cap = v_in * (1 - exp(-RC/SHTIM)) = v_in * (1 - exp(-3)) = v_in * 0,95 (i.e. an error of 5%)
|
||||
//
|
||||
// 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;
|
||||
|
||||
while (!(AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ch))) {};
|
||||
|
||||
d = AT91C_BASE_ADC->ADC_CDR[ch];
|
||||
return d;
|
||||
|
||||
return AT91C_BASE_ADC->ADC_CDR[ch];
|
||||
}
|
||||
|
||||
// was static - merlok
|
||||
int AvgAdc(int ch) {
|
||||
int i, a = 0;
|
||||
uint8_t i;
|
||||
int a = 0;
|
||||
for(i = 0; i < 32; i++)
|
||||
a += ReadAdc(ch);
|
||||
|
||||
|
@ -205,8 +204,8 @@ int AvgAdc(int ch) {
|
|||
void MeasureAntennaTuning(void) {
|
||||
|
||||
uint8_t LF_Results[256];
|
||||
int i, adcval = 0, peak = 0, peakv = 0, peakf = 0;
|
||||
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
||||
uint32_t i, adcval = 0, peak = 0, peakv = 0, peakf = 0;
|
||||
uint32_t vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
||||
|
||||
memset(LF_Results, 0, sizeof(LF_Results));
|
||||
LED_B_ON();
|
||||
|
@ -234,7 +233,7 @@ void MeasureAntennaTuning(void) {
|
|||
if (i == 89)
|
||||
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) {
|
||||
peakv = adcval;
|
||||
peak = LF_Results[i];
|
||||
|
@ -255,16 +254,15 @@ void MeasureAntennaTuning(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.
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
|
||||
while ( !BUTTON_PRESS() ){
|
||||
while( !BUTTON_PRESS() ){
|
||||
SpinDelay(20);
|
||||
vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
||||
//Dbprintf("%d mV",vHf);
|
||||
DbprintfEx(CMD_MEASURE_ANTENNA_TUNING_HF, "%d mV",vHf);
|
||||
DbprintfEx(CMD_MEASURE_ANTENNA_TUNING_HF, "%u mV",vHf);
|
||||
}
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
DbpString("cancelled");
|
||||
|
|
|
@ -1396,8 +1396,13 @@ int CmdSamples(const char *Cmd)
|
|||
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;
|
||||
printf("\n[+] measuring antenna characteristics, please wait...");
|
||||
|
||||
|
@ -1414,45 +1419,41 @@ 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 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("");
|
||||
uint32_t vLf125 = resp.arg[0] & 0xffff;
|
||||
uint32_t vLf134 = resp.arg[0] >> 16;
|
||||
|
||||
uint32_t vHf = resp.arg[1] & 0xffff;;
|
||||
uint32_t peakf = resp.arg[2] & 0xffff;
|
||||
uint32_t peakv = resp.arg[2] >> 16;
|
||||
|
||||
PrintAndLog("\n");
|
||||
|
||||
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 )
|
||||
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 )
|
||||
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 )
|
||||
PrintAndLog("[+] HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
|
||||
PrintAndLog("[+] HF antenna: %5.2f V - 13.56 MHz", vHf/1000.0);
|
||||
|
||||
|
||||
|
||||
if (peakv < LF_UNUSABLE_V)
|
||||
PrintAndLog("[!] Your LF antenna is unusable.");
|
||||
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.");
|
||||
// HF judgement
|
||||
if (vHf < HF_UNUSABLE_V) PrintAndLog("[!] HF antenna is unusable");
|
||||
else if (vHf < HF_MARGINAL_V) PrintAndLog("[!] HF antenna is marginal");
|
||||
else PrintAndLog("[+] HF antenna is ok");
|
||||
|
||||
if (peakv >= LF_UNUSABLE_V) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
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;
|
||||
ShowGraphWindow();
|
||||
RepaintGraphWindow();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue