Ejemplo n.º 1
0
void main ()
{
	auto int rawdata11, rawdata12, rawdata13;
	auto int numbits;

	brdInit();
	if(_BOARD_TYPE_ == 0x0800 || _BOARD_TYPE_ == 0x0802)
	{
		numbits = 12;
	}
	else
	{
		numbits = 10;
	} 
	printf("\n\n\r");
	printf("Displaying RAW data for the %d bit A/D internal test voltages\n\r", numbits);
	printf("------------------------------------------------------------\n\r");
	
	rawdata11 = anaIn(11);	//read A/D internal test voltage (Vref+ - Vref-)/2
	rawdata12 = anaIn(12);	//read A/D internal test voltage  Vref-
	rawdata13 = anaIn(13);  //read A/D internal test voltage  Vref+

	printf("Rawdata count for ch11 is 0x%03x (Vref+ - Vref-)/2 \r\n", rawdata11);
	printf("Rawdata count for ch12 is 0x%03x  Vref-\r\n", rawdata12);
	printf("Rawdata count for ch13 is 0x%03x  Vref+\r\n", rawdata13);
	
}
Ejemplo n.º 2
0
void menuGeneralDiagAna(uint8_t event)
{
  SIMPLE_MENU(STR_MENUANA, menuTabGeneral, e_Ana, 1);

  STICK_SCROLL_DISABLE();

  for (int i=0; i<NUM_STICKS+NUM_POTS; i++) {
#if (NUM_STICKS+NUM_POTS) > 9
    coord_t y = MENU_HEADER_HEIGHT + 1 + (i/3)*FH;
    const uint8_t x_coord[] = {0, 70, 154};
    uint8_t x = x_coord[i%3];
    lcd_outdezNAtt(x, y, i+1, LEADING0|LEFT, 2);
    lcd_putc(x+2*FW-2, y, ':');
#else
    coord_t y = MENU_HEADER_HEIGHT + 1 + (i/2)*FH;
    uint8_t x = i&1 ? 64+5 : 0;
    putsStrIdx(x, y, PSTR("A"), i+1);
    lcd_putc(lcdNextPos, y, ':');
#endif
    lcd_outhex4(x+3*FW-1, y, anaIn(i));
    lcd_outdez8(x+10*FW-1, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*25/256);
  }

  lcd_putsLeft(MENU_HEADER_HEIGHT+1+5*FH, STR_BATT_CALIB);
  static int32_t adcBatt;
  adcBatt = ((adcBatt * 7) + anaIn(TX_VOLTAGE)) / 8;
  uint32_t batCalV = (adcBatt + (adcBatt*g_eeGeneral.txVoltageCalibration)/128) * BATT_SCALE;
  batCalV >>= 11;
  batCalV += 2; // because of the diode
  putsVolts(LEN_CALIB_FIELDS*FW+4*FW, MENU_HEADER_HEIGHT+1+5*FH, batCalV, s_editMode > 0 ? BLINK|INVERS : INVERS);
  if (s_editMode > 0) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txVoltageCalibration, -127, 127);
}
void menuGeneralDiagAna(uint8_t event)
{
#if defined(TX_CAPACITY_MEASUREMENT)
  #define ANAS_ITEMS_COUNT 4
#else
  #define ANAS_ITEMS_COUNT 2
#endif

  SIMPLE_MENU(STR_MENUANA, menuTabGeneral, e_Ana, ANAS_ITEMS_COUNT);

  STICK_SCROLL_DISABLE();

  for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {
#if (NUM_STICKS+NUM_POTS) > 9
    coord_t y = MENU_HEADER_HEIGHT + 1 + (i/3)*FH;
    const uint8_t x_coord[] = {0, 70, 154};
    uint8_t x = x_coord[i%3];
    lcdDrawNumberNAtt(x, y, i+1, LEADING0|LEFT, 2);
    lcdDrawChar(x+2*FW-2, y, ':');
#else
    coord_t y = MENU_HEADER_HEIGHT + 1 + (i/2)*FH;
    uint8_t x = i&1 ? 64+5 : 0;
    lcdDrawStringWithIndex(x, y, PSTR("A"), i+1);
    lcdDrawChar(lcdNextPos, y, ':');
#endif
    lcd_outhex4(x+3*FW-1, y, anaIn(i));
    lcd_outdez8(x+10*FW-1, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*25/256);
  }

  // Display raw BandGap result (debug)
  lcdDrawText(64+5, MENU_HEADER_HEIGHT+1+3*FH, STR_BG);
  lcdDrawNumberAttUnit(64+5+6*FW-3, 1+4*FH, BandGap, 0);

#if   defined(PCBGRUVIN9X)
  lcdDrawTextLeft(6*FH-2, STR_BATT_CALIB);
  // Gruvin wants 2 decimal places and instant update of volts calib field when button pressed
  static uint16_t adcBatt;
  adcBatt = ((adcBatt * 7) + anaIn(TX_VOLTAGE)) / 8; // running average, sourced directly (to avoid unending debate :P)
  uint32_t batCalV = ((uint32_t)adcBatt*1390 + (10*(int32_t)adcBatt*g_eeGeneral.txVoltageCalibration)/8) / BandGap;
  lcdDrawNumberNAtt(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, batCalV, PREC2|(menuVerticalPosition==1 ? INVERS : 0));
#else
  lcdDrawTextLeft(6*FH-2, STR_BATT_CALIB);
  lcdPutsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, g_vbat100mV, (menuVerticalPosition==1 ? INVERS : 0));
