コード例 #1
0
ファイル: main.c プロジェクト: thasti/gpsdo
int main(void) {
	uint16_t diff;
	int16_t count_deviation;
	uint32_t count;
	char count_string[COUNT_STRING_LEN + 1];
	char pwm_string[3 + 1];

	int16_t c_int = 0;
	int16_t vc = 0;

	WDTCTL = WDTPW + WDTHOLD;
	hw_init();
	gps_startup_delay();
	while(!(gps_disable_nmea_output()));
	while(!(gps_set_gps_only()));
	
	while(1) {
		if (P1IN & CLK_PPS) {
			PJOUT |= LED4;
		} else {
			PJOUT &= ~LED4;
		}
		if (meas_finished == 1) {
			meas_finished = 0;
			diff = end_count - start_count;
			count_deviation = (int16_t) (diff - SETPOINT_COUNT_MOD);
			/* visual lock indication */
			if (count_deviation < -FDEV_DEADZONE) {
				PJOUT = LED1;
			} else if (count_deviation > FDEV_DEADZONE) {
				PJOUT = LED3;
			} else {
				PJOUT = LED2;
			}

			/* output absolute count number to USART */
			count = SETPOINT_COUNT + count_deviation;
			i32toa(count, COUNT_STRING_LEN, count_string);	
			count_string[COUNT_STRING_LEN] = ' ';
			debug_transmit_string_fixed(count_string, COUNT_STRING_LEN + 1);

			/* control algorithm, count_deviation contains the control error */
			c_int = c_int + count_deviation;
			if (c_int > 200) c_int = 200;
			if (c_int < -200) c_int = -200;
			vc = (32768 - 350 * c_int) >> 8;
			if (vc > 255) vc = 255;
			if (vc < 0) vc = 0;
			TA1CCR2 = vc;

			/* output PWM for debug purposes */
			i32toa((uint32_t)vc, 3, pwm_string);
			pwm_string[3] = '\n';
			debug_transmit_string_fixed(pwm_string, 3 + 1);

		}
	} /* while(1) */
コード例 #2
0
ファイル: uforth-ext.c プロジェクト: item28/tosqa-ssb
/*
  All extended commands are handled here.  This is a really long
  switch statement. It could be made shorter by making the contents function
  calls but (outside of a good optimizer) this would incur additional overhead.
  We want to be as fast as possible.

  If you are reading this, but haven't looked at uForth scripts, you are
  missing a lot of context. This is just a bunch of utility calls that will
  make more sense when browsed within the context of a calling script!
  
*/
uforth_stat c_ext_handle_cmds(CELL n) {
  CELL r1, r2,r3;               /* NOTE: THESE ARE 16 bit values! */
  char *str1;

  switch (n) {
  case UF_INTERP:               /* recursively call the uforth interpreter */
    r1 = dpop();
    str1 = uforth_count_str(r1,&r1);
    str1[r1] = '\0';
    dpush(uforth_interpret(str1));
    break;
  case UF_SUBSTR:               /* return a substring of the uForth string */
    r1 = dpop();                /* addr */
    r2 = dpop();                /* length */
    r3 = dpop();                /* start */
    str1 = uforth_count_str(r1,&r1);
    if (r1 < r2) r2 = r1;
    PAD_STRLEN = r2;
    memcpy(PAD_STR, str1 + r3, r2);
    dpush(RAM_START_IDX+PAD_ADDR);
    break;
  case UF_NUM_TO_STR:                   /* 32bit to string */
    {
      char num[12];
      i32toa(dpop32(),num,uforth_uram->base);
      PAD_STRLEN=strlen(num);
      memcpy(PAD_STR, num, PAD_SIZE);
      dpush(RAM_START_IDX+PAD_ADDR);
    }
    break;
  default:
    return E_ABORT;
  }
  return OK;
}
コード例 #3
0
ファイル: test.c プロジェクト: Insecurity-plan15/trinary
void cmain(void)
{

    char s[200];
	unsigned i;
	
	out("       <-- Test: Hello, World!");

  
    for (i = 0;; i++)
	{
		i32toa(i, s, 10);
		out(s);
	}
}
コード例 #4
0
ファイル: tlm.c プロジェクト: scarecrowli/utrak
/*
 * prepare_tx_buffer
 *
 * fills tx_buf with telemetry values. this depends on the
 * GPS having a fix and telemetry being extracted before
 *
 * telemetry format:
 * - callsign
 * - sentence id
 * - time
 * - latitude
 * - longitude
 * - altitude
 * - available satellites
 * - voltage of the AAA cell
 * - MSP430 temperature
 */
void prepare_tx_buffer(void) {
	static uint16_t sent_id = 0;
	int i;
	uint16_t crc;

	sent_id++;
	tlm_sent_id_length = i16toav(sent_id, &tx_buf[TX_BUF_SENT_ID_START]);
	tx_buf[TX_BUF_SENT_ID_START + tlm_sent_id_length] = ',';

	i16toa(current_fix.hour, 2, &tx_buf[TX_BUF_TIME_START]);
	i16toa(current_fix.min, 2, &tx_buf[TX_BUF_TIME_START + 2]);
	i16toa(current_fix.sec, 2, &tx_buf[TX_BUF_TIME_START + 4]);
	tx_buf[TX_BUF_TIME_START + TIME_LENGTH] = ',';
	
	if (current_fix.lat > 0) {
		tx_buf[TX_BUF_LAT_START] = '+';
		i32toa(current_fix.lat, 9, &tx_buf[TX_BUF_LAT_START + 1]);
	} else {
		tx_buf[TX_BUF_LAT_START] = '-';
		i32toa(0 - current_fix.lat, 9, &tx_buf[TX_BUF_LAT_START + 1]);
	}
	/* copy fraction of degrees one character towards the end, insert dot */
	/* 012XXXXXX -> 012 XXXXXX */
	for (i = 8; i >= 3; i--) {
		tx_buf[TX_BUF_LAT_START + i + 1] = tx_buf[TX_BUF_LAT_START + i];	
	}
	tx_buf[TX_BUF_LAT_START + 3] = '.';
	tx_buf[TX_BUF_LAT_START + LAT_LENGTH + 1] = ',';

	if (current_fix.lon > 0) {
		tx_buf[TX_BUF_LON_START] = '+';
		i32toa(current_fix.lon, 10, &tx_buf[TX_BUF_LON_START + 1]);
	} else {
		tx_buf[TX_BUF_LON_START] = '-';
		i32toa(0 - current_fix.lon, 10, &tx_buf[TX_BUF_LON_START + 1]);
	}
	/* copy fraction of degrees one character towards the end, insert dot */
	/* 51XXXXXX -> 51 XXXXXX */
	for (i = 9; i >= 4; i--) {
		tx_buf[TX_BUF_LON_START + i + 1] = tx_buf[TX_BUF_LON_START + i];	
	}
	tx_buf[TX_BUF_LON_START + 4] = '.';
	tx_buf[TX_BUF_LON_START + LON_LENGTH + 1] = ',';
	
	tlm_alt_length = i16toav(current_fix.alt, &tx_buf[TX_BUF_ALT_START]);
	tx_buf[TX_BUF_ALT_START + tlm_alt_length] = ',';
	
	i16toa(current_fix.num_svs, SAT_LENGTH, &tx_buf[TX_BUF_SAT_START]);
	tx_buf[TX_BUF_SAT_START + SAT_LENGTH] = ',';
	
	i16toa(current_fix.voltage_bat, VOLT_LENGTH, &tx_buf[TX_BUF_VOLT_START]);
	tx_buf[TX_BUF_VOLT_START + VOLT_LENGTH] = ',';

	if (current_fix.temperature_int < 0) {
		tx_buf[TX_BUF_TEMP_START] = '-';
		i16toa(0 - current_fix.temperature_int, TEMP_LENGTH, &tx_buf[TX_BUF_TEMP_START + 1]);
	} else {
		tx_buf[TX_BUF_TEMP_START] = '+';
		i16toa(current_fix.temperature_int, TEMP_LENGTH, &tx_buf[TX_BUF_TEMP_START + 1]);
	}
	
	tx_buf[TX_BUF_TEMP_START + TEMP_LENGTH + 1] = '*';

	crc = calculate_txbuf_checksum();
	i16tox(crc, &tx_buf[TX_BUF_CHECKSUM_START]);
	for (i = 0; i < TX_BUF_POSTFIX_LENGTH; i++)
		tx_buf[TX_BUF_POSTFIX_START + i] = TX_BUF_POSTFIX[i];

	tx_buf_length = TX_BUF_FRAME_END;
	/* trigger transmission */
	tx_buf_rdy = 1;
}