lf: change macros to allow float freq, change 134 -> 134.2

This commit is contained in:
Philippe Teuwen 2019-10-25 00:42:47 +02:00
commit eb7268cd98
5 changed files with 15 additions and 14 deletions

View file

@ -2418,7 +2418,7 @@ because of this, we can "sample" the data signal but we interpreate it to Manche
This behavior looks very similar to old ancient Motorola Flexpass This behavior looks very similar to old ancient Motorola Flexpass
----------------------------------------------------------------------- -----------------------------------------------------------------------
According to patent: According to patent EP0040544B1:
Operating freq Operating freq
reader 132 kHz reader 132 kHz
tag 66 kHz tag 66 kHz
@ -2453,7 +2453,7 @@ void Cotag(uint32_t arg0) {
LED_A_ON(); LED_A_ON();
LFSetupFPGAForADC(LF_DIVISOR(132), true); LFSetupFPGAForADC(LF_FREQ2DIV(132), true);
//clear buffer now so it does not interfere with timing later //clear buffer now so it does not interfere with timing later
BigBuf_Clear_ext(false); BigBuf_Clear_ext(false);

View file

@ -1676,16 +1676,16 @@ int CmdTuneSamples(const char *Cmd) {
struct p *package = (struct p *)resp.data.asBytes; struct p *package = (struct p *)resp.data.asBytes;
if (package->v_lf125 > NON_VOLTAGE) if (package->v_lf125 > NON_VOLTAGE)
PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf125 * ANTENNA_ERROR) / 1000.0, 12000.0 / (LF_DIVISOR_125 + 1)); PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf125 * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(LF_DIVISOR_125));
if (package->v_lf134 > NON_VOLTAGE) if (package->v_lf134 > NON_VOLTAGE)
PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf134 * ANTENNA_ERROR) / 1000.0, 12000.0 / (LF_DIVISOR_134 + 1)); PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lf134 * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(LF_DIVISOR_134));
if (package->v_lfconf > NON_VOLTAGE && package->divisor > 0 && package->divisor != LF_DIVISOR_125 && package->divisor != LF_DIVISOR_134) 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 + 1)); PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - %.2f kHz", (package->v_lfconf * ANTENNA_ERROR) / 1000.0, LF_DIV2FREQ(package->divisor));
if (package->peak_v > NON_VOLTAGE && package->peak_f > 0) 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, LF_DIV2FREQ(package->peak_f));
char judgement[20]; char judgement[20];
memset(judgement, 0, sizeof(judgement)); memset(judgement, 0, sizeof(judgement));
@ -1730,7 +1730,7 @@ int CmdTuneSamples(const char *Cmd) {
if (test1 > 0) { if (test1 > 0) {
PrintAndLogEx(SUCCESS, "\nDisplaying LF tuning graph. Divisor %d is %.2f kHz, %d is %.2f kHz.\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 + 1), LF_DIVISOR_125, 12000.0 / (LF_DIVISOR_125 + 1)); LF_DIVISOR_134, LF_DIV2FREQ(LF_DIVISOR_134), LF_DIVISOR_125, LF_DIV2FREQ(LF_DIVISOR_125));
GraphTraceLen = 256; GraphTraceLen = 256;
ShowGraphWindow(); ShowGraphWindow();
RepaintGraphWindow(); RepaintGraphWindow();

View file

@ -232,7 +232,7 @@ int CmdLFTune(const char *Cmd) {
break; break;
case 'f': { case 'f': {
int freq = param_get32ex(Cmd, cmdp + 1, 125, 10); int freq = param_get32ex(Cmd, cmdp + 1, 125, 10);
divisor = LF_DIVISOR(freq); divisor = LF_FREQ2DIV(freq);
if (divisor < 19) { if (divisor < 19) {
PrintAndLogEx(ERR, "freq must be between 47 and 600"); PrintAndLogEx(ERR, "freq must be between 47 and 600");
return PM3_EINVARG; return PM3_EINVARG;
@ -254,7 +254,7 @@ int CmdLFTune(const char *Cmd) {
//Validations //Validations
if (errors) return usage_lf_tune(); if (errors) return usage_lf_tune();
PrintAndLogEx(SUCCESS, "Measuring LF antenna at %.2f kHz, click button or press Enter to exit", 12000.0 / (divisor + 1)); PrintAndLogEx(SUCCESS, "Measuring LF antenna at %.2f kHz, click button or press Enter to exit", LF_DIV2FREQ(divisor));
uint8_t params[] = {1, 0}; uint8_t params[] = {1, 0};
params[1] = divisor; params[1] = divisor;
@ -498,7 +498,7 @@ int CmdLFConfig(const char *Cmd) {
break; break;
case 'f': { case 'f': {
int freq = param_get32ex(Cmd, cmdp + 1, 125, 10); int freq = param_get32ex(Cmd, cmdp + 1, 125, 10);
divisor = LF_DIVISOR(freq); divisor = LF_FREQ2DIV(freq);
if (divisor < 19) { if (divisor < 19) {
PrintAndLogEx(ERR, "freq must be between 47 and 600"); PrintAndLogEx(ERR, "freq must be between 47 and 600");
return PM3_EINVARG; return PM3_EINVARG;

View file

@ -127,7 +127,7 @@ static int CmdMotorolaRead(const char *Cmd) {
.decimation = 0, .decimation = 0,
.bits_per_sample = 0, .bits_per_sample = 0,
.averaging = false, .averaging = false,
.divisor = LF_DIVISOR(74), .divisor = LF_FREQ2DIV(74),
.trigger_threshold = -1, .trigger_threshold = -1,
.samples_to_skip = 4500, .samples_to_skip = 4500,
.verbose = false .verbose = false

View file

@ -590,9 +590,10 @@ typedef struct {
#define PM3_EFATAL -99 #define PM3_EFATAL -99
// LF // LF
#define LF_DIVISOR(f) (((12000 + (f)/2)/(f))-1) #define LF_FREQ2DIV(f) ((int)(((12000.0 + (f)/2.0)/(f))-1))
#define LF_DIVISOR_125 LF_DIVISOR(125) #define LF_DIVISOR_125 LF_FREQ2DIV(125)
#define LF_DIVISOR_134 LF_DIVISOR(134) #define LF_DIVISOR_134 LF_FREQ2DIV(134.2)
#define LF_DIV2FREQ(d) (12000.0/((d)+1))
// Receiving from USART need more than 30ms as we used on USB // Receiving from USART need more than 30ms as we used on USB
// else we get errors about partial packet reception // else we get errors about partial packet reception