#endif
  if (menuVerticalPosition==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txVoltageCalibration, -127, 127);

#if defined(TX_CAPACITY_MEASUREMENT)
  lcdDrawTextLeft(6*FH+1, STR_CURRENT_CALIB);
  lcdPutsValueWithUnit(LEN_CALIB_FIELDS*FW+4*FW, 6*FH+1, getCurrent(), UNIT_MILLIAMPS, (menuVerticalPosition==2 ? INVERS : 0)) ;
  if (menuVerticalPosition==2) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txCurrentCalibration, -49, 49);
#endif

}
Ejemplo n.º 4
0
main ()
{
	auto unsigned int rawdata, data1, data2;
	auto float locurrent, hicurrent;
	auto float currentequ;
	auto int inputnum;
	auto char buffer[64];

	brdInit();

	while (1)
	{
		printf("\nChoose the AD mAmp channel %d to %d .... ", STARTCHAN, ENDCHAN);
		gets(buffer);
		inputnum = atoi(buffer);

		/////Get two data points using known currents
		printf("\n\nAdjust the current to approx. 5.0 mA and then ENTER the actual\n");
		printf("current being measured, (floating point value) = ");
		gets(buffer);
		locurrent = atof(buffer);
		data1 = anaIn(inputnum, mAMP, GAINCODE);
		printf("data1 = %d\n", data1);

		printf("\n\nAdjust the current to approx. 19.0 mA and ENTER the actual\n");
		printf("current being measured, (floating point value) = ");
		gets(buffer);
		hicurrent = atof(buffer);
		data2 = anaIn(inputnum, mAMP, GAINCODE);
		printf("data2 = %d\n", data2);

		/////Calculate gains and offsets
		anaInCalib(inputnum, mAMP, GAINCODE, data1, locurrent, data2, hicurrent);

		/////Store coefficients into eeprom
		anaInEEWr(inputnum, mAMP, GAINCODE);
		printf("Wrote coefficients to eeprom\n");

		/////Read back coefficients from eeprom
		anaInEERd(inputnum, mAMP, GAINCODE);
		printf("Read coefficients from eeprom\n");

		printf("Vary current on channel %d\n", inputnum);
		while (strcmp(buffer,"q") && strcmp(buffer,"Q"))
		{
			currentequ = anaInmAmps(inputnum);
			printf("Current at CH%d is %.2fma\n", inputnum, currentequ);
			printf("\npress enter key to read value again or 'Q' to calibrate another channel\n\n");
			gets(buffer);
		}
	}

}	//end main
Ejemplo n.º 5
0
main ()
{
	auto unsigned int rawdata, inputnum;
	auto float voltequ;

	brdInit();			//sets pwm frequency
	inputnum=0;
	
	while (1)
	{	
		printf("\nChoose:\n");
		printf("  1 to display raw data only\n");
		printf("  2 to display voltage only\n");
		printf("  3 to display both\n\n");

		switch (getchar())
		{
			case '1': 
					rawdata = anaIn(inputnum);
					printf("CH%2d raw data %d\n", inputnum, rawdata);
				break;
			case '2':
					voltequ = anaInVolts(inputnum);
					printf("CH%2d is %.5f V\n", inputnum, voltequ);
				break;
			case '3':
					anaInInfo(inputnum, &rawdata, &voltequ);
					printf("CH%2d is %.5f V from raw data %d\n", inputnum, voltequ, rawdata);
				break;
			default:
			break;
		}
	}		
}	//end main
Ejemplo n.º 6
0
void main()
{
   auto int rc;

	brdInit();

	// initially start up A/D oscillator and charge up cap
	anaIn(0, SINGLE, GAINSET);

	printf("\t\t<<< Analog input channels 0 - 6: >>>\n");
	printf("\t LN0IN\t LN1IN\t LN2IN\t LN3IN\t LN4IN\t LN5IN\t LN6IN\n");
	printf("\t------\t------\t------\t------\t------\t------\t------\n");

  logAddr = MINFLASHADDR;

   while(1)
   {
 		costate{   // Task 1
			waitfor(ADSPIBUSY != (rc=readADC()));
         if(rc<0){
         	 exit(rc);             // 0 = successful finish
         }
     		waitfor(DelaySec(60));     // Delay, yield to other costate 1 minute
      }

 		costate{  // Task 2
	      waitfor(sampleComplete);   // wait for flag to log & display data
			logADC();
      }
   }
}
Ejemplo n.º 7
0
float ReadADCAngleSensor( int chan, int errflagvalue)
{
	int iCounts;
	float fVolts;
	// Convert raw ADC counts on specified channel to volts
	iCounts = anaIn(chan);
	//	First run a sanity check on the ADC input value.
	if(( iCounts <= 0) || ( iCounts > 2047))
	{
		//	RCM4xx function anain can return one error code - ADC OVERFLOW (-4096).
		if( iCounts == FAULTCODE_ADC_OVERFLOW )
		{
			logf("%d ADC_OVERFLOW\r\n",chan);
		}
		else	//	Only remaining possiblity is ADC busy. This is temporary.
		{
			//logf("%d ADC_BUSY\r\n",chan);
			//For now just print these and set the error indicator...
		}
		g_cClampSensorError &= errflagvalue;
		return 0;
	}

	//	Convert counts to volts.
	fVolts = anaCountsToVolts(iCounts);
	return fVolts;
}
Ejemplo n.º 8
0
//////
// this function returns the count and its converted voltage value
//////
void anaInInfo (unsigned int channel, unsigned int *rd, float *ve)
{
	auto int count;
	auto float value;
	
	count = anaIn(channel);
	if (count == ADOVERFLOW)
		value = ADOVERFLOW;
	else
		value = (count - _adcCalibS[channel].offset)*(_adcCalibS[channel].kconst);

	*rd = count;
	*ve = value;
}
Ejemplo n.º 9
0
void main()
{
	auto unsigned int rawdata;
	auto int inputnum, keypress;
	auto float voltequ;
	auto char buffer[64];

	brdInit();			//read constants if AD device installed

	while (1)
	{
		printf("\nChoose the AD channel %d to %d .... ", STARTCHAN, ENDCHAN);
		gets(buffer);
		inputnum = atoi(buffer);

		printf("\nChoose:\n");
		printf("  1 to display raw data only\n");
		printf("  2 to display voltage only\n");
		printf("  3 to display both\n  .... ");
		gets(buffer);
		keypress = atoi(buffer);

		while (strcmp(buffer,"q") && strcmp(buffer,"Q"))
		{
			switch (keypress)
			{
				case 1:
					rawdata = anaIn(inputnum, SINGLE, GAINSET);
					printf("CH%2d raw data %d\n", inputnum, rawdata);
					break;
				case 2:
					voltequ = anaInVolts(inputnum, GAINSET);
					printf("CH%2d is %.5f V\n", inputnum, voltequ);
					break;
				case 3:
					anaInInfo(inputnum, &rawdata, &voltequ);
					printf("CH%2d is %.5f V from raw data %d\n", inputnum, voltequ, rawdata);
					break;
				default:
				break;
			}
			printf("\npress enter key to read value again or 'Q' or read another channel\n\n");
			gets(buffer);
		}
	}
}	//end main
Ejemplo n.º 10
0
main()
{
	auto float 	Tc,		//temperature celcius
					Tk,		//calculated temperature kelvins
					Tkstd,	//standard temperature kelvins
					Tf,		//temperature farenheit
				 	Bt,		//given thermistor beta			// B=(-alpha*T^2)  ???
					Rs,		//given series resistor
					Rtstd,	//given thermistor resistance at standard temperature
					Draw,		//raw data value
					Gain,		//gain
					Dmax;		//max raw data value

	brdInit();

	//assign variables as float values for calculation
	Tc = 25.0;						//standard temp in Celcius
	Tkstd = Tc + 273.15;  		//convert to Kelvins
	Bt = 3965.0;					//thermistor beta
	Rs = 1000.0;					//series resistor
	Rtstd = 3000.0;				//standard temp resistance
	Dmax = 2047.0;					//max value on ADS7870
	Gain = 1.0;						//actual gain multiplier

	while(1)
	{
		//first-time call of this function will take 1 second to charge up cap
		//use single-ended and gain of 1
		do {
			sDelay(1);
		 	Draw = anaIn(7, SINGLE, GAIN_1);
		} while(Draw == 0);

		//calculate temperature in kelvins
		Tk = (Bt * Tkstd) /
			(Tkstd * (log(fabs((-Draw * Rs) /
			(Rtstd * (Draw - (Dmax * Gain)))))) + Bt);

		Tc = Tk - 273.15;				//convert to celcius
		Tf = 1.8*(Tk - 255.37);		//calculate fahrenheit

		printf("Temperature at %.2f C (%.2f F) from data %d\n", Tc, Tf,(int)Draw);
	}
}
Ejemplo n.º 11
0
main ()
{
	auto unsigned int rawdata;
	auto int inputnum, slotnum, keypress, msgcode;
	auto float voltequ;

	brdInit();			//reads calibration constants

	while (1)
	{
		printf("\nChoose:\n");
		printf("  1 to display raw data only\n");
		printf("  2 to display voltage only\n");
		printf("  3 to display both\n\n");

		switch (getchar())
		{
			case '1':
				for (inputnum=STARTCHAN; inputnum<=ENDCHAN; inputnum++)
				{
					rawdata = anaIn(inputnum, SINGLE, GAINSET);
					printf("CH%2d raw data %d\n", inputnum, rawdata);
				}
				break;
			case '2':
				for (inputnum=STARTCHAN; inputnum<=ENDCHAN; inputnum++)
				{
					voltequ = anaInVolts(inputnum, GAINSET);
					printf("CH%2d is %.5f V\n", inputnum, voltequ);
				}
				break;
			case '3':
				for (inputnum=STARTCHAN; inputnum<=ENDCHAN; inputnum++)
				{
					anaInInfo(inputnum, &rawdata, &voltequ);
					printf("CH%2d is %.5f V from raw data %d\n", inputnum, voltequ, rawdata);
				}
				break;
			default:
			break;
		}
	}
}	//end main
Ejemplo n.º 12
0
//---------------------------------------------------------
//	displays both the raw data count and voltage equivalent
//	_adsCalibS is address for single ended channels
//---------------------------------------------------------
void anaInInfo (unsigned int channel, unsigned int *rd, float *ve)
{
	auto unsigned value;
	auto float volt;

	value = anaIn(channel, SINGLE, GAINSET);
	volt = (value - _adcCalibS[channel][GAINSET].offset)*(_adcCalibS[channel][GAINSET].kconst);

	if (value == ADOVERFLOW)
	{
		*rd = ADOVERFLOW;
		*ve = ADOVERFLOW;
	}
	else
	{
		*rd = value;
		if (value <= 0.00)
			*ve = 0.000;
		else
			*ve = volt;
	}
}
Ejemplo n.º 13
0
main ()
{
    auto int channel;
    auto unsigned int avg_sample;
    auto char s[80];
    auto char display[80];
    auto float ad_inputs[ENDCHAN+1];

    brdInit();

    //initially start up A/D oscillator and charge up cap
    anaIn(0,SINGLE,GAINSET);

    DispStr(1, 1, "\t\t<<< Analog input channels 0 - 6: >>>");
    DispStr(1, 3, "\t LN0IN\t LN1IN\t LN2IN\t LN3IN\t LN4IN\t LN5IN\t LN6IN");
    DispStr(1, 4, "\t------\t------\t------\t------\t------\t------\t------");

    for(;;)
    {
        for(channel = STARTCHAN; channel <= ENDCHAN; channel++)
        {
            // sample each channel
            avg_sample = sample_ad(channel, NUMSAMPLES);
            ad_inputs[channel] = convert_volt(channel, avg_sample);
        }

        display[0] = '\0';
        for(channel =  STARTCHAN; channel <= ENDCHAN; channel++)
        {
            sprintf(s, "\t%6.3f", ad_inputs[channel]);
            strcat(display, s);
        }

        DispStr(1, 5, display);
        msDelay(1000);				//delay one second for viewing
    }
}
Ejemplo n.º 14
0
void main ()
{
	auto int inputnum, slotnum, status;
	auto int data1[11], data2[11];
	auto unsigned int rawdata;
	auto float voltequ, volt1, volt2;
	auto char buffer[64];

	brdInit();

	printf("Please enter ADC board slot position, 0 thru 6....");
	do {
		slotnum = getchar();
		} while ((slotnum < '0') || (slotnum > '6'));
	printf("Slot %d chosen.\n", slotnum-=0x30);

	if (status = anaInEERd(ChanAddr(slotnum, 0)))
	{
		printf("Error %d: eeprom unreadable or empty slot\n", status);
		exit(0);
	}
	
	/////get raw data values
	printf("\nAdjust the voltage to approximately %.3fV and then ENTER the actual\n", LOVOLT);
	printf("voltage measurement, (floating point value) = ");
	gets(buffer);
	volt1 = atof(buffer);
	for (inputnum=0; inputnum<=10; inputnum++)
	{
		data1[inputnum] = anaIn(ChanAddr(slotnum, inputnum));
	}
	printf("\nAdjust the voltage to approximately %.3fV and then ENTER the actual\n", HIVOLT);
	printf("voltage measurement, (floating point value) = ");
	gets(buffer);
	volt2 = atof(buffer);
	for (inputnum=0; inputnum<=10; inputnum++)
	{
		data2[inputnum] = anaIn(ChanAddr(slotnum, inputnum));
	}

	for (inputnum=0, status=0; inputnum<=10; inputnum++)
	{
		/////calculate gains and offsets
		if	(anaInCalib(ChanAddr(slotnum, inputnum), data1[inputnum], volt1, data2[inputnum], volt2))
		{
			printf("Cannot make coefficients for channel %d\n", inputnum);
			status++;
		}
	}
	
	if (!status)
	{
		/////store coefficients into eeprom
		for (inputnum=0; inputnum<=10; inputnum++)
		{
			while (anaInEEWr(ChanAddr(slotnum, inputnum)));
		}
		printf("Wrote coefficients to eeprom\n");
 		
		printf("Read back coefficients from eeprom\n");
		for (inputnum=0; inputnum<=10; inputnum++)
		{
			if (status = anaInEERd(ChanAddr(slotnum, inputnum)))
			{
				printf("Error %d: eeprom unreadable; channel %d\n", status,inputnum);
				exit(0);
			}
		}
		
		for (inputnum=0; inputnum<=10; inputnum++)
		{
			voltequ = anaInVolts(ChanAddr(slotnum, inputnum));
			printf("Voltage at CH%d is %.5f V \n", inputnum, voltequ);
		}
	}	
}	//end main
Ejemplo n.º 15
0
void menuGeneralDiagAna(uint8_t event)
{
#if defined(PCBSKY9X) && !defined(REVA)
#define ANAS_ITEMS_COUNT 4
#elif defined(PCBSKY9X)
#define ANAS_ITEMS_COUNT 3
#else
#define ANAS_ITEMS_COUNT 2
#endif

  SIMPLE_MENU(STR_MENUANA, menuTabDiag, e_Ana, ANAS_ITEMS_COUNT);

  STICK_SCROLL_DISABLE();

  for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {
    uint8_t y = 1+FH+(i/2)*FH;
    uint8_t x = i&1 ? 64+5 : 0;
    putsStrIdx(x, y, PSTR("A"), i+1);
    lcd_putc(x+2*FWNUM, y, ':');
    lcd_outhex4(x+3*FW-1, y, anaIn(i));
    lcd_outdez8(x+10*FW-1, y, (int16_t)calibratedStick[CONVERT_MODE(i+1)-1]*25/256);
  }

#if !defined(CPUARM)
  // Display raw BandGap result (debug)
  lcd_puts(64+5, 1+4*FH, STR_BG);
  lcd_outdezAtt(64+5+6*FW-3, 1+4*FH, BandGap, 0);
#endif

#if defined(PCBTARANIS)
  lcd_putsLeft(6*FH+1, STR_BATT_CALIB);
  static int32_t adcBatt;
  adcBatt = ((adcBatt * 7) + anaIn(8)) / 8;
  uint32_t batCalV = (adcBatt + (adcBatt*g_eeGeneral.vBatCalib)/128) * BATT_SCALE;
  batCalV >>= 11;
  batCalV += 2; // because of the diode
  putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH+1, batCalV, (m_posVert==1 ? INVERS : 0));
