Rework FM modulation and UI crash

pull/5/head
erikkaashoek 5 years ago
parent 10982ac23c
commit e0ab998ffd

@ -867,8 +867,8 @@ config_t config = {
.correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 },
.correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, .correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 },
.cor_am = -14, .cor_am = -14,
.cor_wfm = -21, .cor_wfm = -17,
.cor_nfm = -23, .cor_nfm = -17,
}; };
//properties_t current_props; //properties_t current_props;

@ -1483,10 +1483,23 @@ static int modulation_counter = 0;
#define MODULATION_STEPS 8 #define MODULATION_STEPS 8
static const int am_modulation[MODULATION_STEPS] = { 5, 1, 0, 1, 5, 9, 11, 9 }; // AM modulation static const int am_modulation[MODULATION_STEPS] = { 5, 1, 0, 1, 5, 9, 11, 9 }; // AM modulation
#define ND 12 //
//static const int nfm_modulation[MODULATION_STEPS] = { 2*ND, 3*ND, 4*ND, 3*ND, 2*ND, ND, 0, ND}; // narrow FM modulation avoid sign changes // Offset is 156.25Hz when below 600MHz and 312.5 when above.
static const int nfm_modulation[MODULATION_STEPS] = { 2*ND,(int)( 3.5*ND ), 4*ND, (int)(3.5*ND), 2*ND, (int)(0.5*ND), 0, (int)(0.5*ND)}; // narrow FM modulation avoid sign changes //
static const int wfm_modulation[MODULATION_STEPS] = { 0, 140, 190, 140, 0, -140, -190, -140 }; // wide FM modulation #define LND 16 // Total NFM deviation is LND * 4 * 156.25 = 5kHz when below 600MHz or 600MHz - 434MHz
#define HND 8
#define LWD 96 // Total WFM deviation is LWD * 4 * 156.25 = 30kHz when below 600MHz
#define HWD 48
static const int fm_modulation[4][MODULATION_STEPS] = // Avoid sign changes in NFM
{
{ 2*LND,(int)( 3.5*LND ), 4*LND, (int)(3.5*LND), 2*LND, (int)(0.5*LND), 0, (int)(0.5*LND)},
{ 0*LWD,(int)( 1.5*LWD ), 2*LWD, (int)(1.5*LWD), 0*LWD, (int)(-1.5*LWD), (int)-2*LWD, (int)(-1.5*LWD)},
{ 2*HND,(int)( 3.5*HND ), 4*HND, (int)(3.5*HND), 2*HND, (int)(0.5*HND), 0, (int)(0.5*HND)},
{ 0*HWD,(int)( 1.5*HWD ), 2*HWD, (int)(1.5*HWD), 0*HWD, (int)(-1.5*HWD), (int)-2*HWD, (int)(-1.5*HWD)},
}; // narrow FM modulation avoid sign changes
static const int fm_modulation_offset[4] = { LND*625/2, 0, LND*625/2, 0};
deviceRSSI_t age[POINTS_COUNT]; // Array used for 1: calculating the age of any max and 2: buffer for fast sweep RSSI values; deviceRSSI_t age[POINTS_COUNT]; // Array used for 1: calculating the age of any max and 2: buffer for fast sweep RSSI values;
@ -1499,6 +1512,7 @@ static systime_t sweep_elapsed = 0; // Time since fi
pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
{ {
int modulation_delay = 0; int modulation_delay = 0;
int modulation_index = 0;
if (i == 0 && dirty ) { // if first point in scan and dirty if (i == 0 && dirty ) { // if first point in scan and dirty
calculate_correction(); // pre-calculate correction factor dividers to avoid float division calculate_correction(); // pre-calculate correction factor dividers to avoid float division
apply_settings(); // Initialize HW apply_settings(); // Initialize HW
@ -1605,16 +1619,27 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking)
if (i == 0 || setting.frequency_step != 0) if (i == 0 || setting.frequency_step != 0)
correct_RSSI_freq = get_frequency_correction(f); correct_RSSI_freq = get_frequency_correction(f);
} }
int *current_fm_modulation;
if (MODE_OUTPUT(setting.mode)) { if (MODE_OUTPUT(setting.mode)) {
if (setting.modulation != MO_NONE && setting.modulation != MO_EXTERNAL && setting.modulation_frequency != 0) { if (setting.modulation != MO_NONE && setting.modulation != MO_EXTERNAL && setting.modulation_frequency != 0) {
modulation_delay = (1000000/ MODULATION_STEPS ) / setting.modulation_frequency; // 5 steps so 1MHz/5 modulation_delay = (1000000/ MODULATION_STEPS ) / setting.modulation_frequency; // 5 steps so 1MHz/5
modulation_counter = 0; modulation_counter = 0;
if (setting.modulation == MO_AM) // -14 default if (setting.modulation == MO_AM) // -14 default
modulation_delay += config.cor_am; modulation_delay += config.cor_am;
if (setting.modulation == MO_WFM) // -21 default else { // must be FM
if (setting.modulation == MO_WFM) { // -17 default
modulation_delay += config.cor_wfm; modulation_delay += config.cor_wfm;
if (setting.modulation == MO_NFM) // -23 default modulation_index = 1;
modulation_delay += config.cor_nfm; } else { // must be NFM
modulation_delay += config.cor_nfm; // -17 default
// modulation_index = 0; // default value
}
if ((setting.mode == M_GENLOW && f > 480000000 - 433000000) ||
(setting.mode == M_GENHIGH && f > 480000000) )
modulation_index += 2;
current_fm_modulation = (int *)fm_modulation[modulation_index];
f -= fm_modulation_offset[modulation_index]; // Shift output frequency
}
} }
} }
modulation_again: modulation_again:
@ -1631,9 +1656,9 @@ modulation_again:
else if (setting.modulation == MO_NFM || setting.modulation == MO_WFM ) { //FM modulation else if (setting.modulation == MO_NFM || setting.modulation == MO_WFM ) { //FM modulation
#ifdef __SI4432__ #ifdef __SI4432__
SI4432_Sel = SI4432_LO ; SI4432_Sel = SI4432_LO ;
int offset = setting.modulation == MO_NFM ? nfm_modulation[modulation_counter] : wfm_modulation[modulation_counter] ; int offset = current_fm_modulation[modulation_counter];
SI4432_Write_Byte(SI4432_FREQ_OFFSET1, (offset & 0xff )); // Use frequency hopping channel for FM modulation SI4432_Write_2_Byte(SI4432_FREQ_OFFSET1, (offset & 0xff ), ((offset >> 8) & 0x03 )); // Use frequency hopping channel for FM modulation
SI4432_Write_Byte(SI4432_FREQ_OFFSET2, ((offset >> 8) & 0x03 )); // Use frequency hopping channel for FM modulation // SI4432_Write_Byte(SI4432_FREQ_OFFSET2, ); // Use frequency hopping channel for FM modulation
#endif #endif
} }
modulation_counter++; modulation_counter++;

