From f29ad0fba29ada6d6f42886ff2dccd7d5e26b79c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 3 Oct 2019 18:25:21 +0200 Subject: [PATCH] macros for divisors and fix lf optimal freq display --- armsrc/appmain.c | 4 ++-- armsrc/lfsampling.c | 2 +- client/cmddata.c | 13 +++++++------ include/pm3_cmd.h | 5 +++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index b67788bc5..af90060d5 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -182,10 +182,10 @@ void MeasureAntennaTuning(void) { FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i); SpinDelay(20); uint32_t adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10); - if (i == 96) + if (i == LF_DIVISOR_125) payload.v_lf125 = adcval; // voltage at 125kHz - if (i == 89) + if (i == LF_DIVISOR_134) payload.v_lf134 = adcval; // voltage at 134kHz if (i == sc->divisor) diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 75cab1e7f..993418360 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -24,7 +24,7 @@ Default LF config is set to: divisor = 95 (125kHz) trigger_threshold = 0 */ -sample_config config = { 1, 8, 1, 96, 0, 0 } ; +sample_config config = { 1, 8, 1, LF_DIVISOR_125, 0, 0 } ; void printConfig() { uint32_t d = config.divisor; diff --git a/client/cmddata.c b/client/cmddata.c index 5397570dd..1e9d7855e 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1676,16 +1676,16 @@ int CmdTuneSamples(const char *Cmd) { struct p* package = (struct p*)resp.data.asBytes; if (package->v_lf125 > NON_VOLTAGE) - PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - 125.00 kHz", (package->v_lf125 * ANTENNA_ERROR) / 1000.0); + PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf125 * ANTENNA_ERROR) / 1000.0, 12000.0 / LF_DIVISOR_125); if (package->v_lf134 > NON_VOLTAGE) - PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - 134.00 kHz", (package->v_lf134 * ANTENNA_ERROR) / 1000.0); + PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf134 * ANTENNA_ERROR) / 1000.0, 12000.0 / LF_DIVISOR_134); - if (package->v_lfconf > NON_VOLTAGE && package->divisor > 0) - PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lfconf * ANTENNA_ERROR) / 1000.0, (12000.0 / package->divisor)); + if (package->v_lfconf > NON_VOLTAGE && package->divisor > 0 && package->divisor != LF_DIVISOR_125 && package->divisor != LF_DIVISOR_134) + PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lfconf * ANTENNA_ERROR) / 1000.0, 12000.0 / package->divisor); if (package->peak_v > NON_VOLTAGE && package->peak_f > 0) - PrintAndLogEx(SUCCESS, "LF optimal: %5.2f V - %6.2f kHz", (package->peak_v * ANTENNA_ERROR) / 1000.0, 12000.0 / (package->peak_f + 1)); + PrintAndLogEx(SUCCESS, "LF optimal: %5.2f V - %6.2f kHz", (package->peak_v * ANTENNA_ERROR) / 1000.0, 12000.0 / package->peak_f); char judgement[20]; memset(judgement, 0, sizeof(judgement)); @@ -1729,7 +1729,8 @@ int CmdTuneSamples(const char *Cmd) { } if (test1 > 0) { - PrintAndLogEx(SUCCESS, "\nDisplaying LF tuning graph. Divisor 89 is 134kHz, 96 is 125kHz.\n\n"); + PrintAndLogEx(SUCCESS, "\nDisplaying LF tuning graph. Divisor %d is %.2f kHz, %d is %.2f kHz.\n\n", + LF_DIVISOR_134, 12000.0 / LF_DIVISOR_134, LF_DIVISOR_125, 12000.0 / LF_DIVISOR_125); GraphTraceLen = 256; ShowGraphWindow(); RepaintGraphWindow(); diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 010e46728..ed2a4585c 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -578,6 +578,11 @@ typedef struct { // Quit program client: reserved, order to quit the program #define PM3_EFATAL -99 +// LF +//#define LF_DIVISOR(f) ((12000 + (f)/2)/(f)) +//Note that 90 = 133.33 is closer to 134 than 89 = 134.83 +#define LF_DIVISOR_125 96 +#define LF_DIVISOR_134 89 // Receiving from USART need more than 30ms as we used on USB // else we get errors about partial packet reception