#elif defined(PCBSKY9X)
  lcd_putsLeft(5*FH+1, STR_BATT_CALIB);
  static int32_t adcBatt;
  adcBatt = ((adcBatt * 7) + anaIn(7)) / 8;
  uint32_t batCalV = (adcBatt + adcBatt*(g_eeGeneral.vBatCalib)/128) * 4191;
  batCalV /= 55296;
  putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 5*FH+1, batCalV, (m_posVert==1 ? INVERS : 0));
#elif defined(PCBGRUVIN9X)
  lcd_putsLeft(6*FH-2, STR_BATT_CALIB);
  // Gruvin wants 2 decimal places and instant update of volts calib field when button pressed
  static uint16_t adcBatt;
  adcBatt = ((adcBatt * 7) + anaIn(7)) / 8; // running average, sourced directly (to avoid unending debate :P)
  uint32_t batCalV = ((uint32_t)adcBatt*1390 + (10*(int32_t)adcBatt*g_eeGeneral.vBatCalib)/8) / BandGap;
  lcd_outdezNAtt(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, batCalV, PREC2|(m_posVert==1 ? INVERS : 0));
#else
  lcd_putsLeft(6*FH-2, STR_BATT_CALIB);
  putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, g_vbat100mV, (m_posVert==1 ? INVERS : 0));
