Esempio n. 1
0
File: main.c Progetto: kqzca/prj
void goSleep(void)
{
	setSensorDevPwr(DEV_PWR_OFF);
	setSysWakeUpLed(LED_OFF);
	setSysStsLed(LED_OFF);
	setTestPassLed(LED_OFF);
	setTestFailLed(LED_OFF);
	
	int adcVolBat = 0;
	do
	{
		HAL_SuspendTick();
		HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFE);
		HAL_ResumeTick();
		adcVolBat = readAdcChannel(ADC_CHANNEL_7);
		if (adcVolBat < (0x0400))
		{
			setSysStsLed(LED_ON);
			HAL_Delay(10);
			setSysStsLed(LED_OFF);
			HAL_Delay(200);
			setSysStsLed(LED_ON);
			HAL_Delay(10);
			setSysStsLed(LED_OFF);
		}
	} while (adcVolBat < (0x0400));
}
Esempio n. 2
0
File: main.c Progetto: kqzca/prj
int dacOutAdcIn(int dacValue, uint32_t adcChannel)
{
	HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
	HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dacValue);
	HAL_Delay(DAC_OUT_TO_ADC_IN_DELAY); // ms
	int adcValue = readAdcChannel(adcChannel);
	HAL_DAC_Stop(&hdac, DAC_CHANNEL_1);
	return adcValue;
}
Esempio n. 3
0
/*
 * There are the two seperate channels on the sensor, that detect the light.
 * Ch1 detects only the infrarated light spectrum and ch0 detects the visible and the infrarated light spectrum.
 * To calibrate the sensor to the human seeable light spectrum, ch1 will be subtracted from ch0.
 * */
unsigned long read_intensity() {
	long ch0 = readAdcChannel(CHANNEL0_LOW_BYTE_ADDRESS,
			CHANNEL0_HIGH_BYTE_ADDRESS);
	long ch1 = readAdcChannel(CHANNEL1_LOW_BYTE_ADDRESS,
			CHANNEL1_HIGH_BYTE_ADDRESS);
	unsigned long ratio1 = 0;

	data = 0;

	// calculate ratio and scale to 512 (2^9)
	if (ch0 != 0) {
		ratio1 = (ch1 << (RATIO_SCALE + 1)) / ch0;
	}

	// round ratio value
	unsigned long ratio = (ratio1 + 1) >> 1;

	/* transform to LUX (p. 23) */
	// FN package
	unsigned int b, m;

	if (ratio >= 0 && ratio <= K1T) {
		b = B1T;
		m = M1T;
	} else if (ratio <= K2T) {
		b = B2T;
		m = M2T;
	} else if (ratio <= K3T) {
		b = B3T;
		m = M3T;
	} else if (ratio <= K4T) {
		b = B4T;
		m = M4T;
	} else if (ratio <= K5T) {
		b = B5T;
		m = M5T;
	} else if (ratio <= K6T) {
		b = B6T;
		m = M6T;
	} else if (ratio <= K7T) {
		b = B7T;
		m = M7T;
	} else if (ratio <= K8T) {
		b = B8T;
		m = M8T;
	}

	unsigned long temp = (ch0 * b) - (ch1 * m);

	// avoid negativ LUX values
	if(temp < 0){
		temp = 0;
	}

	// round the LSB (2^LUX-SCALE-1)
	temp += (1 << LUX_SCALE-1);

	// cut the rest
	unsigned long lux = temp >> LUX_SCALE;

	return lux;
}