@ -158,6 +158,22 @@ void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA )
// SI4432_guard = 0; // SI4432_guard = 0;
} }
void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2)
{
// if (SI4432_guard)
// while(1) ;
// SI4432_guard = 1;
// SPI2_CLK_LOW;
palClearPad(GPIOC, SI_nSEL[SI4432_Sel]);
// chThdSleepMicroseconds(SELECT_DELAY);
ADR |= 0x80 ; // RW = 1
shiftOut( ADR );
shiftOut( DATA1 );
shiftOut( DATA2 );
palSetPad(GPIOC, SI_nSEL[SI4432_Sel]);
// SI4432_guard = 0;
}
void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA3 ) void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA3 )
{ {
// if (SI4432_guard) // if (SI4432_guard)

@ -114,6 +114,7 @@ extern int SI4432_frequency_changed;
extern int SI4432_offset_changed; extern int SI4432_offset_changed;
void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA ); void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA );
void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2);
uint8_t SI4432_Read_Byte( uint8_t ADR ); uint8_t SI4432_Read_Byte( uint8_t ADR );
void SI4432_Transmit(int d); void SI4432_Transmit(int d);

@ -190,8 +190,11 @@ static int btn_wait_release(void)
uint16_t changed = last_button ^ cur_button; uint16_t changed = last_button ^ cur_button;
if (dt >= BUTTON_DOWN_LONG_TICKS && (cur_button & (1<<BIT_PUSH))) if (dt >= BUTTON_DOWN_LONG_TICKS && (cur_button & (1<<BIT_PUSH)))
return EVT_BUTTON_DOWN_LONG; return EVT_BUTTON_DOWN_LONG;
else if (changed & (1<<BIT_PUSH)) // release else if (changed & (1<<BIT_PUSH)) { // release
last_button = cur_button;
last_button_down_ticks = ticks;
return EVT_BUTTON_SINGLE_CLICK; return EVT_BUTTON_SINGLE_CLICK;
}
if (changed) { if (changed) {
// finished // finished
last_button = cur_button; last_button = cur_button;
@ -2229,7 +2232,7 @@ ui_process_menu(void)
const menuitem_t *menu = menu_stack[menu_current_level]; const menuitem_t *menu = menu_stack[menu_current_level];
int status = btn_check(); int status = btn_check();
if (status != 0) { if (status != 0) {
if (status & EVT_BUTTON_SINGLE_CLICK) { if (selection >=0 && status & EVT_BUTTON_SINGLE_CLICK) {
menu_invoke(selection); menu_invoke(selection);
} else { } else {
do { do {
@ -2245,7 +2248,7 @@ ui_process_menu(void)
} }
if (status & EVT_DOWN) { if (status & EVT_DOWN) {
// skip menu item if disabled // skip menu item if disabled
while (menuDisabled(menu[selection-1].type)) while (selection > 0 && menuDisabled(menu[selection-1].type))
selection--; selection--;
// close menu if item is 0, else step down // close menu if item is 0, else step down
if (selection > 0) if (selection > 0)

@ -1604,7 +1604,7 @@ static const menuitem_t menu_settings3[] =
{ {
{ MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual l0MHz frequency"}, { MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual l0MHz frequency"},
{ MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"},
{ MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"}, // { MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"},
{ MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"}, { MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"},
{ MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"}, { MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"},
#ifdef __HAM_BAND__ #ifdef __HAM_BAND__

Loading…
Cancel
Save

Powered by TurnKey Linux.