#endif
  if (m_posVert==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatCalib, -127, 127);

#if defined(PCBSKY9X) && !defined(REVA)
  lcd_putsLeft(6*FH+1, STR_CURRENT_CALIB);
  putsTelemetryValue(LEN_CALIB_FIELDS*FW+4*FW, 6*FH+1, getCurrent(), UNIT_MILLIAMPS, (m_posVert==2 ? INVERS : 0)) ;
  if (m_posVert==2) CHECK_INCDEC_GENVAR(event, g_eeGeneral.currentCalib, -49, 49);
#endif

#if defined(PCBSKY9X)
  lcd_putsLeft(7*FH+1, STR_TEMP_CALIB);
  putsTelemetryValue(LEN_CALIB_FIELDS*FW+4*FW, 7*FH+1, getTemperature(), UNIT_DEGREES, (m_posVert==3 ? INVERS : 0)) ;
  if (m_posVert==3) CHECK_INCDEC_GENVAR(event, g_eeGeneral.temperatureCalib, -100, 100);
#endif
}
Ejemplo n.º 16
0
void main ()
{
	auto int rawdata, datapoint1, datapoint2;
	auto float voltequ, lovoltage, hivoltage;
	auto int channel, cal_error, done, key;
	auto char buffer[128];

	brdInit();		// Required for BL2100 series boards

	while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");  

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{		
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}
		
	}

	clrscreen(0, 3);
	DispStr(1, 1, "ADC0 - ADC10 Calibration Program");
	DispStr(1, 2, "--------------------------------");

	for(;;)
	{
		DispStr(1, 3, "Please enter an input channel, 0 thru A (10)....");
		do
		{
			channel = getchar();
		} while (!(isdigit(channel)) && (channel != 'a') && (channel != 'A'));

		// convert the ascii hex value to a interger
		if( channel >= '0' && channel <='9')
		{
			channel = channel - 0x30;
		}
		else
		{
			channel = tolower(channel);
			channel = (channel - 'a') + 10;
		}
		printf("%d", channel);
		
		/////get raw data from two known voltage points
		sprintf(buffer, "Adjust the voltage to appox %.2f volts and then ENTER the actual", MINVOLT);
		DispStr(1, 5, buffer);
		DispStr(1, 6, "voltage being measured, (floating point value) = ");
		gets(buffer);
		datapoint1 = anaIn(channel);
		lovoltage = atof(buffer);

		sprintf(buffer, "Adjust the voltage to appox +%.2f volts and then ENTER the actual", MAXVOLT);
		DispStr(1, 8, buffer);
		DispStr(1, 9, "voltage being measured, (floating point value) = ");
		gets(buffer);
		datapoint2 = anaIn(channel);
		hivoltage = atof(buffer);
		
		/////calculate gains and offsets
		cal_error = FALSE;
		if	(anaInCalib(channel, datapoint1, lovoltage, datapoint2, hivoltage))
		{
			cal_error = TRUE;
			DispStr(1, 12, "Cannot make coefficients...Press any key to retry");
			while(!kbhit());
			clrscreen(3, 20);
		}
		else
		{
			/////store coefficients into eeprom (simulated in flash memory)
			while (anaInEEWr(channel));
		
			/////read back coefficients from eeprom
			while (anaInEERd(channel));
			DispStr(1, 11, "Calibration constants has been written to the eeprom");

			// display user options
			DispStr(1, 17, "User Options:");
			DispStr(1, 18, "-------------");
			DispStr(1, 19, "- Press the 'C' key to calibrate another ADC channel");
			DispStr(1, 20, "- Press the 'Q' key to quit");
		}

		done = FALSE;
		while (!done && !cal_error)
		{
			sprintf(buffer, "Vary voltage on channel %d  (voltage range -10 to +10 volts)", channel);
			DispStr(1, 13, buffer);

			voltequ = anaInVolts(channel);
			sprintf(buffer, "Voltage at CH%d is %.4f ", channel, voltequ);
			DispStr(1, 14, buffer);
			
			// check if a key was pressed
			if(kbhit())
			{
				key = getchar();
				if(key == 'C' || key == 'c')
				{
					// exit and prompt user for next channel to be calibrated
					done = TRUE;
					clrscreen(3, 20);
			
					// empty keyboard buffer
					while(kbhit()) getchar();       
				}
				if (key == 'Q' || key == 'q')		// check if it's the q or Q key        
				{
					// exit sample program     
  					exit(0);               
  				}
  			}
   	}
   }
}	
Ejemplo n.º 17
0
main ()
{
    auto int channel, value1, value2;
    auto float voltage, volts1, volts2;
    auto unsigned int rawdata, gaincode;
    auto char buffer[64];

    brdInit();

    while (1)
    {
        do {
            printf("\nChoose channel 0 - 6 .... ");
            gets(buffer);
            channel = atoi(buffer);
        } while(channel < 0 || channel > 6);

        printrange();
        do {
            printf("\nChoose gain code .... ");
            gets(buffer);
            gaincode = atoi(buffer);
        } while(gaincode < 0 || gaincode > 7);

        printf("\nAdjust to lower voltage of %s and enter actual =  ", vstr[gaincode]);
        gets(buffer);
        volts1 = atof(buffer);
        value1 = anaIn(channel, SINGLE, gaincode);
        if (value1 == ADOVERFLOW)
            printf("lo:  channel=%d overflow\n", channel);
        else
            printf("lo:  channel=%d raw=%d\n", channel, value1);

        printf("\nAdjust to higher voltage of %s and enter actual =  ", vstr[gaincode]);
        gets(buffer);
        volts2 = atof(buffer);
        value2 = anaIn(channel, SINGLE, gaincode);
        if (value2 == ADOVERFLOW)
            printf("hi:  channel=%d overflow\n", channel);
        else
            printf("hi:  channel=%d raw=%d\n", channel, value2);

        anaInCalib(channel, SINGLE, gaincode, value1, volts1, value2, volts2);

        printf("\nstore constants to flash\n");
        anaInEEWr(channel, SINGLE, gaincode);

        printf("\nread back constants\n");
        anaInEERd(channel, SINGLE, gaincode);

        printf("\nVary voltage from 0 - 10  .... \n");

        while (strcmp(buffer,"q") && strcmp(buffer,"Q"))
        {
            voltage = anaInVolts(channel, gaincode);
            printf("Ch %2d Volt=%.5f \n", channel, voltage);
            printf("press enter key to read values again or 'Q' to calibrate another channel\n\n");
            gets(buffer);
        }
    }
}
Ejemplo n.º 18
0
main ()
{
   auto unsigned int rawdata, gain;
   auto int inputnum, slotnum, keypress, msgcode;
   auto float voltequ;

   brdInit();			//reads calibration constants

   gain = 0;
   while (1)
   {
      printf("\nCurrent Gain = %s\n", gainstr[gain]);
      printf("\nChoose:\n");
      printf("  1 to display raw data only\n");
      printf("  2 to display voltage only\n");
      printf("  3 to display both\n");
      printf("  4 to change gain\n\n");

      switch (getchar())
      {
         case '1':
            for (inputnum=STARTCHAN; inputnum<=ENDCHAN; inputnum++)
            {
               rawdata = anaIn(inputnum, SINGLE, gain);
               printf("CH%2d raw data %d\n", inputnum, rawdata);
            }
            break;
         case '2':
            for (inputnum=STARTCHAN; inputnum<=ENDCHAN; inputnum++)
            {
               voltequ = anaInVolts(inputnum, gain);
               printf("CH%2d is %.5f V\n", inputnum, voltequ);
            }
            break;
         case '3':
            for (inputnum=STARTCHAN; inputnum<=ENDCHAN; inputnum++)
            {
               anaInInfo(inputnum, gain, &rawdata, &voltequ);
               printf("CH%2d is %.5f V from raw data %d\n", inputnum, voltequ, rawdata);
            }
            break;
         case '4':
            printf("\nCode  Voltage Range\n");
				for (inputnum=0; inputnum<8; inputnum++)
				{
					printf("  %d = %s\n", inputnum, gainstr[inputnum]);
				}
            printf("Select new gain code: ");
            gain = getchar() - 0x30;
            if (gain > 7) {
               printf("\nInvalid gain, setting to 0 (1x - 0 to 20 Volts).\n\n");
               gain = 0;
            }
            else {
               printf("\n\n");
            }
				break;
			default:
			break;
		}
	}
}
Ejemplo n.º 19
0
void main ()
{
	auto int channel;
	auto float voltage;
	auto unsigned int rawdata, gaincode;
	auto char buffer[64];

	brdInit();

	while (1)
	{
		printrange();
		printf("\nChoose gain code .... ");
		gets(buffer);
		gaincode = atoi(buffer);

		printf("\nAdjust to lower voltage of %s and enter actual =  ", vstr[gaincode]);
		gets(buffer);
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			ln[channel].volts1 = atof(buffer);
			ln[channel].value1 = anaIn(channel, SINGLE, gaincode);
			if (ln[channel].value1 == ADOVERFLOW)
				printf("lo:  channel=%d overflow\n", channel);
			else
				printf("lo:  channel=%d raw=%d\n", channel, ln[channel].value1);
		}

		printf("\nAdjust to higher voltage of %s and enter actual =  ", vstr[gaincode]);
		gets(buffer);
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			ln[channel].volts2 = atof(buffer);
			ln[channel].value2 = anaIn(channel, SINGLE, gaincode);
			if (ln[channel].value2 == ADOVERFLOW)
				printf("hi:  channel=%d overflow\n", channel);
			else
				printf("hi:  channel=%d raw=%d\n", channel, ln[channel].value2);
		}

		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
 			anaInCalib(channel, SINGLE, gaincode, ln[channel].value1, ln[channel].volts1,ln[channel].value2, ln[channel].volts2);
		}

		printf("\nstore constants to flash\n");
		anaInEEWr(ALLCHAN, SINGLE, gaincode);				//store all channels

		printf("\nread back constants\n");
		anaInEERd(ALLCHAN, SINGLE, gaincode);				//read all channels

		printf("\nVary voltage %s\n", vstr[gaincode]);

		while (strcmp(buffer,"q") && strcmp(buffer,"Q"))
		{
			for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
			{
				voltage = anaInVolts(channel, gaincode);
				printf("Ch %2d Volt=%.5f \n", channel, voltage);
			}
			printf("press enter key to read values again or 'Q' to calibrate another gain\n\n");
			gets(buffer);
		}
	}
}
Ejemplo n.º 20
0
void menuCommonCalib(uint8_t event)
{
  for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { //get low and high vals for sticks and trims
    int16_t vt = anaIn(i);
    reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
    reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
#if defined(PCBTARANIS)
    if(i >= NUM_STICKS && i < NUM_STICKS+NUM_POTS-2) {
#else
    if (i >= NUM_STICKS) {
#endif
      reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2;
    }
  }

  s_noScroll = reusableBuffer.calib.state; // make sure we don't scroll while calibrating

  switch(event)
  {
    case EVT_ENTRY:
      reusableBuffer.calib.state = 0;
      break;

    case EVT_KEY_BREAK(KEY_ENTER):
      reusableBuffer.calib.state++;
      break;
  }

  switch (reusableBuffer.calib.state) {
    case 0:
      // START CALIBRATION
      lcd_putsLeft(3*FH, STR_MENUTOSTART);
      break;

    case 1:
      // SET MIDPOINT
      lcd_putsAtt(0*FW, 2*FH, STR_SETMIDPOINT, s_noScroll ? INVERS : 0);
      lcd_putsLeft(3*FH, STR_MENUWHENDONE);

      for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {
        reusableBuffer.calib.loVals[i] = 15000;
        reusableBuffer.calib.hiVals[i] = -15000;
        reusableBuffer.calib.midVals[i] = anaIn(i);
      }
      break;

    case 2:
      // MOVE STICKS/POTS
      STICK_SCROLL_DISABLE();
      lcd_putsAtt(0*FW, 2*FH, STR_MOVESTICKSPOTS, s_noScroll ? INVERS : 0);
      lcd_putsLeft(3*FH, STR_MENUWHENDONE);

      for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {
        if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i])>50) {
          g_eeGeneral.calibMid[i] = reusableBuffer.calib.midVals[i];
          int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i];
          g_eeGeneral.calibSpanNeg[i] = v - v/STICK_TOLERANCE;
          v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i];
          g_eeGeneral.calibSpanPos[i] = v - v/STICK_TOLERANCE;
        }
      }
      break;

    case 3:
      g_eeGeneral.chkSum = evalChkSum();
      eeDirty(EE_GENERAL);
      reusableBuffer.calib.state = 4;
      break;

    default:
      reusableBuffer.calib.state = 0;
      break;
  }

  doMainScreenGraphics();
