145 lines
4.4 KiB
C
145 lines
4.4 KiB
C
|
|
/*
|
||
|
|
* frq.h
|
||
|
|
*
|
||
|
|
* Created on: Jun 8, 2022
|
||
|
|
* Author: Keith.Lloyd
|
||
|
|
*/
|
||
|
|
|
||
|
|
#ifndef FRQ_H_
|
||
|
|
#define FRQ_H_
|
||
|
|
|
||
|
|
#include "spi.h"
|
||
|
|
|
||
|
|
typedef enum {
|
||
|
|
NULL_FREQ,
|
||
|
|
SINGLE,
|
||
|
|
DUAL
|
||
|
|
}FRQ_OUT_SELECT_t;
|
||
|
|
|
||
|
|
|
||
|
|
#define TX_SYS_CLK 12000000 // 12MHZ
|
||
|
|
#define DDS_CLK TX_SYS_CLK
|
||
|
|
|
||
|
|
|
||
|
|
#define FREQ_MAX_NUM 50 //Max number of frequencies allowed
|
||
|
|
#define FREQ_MIN 0
|
||
|
|
#define FREQ0_REG 0x4000 // Address of internal 9838 register
|
||
|
|
#define FRQ_CTRL_WORD1 0x2100 // Control register with Reset bit active
|
||
|
|
#define FRQ_CTRL_WORD2 0x2000 // Exit Reset Control Word
|
||
|
|
//#define FRQ_CTRL_WORD2 0x2038 // Exit Reset Control Word for PLL Test
|
||
|
|
#define PHASE_RESET 0xC000 // PHASE Register 0 = 0;
|
||
|
|
|
||
|
|
#define RAMP_CTRL_WORD1 0x2102
|
||
|
|
#define RAMP_CTRL_WORD2 0x2002
|
||
|
|
#define RAMP_CTRL_WORD3 0x2002 // TODO Places wavegen in sleep mode
|
||
|
|
#define SLP_CTRL_WRD 0x2180 // Power down unused DDS
|
||
|
|
#define SLP_CTRL_WRD2 0x21C0
|
||
|
|
#define RAMP_PORT 1
|
||
|
|
//#define RAMP_RST_GPIO_PIN 14
|
||
|
|
#define HI 1
|
||
|
|
#define BCAST_MIN 3140
|
||
|
|
#define BCAST_MAX 200000
|
||
|
|
#define DUMMY_FRQ 250
|
||
|
|
#define MIN_BLOCK_FREQ 20000
|
||
|
|
#define MASK_15 0b00000000
|
||
|
|
#define MASK_58 0b00001000
|
||
|
|
#define MASK_144 0b00011000
|
||
|
|
#define CLK_MASK_BITS 0b11100111
|
||
|
|
#define MAX_LD_FREQ 10000
|
||
|
|
|
||
|
|
//FREQUENCY PACKING - from RX so it has extra fields
|
||
|
|
#define FREQ_PACK_MASK_FREQ 0x0007ffff //target frequency bits 0 - 18
|
||
|
|
#define FREQ_PACK_MASK_TYPE 0x00380000 //3-bit field for FREQ_TYPE_t. bits 19 - 21
|
||
|
|
#define FREQ_PACK_SHIFT_TYPE 19 //Frequency type shift
|
||
|
|
#define FREQ_PACK_MASK_ENABLED 0x80000000 //enabled mask
|
||
|
|
#define FREQ_PACK_SHIFT_ENABLED 31 //enabled shift bit 31
|
||
|
|
#define FREQ_PACK_MASK_INMENU 0x40000000 //inMenu mask
|
||
|
|
#define FREQ_PACK_SHIFT_INMENU 30 //inMenu shift bit 30
|
||
|
|
|
||
|
|
//Locate direction (LD)
|
||
|
|
#define FREQ_LD_MAX_FREQUENCY 10000 //LD runs at or below this frequency
|
||
|
|
#define FREQ_LD_SWITCH_POINT 1500 //At or below this freq, f2 is f1 * 2. above this f2 = f1 / 2
|
||
|
|
|
||
|
|
#define MIN_CTYPE 263 // Minimum clamp frequency.
|
||
|
|
|
||
|
|
|
||
|
|
typedef enum {
|
||
|
|
FT_ACTIVE, //active
|
||
|
|
FT_LD_ACTIVE, //active w/ Locate Direction
|
||
|
|
FT_POWER, //RX ONLY individual power
|
||
|
|
FT_GROUPED_POWER, //RX ONLY Radio style grouped power
|
||
|
|
FT_CATHODIC, //RX ONLY cathodic protection - Identical to individual power except naming in frequency menu
|
||
|
|
FT_SONDE, //RX ONLY
|
||
|
|
FT_RADIO, //RX ONLY
|
||
|
|
FT_FAULT_FIND, //RX ONLY fault finder - Has it's own dedicated frequency set. frequencies are NOT user definable
|
||
|
|
}FREQ_TYPE_t;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//Data for individual frequencies
|
||
|
|
typedef struct {
|
||
|
|
uint32_t frequency1; //frequency in Hz
|
||
|
|
uint32_t frequency2;
|
||
|
|
uint8_t enabled; //
|
||
|
|
uint8_t bc_enabled;
|
||
|
|
uint8_t bc_Mask;
|
||
|
|
uint8_t max_pot;
|
||
|
|
float i_coeff_lo;
|
||
|
|
float i_coeff_hi;
|
||
|
|
float v_coeff_lo;
|
||
|
|
float v_coeff_hi;
|
||
|
|
|
||
|
|
}FREQUENCY_t;
|
||
|
|
|
||
|
|
|
||
|
|
//General data for frequencies module
|
||
|
|
typedef struct {
|
||
|
|
uint32_t numFrequencies; //number of frequencies in freqArray
|
||
|
|
}FREQDATA_t;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
void FREQ_Init(void);
|
||
|
|
void FREQ_LoadFactoryDefaults(void);
|
||
|
|
uint32_t FREQ_GetPackedFrequency(uint32_t index);
|
||
|
|
void FREQ_AddPackedFrequency(uint32_t packedFreq);
|
||
|
|
void FREQ_ClearFrequencies(void);
|
||
|
|
void FREQ_AddFrequency(uint32_t f1, uint8_t enabledTemp, uint8_t inMenu, FREQ_TYPE_t type);
|
||
|
|
void Load_Ramp(uint32_t ramp_freq);
|
||
|
|
void Load_Frq_Gen(FRQ_OUT_SELECT_t, int32_t, int32_t); // NONE,either or both plus two data words
|
||
|
|
//void AddFrequency(uint32_t frequency, uint32_t frequency2, uint8_t enabled, uint8_t bc_enabled, uint8_t bc_mask);
|
||
|
|
uint8_t Next_Frequency(uint8_t frequency);
|
||
|
|
void FREQ_ToggleEnable(uint32_t selected);
|
||
|
|
FREQUENCY_t FREQ_GetFreqByIndex(uint32_t index);
|
||
|
|
uint32_t FREQ_GetNumFrequencies(void);
|
||
|
|
void FREQ_GetFrequencyName(uint32_t index, uint8_t *string);
|
||
|
|
void Send_Ctrl_Word(uint16_t Control_Reg, SPI_MODE_t mode);
|
||
|
|
uint32_t Calc_Freq(uint32_t fout); // Calculate frequency word for DDS
|
||
|
|
void Update_Min_Frequency(void);
|
||
|
|
void Update_Frequency();
|
||
|
|
void Reset_DDS(void);
|
||
|
|
void AddFrequency(uint32_t frequency1,uint32_t frequency2, uint8_t enabled, uint8_t bc_enabled,uint8_t bc_mask,uint8_t pot,float i_lo,float i_hi,float v_lo,float v_hi);
|
||
|
|
bool Check_freq_enabled(uint8_t frq_tmp);
|
||
|
|
uint8_t BC_Enable_Chk(uint32_t f1);
|
||
|
|
uint8_t BC_Mask_Chk(uint32_t f1);
|
||
|
|
uint8_t Max_Pot_Chk(uint32_t f1);
|
||
|
|
float V_coeff_lo_Chk(uint32_t f1);
|
||
|
|
float V_coeff_hi_Chk(uint32_t f1);
|
||
|
|
float I_coeff_lo_Chk(uint32_t f1);
|
||
|
|
float I_coeff_hi_Chk(uint32_t f1);
|
||
|
|
uint8_t Search_for_frq(uint32_t f1);
|
||
|
|
void Change_to_next_dc_frq(void);
|
||
|
|
void Change_To_Next_BC_Freq(void);
|
||
|
|
void Set_Selected_Freq(void);
|
||
|
|
|
||
|
|
extern FREQUENCY_t freqArray[];
|
||
|
|
|
||
|
|
|
||
|
|
#endif /* FRQ_H_ */
|