Skip to content

Commit

Permalink
zpu: Reset PID when setting TCXO DAC from the control socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
chemeris committed Jul 26, 2017
1 parent aa35f5c commit dfa6aa0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions zpu/apps/txrx_uhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ static void handle_udp_ctrl_packet(
ctrl_data_out.data.zpu_action.action = ctrl_data_in->data.zpu_action.action;
switch (ctrl_data_in->data.zpu_action.action) {
case UMTRX_ZPU_REQUEST_GET_VCTCXO_DAC:
ctrl_data_out.data.zpu_action.data = (uint32_t)get_vctcxo_dac();
ctrl_data_out.data.zpu_action.data = (uint32_t)gpsdo_get_dac();
break;
case UMTRX_ZPU_REQUEST_SET_VCTCXO_DAC:
set_vctcxo_dac((uint16_t)ctrl_data_in->data.zpu_action.data);
gpsdo_set_dac((uint16_t)ctrl_data_in->data.zpu_action.data);
break;
}
}
Expand Down
25 changes: 19 additions & 6 deletions zpu/lib/gpsdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ static int gpsdo_debug = 0;

static uint16_t dac_value; /* Current DAC value */

int
set_vctcxo_dac(uint16_t v)
static int
_set_vctcxo_dac(uint16_t v)
{
if (gpsdo_debug) printf("DAC: %d\n", v);
dac_value = v;
Expand All @@ -53,8 +53,8 @@ set_vctcxo_dac(uint16_t v)
);
}

uint16_t
get_vctcxo_dac(void)
static uint16_t
_get_vctcxo_dac(void)
{
return dac_value;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ _gpsdo_pid_step(int32_t val)
if (gpsdo_debug) printf("GPSDO: correction = %d (P=%d, I=%d, D=%d)>>%d limit +-%d\n", tot, p_term, i_term, d_term, PID_SCALE_SHIFT, PID_MAX_DEV);

/* Update DAC */
set_vctcxo_dac( PID_MID_VAL + tot );
_set_vctcxo_dac( PID_MID_VAL + tot );
}


Expand Down Expand Up @@ -190,7 +190,7 @@ void
gpsdo_init(void)
{
/* Set the DAC to mid value */
set_vctcxo_dac( PID_MID_VAL );
_set_vctcxo_dac( PID_MID_VAL );

/* Register IRQ handler */
pic_register_handler(IRQ_GPSDO, _gpsdo_irq_handler);
Expand All @@ -201,3 +201,16 @@ gpsdo_init(void)
/* Start request */
gpsdo_regs->csr = GPSDO_CSR_REQ;
}

void gpsdo_set_dac(uint16_t v)
{
/* Reset PID */
_gpsdo_pid_init();
/* Set the DAC value */
_set_vctcxo_dac(v);
}

uint16_t gpsdo_get_dac(void)
{
return _get_vctcxo_dac();
}
4 changes: 2 additions & 2 deletions zpu/lib/gpsdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
void gpsdo_init(void);

/* Set value of the VCTCXO DAC */
int set_vctcxo_dac(uint16_t v);
void gpsdo_set_dac(uint16_t v);

/* Get the current VCTCXO DAC value */
uint16_t get_vctcxo_dac(void);
uint16_t gpsdo_get_dac(void);

#endif /* INCLUDED_GPSDO_H */

0 comments on commit dfa6aa0

Please sign in to comment.