#if defined(PCBTARANIS)
  drawPotsBars();
#endif
}

void menuGeneralCalib(uint8_t event)
{
  SIMPLE_MENU(STR_MENUCALIBRATION, menuTabDiag, e_Calib, 1);

  menuCommonCalib(event);
}
Ejemplo n.º 21
0
void main ()
{
	auto long average;
	auto unsigned int rawdata;
	auto int channel, gaincode;
	auto int key, i;
	auto float voltage, cal_voltage;
	auto char buffer[64];

	
	brdInit();	
	while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");  

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{		
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}		
	}
	
	while (1)
	{
		printrange();
		printf("\nChoose gain code .... ");
		do
		{
			gaincode = getchar();
		} while (!( (gaincode >= '0') && (gaincode <= '7')) );
		gaincode = gaincode - 0x30;
		printf("%d", gaincode);
		while(kbhit()) getchar();
		
		cal_voltage = .1*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			ln[channel].volts1 = atof(buffer);
			average = 0;
			for(i=0; i<10; i++)
				average += anaIn(channel, SE_MODE, gaincode);
			ln[channel].value1 = (int)average/10;
			printf("lo:  channel=%d raw=%d\n", channel, ln[channel].value1);
		}
		while(kbhit()) getchar();
	
		cal_voltage = .9*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			ln[channel].volts2 = atof(buffer);
			average = 0;
			for(i=0; i<10; i++)
				average += anaIn(channel, SE_MODE, gaincode);
			ln[channel].value2 = (int)average/10;
			printf("hi:  channel=%d raw=%d\n", channel, ln[channel].value2);
		}
		while(kbhit()) getchar();
			
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
 			anaInCalib(channel, SE_MODE, gaincode, ln[channel].value1, ln[channel].volts1,
 			                                       ln[channel].value2, ln[channel].volts2);
		}
		
		printf("\nstore constants to flash\n");
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			anaInEEWr(channel, SE_MODE, gaincode);				//store all channels
		}
		
		printf("\nread back constants\n");
		anaInEERd(ALL_CHANNELS, SE_MODE, gaincode);				//read all channels
		
		printf("\nVary voltage within the range selected\n");
		
		do 
		{
			for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
			{
				voltage = anaInVolts(channel, gaincode);
				printf("Ch %2d Volt=%.5f \n", channel, voltage);
			}
			printf("Press ENTER key to read values again or 'Q' to calibrate another gain\n\n");
			while(!kbhit());
			key = getchar();
			while(kbhit()) getchar();
			
		}while(key != 'q' && key != 'Q');
	}            
}
Ejemplo n.º 22
0
uint16_t getAnalogValue(uint32_t index) 
{
  return anaIn(index);
}
Ejemplo n.º 23
0
void main ()
{
    auto long value1, value2;
    auto unsigned int rawdata;
    auto int channel, gaincode;
    auto int key, i;
    auto float voltage, volts1, volts2, cal_voltage;
    auto char buffer[64];

    // Initialize the controller
    brdInit();

    // Configure channel pair 0 & 1 for Single-Ended bipolar mode of operation.
    // (Max voltage range is �V)
    anaInConfig(0, SE1_MODE);

    // Configure channel pair 2 & 3 for Single-Ended bipolar mode of operation
    // (Max voltage range is �V)
    anaInConfig(1, SE1_MODE);

    // Configure channel pair 4 & 5 for Single-Ended bipolar mode of operation
    // (Max voltage range is �V)
    anaInConfig(2, SE1_MODE);

    // Configure channel pair 6 & 7 for Single-Ended bipolar mode of operation
    // (Max voltage range is �V)
    anaInConfig(3, SE1_MODE);

    while(1)
    {
        DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
        DispStr(1, 2,"Do you want to continue(Y/N)?");

        while(!kbhit());
        key = getchar();
        if(key == 'Y' || key == 'y')
        {
            break;
        }
        else if(key == 'N' || key == 'n')
        {
            exit(0);
        }

    }
    while(kbhit()) getchar();

    while (1)
    {
        printf("\n\nPlease enter an ADC channel, 0 thru 7....");
        do
        {
            channel = getchar();
        } while (!( (channel >= '0') && (channel <= '7')) );
        channel = channel - 0x30;
        printf("%d", channel);
        while(kbhit()) getchar();


        printrange();
        printf("\nChoose gain code .... ");
        do
        {
            gaincode = getchar();
        } while (!( (gaincode >= '0') && (gaincode <= '5')) );
        gaincode = gaincode - 0x30;
        printf("%d", gaincode);
        while(kbhit()) getchar();

        cal_voltage = vmax[gaincode]*.8;
        printf("\nAdjust Power connected to AIN%d to approx. %.2f\n", channel, cal_voltage);
        printf("and then enter actual voltage = ");
        gets(buffer);

        volts1 = atof(buffer);
        value1 = 0;
        for(i=0; i<10; i++)
            value1 += anaIn(channel, gaincode);
        value1 = value1/10;
        printf("Hi:  channel=%d raw=%d\n", channel, value1);


        printf("\nSwap power supply connections and then PRESS any key\n");
        while(!kbhit());
        while(kbhit()) getchar();

        volts2 = -volts1;
        value2 = 0;
        for(i=0; i<10; i++)
            value2 += anaIn(channel, gaincode);
        value2 = value2/10;
        printf("Lo:  channel=%d raw=%d\n", channel, value2);

        anaInCalib(channel, SE1_MODE, gaincode,
                   (int) value1, volts1, (int) value2, volts2);

        printf("\nVary voltage within the range selected.... \n");
        do
        {
            voltage = anaInVolts(channel, gaincode);
            printf("Ch %2d Volt=%.4f \n", channel, voltage);
            printf("Press ENTER key to read values again or 'Q' to calibrate another channel\n\n");
            while(!kbhit());
            key = getchar();
            while(kbhit()) getchar();
        } while(key != 'q' && key != 'Q');
    }
}