Skip to content

Commit

Permalink
Add console command 'time ppm value'
Browse files Browse the repository at this point in the history
More simple ppm conversion
  • Loading branch information
DiSlord committed Apr 7, 2024
1 parent 8b066c3 commit e623734
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
14 changes: 6 additions & 8 deletions NANOVNA_STM32_F072/rtc_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ void rtc_init(void){
// If calendar has not been initialized yet then proceed with the initial setup.
if ((RTC->ISR & RTC_ISR_INITS) == 0 || RTC->PRER != rtc_prer) {
if (rtc_enter_init()){
RTC->CR &= ~RTC_CR_COE;
RTC->CR = 0
// | RTC_CR_COSEL // RTC output 1Hz (or 512Hz if disabled)
;
RTC->ISR = RTC_ISR_INIT; // Clearing all but RTC_ISR_INIT.
RTC->PRER = rtc_prer; // Prescaler value loaded in registers 2 times
RTC->PRER = rtc_prer;
Expand All @@ -162,14 +164,10 @@ void rtc_init(void){
}

void rtc_set_cal(float ppm) {
ppm*= (1<<20) / 1000000.0f;
int32_t cal = ppm > 0 ? ppm + 0.5f : ppm - 0.5f;
if ((RTC->ISR & RTC_ISR_RECALPF) != 0 || cal < -511 || cal > 512)
int32_t cal = ppm * (1<<20) / 1000000.0f + 511.5f;
if ((RTC->ISR & RTC_ISR_RECALPF) || (uint32_t)cal > 1024)
return;
if (cal > 0)
RTC->CALR = RTC_CALR_CALP | (512 - cal);
else
RTC->CALR = -cal;
RTC->CALR = (511 - cal) & (RTC_CALR_CALP | RTC_CALR_CALM);
}

float rtc_get_cal(void) {
Expand Down
14 changes: 6 additions & 8 deletions NANOVNA_STM32_F303/rtc_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ void rtc_init(void){
// If calendar has not been initialized yet then proceed with the initial setup.
if ((RTC->ISR & RTC_ISR_INITS) == 0 || RTC->PRER != rtc_prer) {
if (rtc_enter_init()){
RTC->CR &= ~RTC_CR_COE;
RTC->CR = 0
// | RTC_CR_COSEL // RTC output 1Hz (or 512Hz if disabled)
;
RTC->ISR = RTC_ISR_INIT; // Clearing all but RTC_ISR_INIT.
RTC->PRER = rtc_prer; // Prescaler value loaded in registers 2 times
RTC->PRER = rtc_prer;
Expand All @@ -162,14 +164,10 @@ void rtc_init(void){
}

void rtc_set_cal(float ppm) {
ppm*= (1<<20) / 1000000.0f;
int32_t cal = ppm > 0 ? ppm + 0.5f : ppm - 0.5f;
if ((RTC->ISR & RTC_ISR_RECALPF) != 0 || cal < -511 || cal > 512)
int32_t cal = ppm * (1<<20) / 1000000.0f + 511.5f;
if ((RTC->ISR & RTC_ISR_RECALPF) || (uint32_t)cal > 1024)
return;
if (cal > 0)
RTC->CALR = RTC_CALR_CALP | (512 - cal);
else
RTC->CALR = -cal;
RTC->CALR = ((511 - cal) & (RTC_CALR_CALP | RTC_CALR_CALM));
}

float rtc_get_cal(void) {
Expand Down
8 changes: 6 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static uint16_t p_sweep = 0;
float measured[2][SWEEP_POINTS_MAX][2];

#undef VERSION
#define VERSION "1.2.28"
#define VERSION "1.2.29"

// Version text, displayed in Config->Version menu, also send by info command
const char *info_about[]={
Expand Down Expand Up @@ -772,7 +772,7 @@ VNA_SHELL_FUNCTION(cmd_time)
dt_buf[0] = rtc_get_tr_bcd(); // TR should be read first for sync
dt_buf[1] = rtc_get_dr_bcd(); // DR should be read second
static const uint8_t idx_to_time[] = {6,5,4,2, 1, 0};
static const char time_cmd[] = "y|m|d|h|min|sec";
static const char time_cmd[] = "y|m|d|h|min|sec|ppm";
// 0 1 2 4 5 6
// time[] ={sec, min, hr, 0, day, month, year, 0}
uint8_t *time = (uint8_t*)dt_buf;
Expand All @@ -782,6 +782,10 @@ VNA_SHELL_FUNCTION(cmd_time)
}
if (argc!=2) goto usage;
int idx = get_str_index(argv[0], time_cmd);
if(idx == 6) {
rtc_set_cal(my_atof(argv[1]));
return;
}
uint32_t val = my_atoui(argv[1]);
if (idx < 0 || val > 99)
goto usage;
Expand Down
4 changes: 2 additions & 2 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -2306,8 +2306,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_rtc_out_acb)
}

const menuitem_t menu_rtc_cal[] = {
{ MT_ADV_CALLBACK, KM_RTC_CAL, "RTC CAL\n " R_LINK_COLOR "%b.4f " S_PPM, menu_keyboard_acb },
{ MT_ADV_CALLBACK, 0, "RTC OUT\n%s" , menu_rtc_out_acb },
{ MT_ADV_CALLBACK, KM_RTC_CAL, "RTC CAL\n" R_LINK_COLOR "%+b.4f" S_PPM, menu_keyboard_acb },
{ MT_ADV_CALLBACK, 0, "RTC OUT\n%s" , menu_rtc_out_acb },
{ MT_NEXT, 0, NULL, menu_back } // next-> menu_back
};
#endif
Expand Down

0 comments on commit e623734

Please sign in to comment.