Example #1
0
unsigned short SampleFvrForVdd(void)
{
	unsigned short result = 0;
	unsigned char i;
	CVRCON2bits.FVREN = 1;	// FVR on
	Delay100us();			// Wait for stability
	Delay100us();
	InitAnalog(); 			// adc to default
	ADCON1 = 0b00000000; 	// vdd used for reference
	ADCON2 = 0b10101011; 	// Right Justified, 12Tad sample time, IntRC, 20us Taq
	ADCON0 = 0b00000001; 	// adc on
	ADCON0 |= (FVR_CHANNEL<<2);	// adc channel

	// Sample multiple times
	for(i=0;i<64;i++)
	{
		// Sample sensor - ~30us * 64
		ADCON0bits.GO = 1;
		while (ADCON0bits.GO){;}
		result += ((unsigned short)ADRESH<<8) + ADRESL;
	}

	CVRCON2bits.FVREN = 0; 	// FVR off
	InitAnalog(); 			// Put everything back (Off)
	return result;
}
Example #2
0
unsigned short SampleLight(void)
{
	// Assembles 16bit ADC value using oversampling
	// Specially delayed to get ~10ms average for 
	// fluorescent lamp compensation @ 50Hz
	unsigned char i;
	unsigned long sum = 0;
	InitAnalog(); 					// adc to default
	ADCON0 = 0b00000001; 			// adc on
	ADCON0 |= (LIGHT_CHANNEL<<2); 	// adc channel
	ADCON0bits.GO = 1;
	// Sample multiple times
	for(i=0;i<64;i++)
	{
		// Sample sensor - ~30us
		ADCON0bits.GO = 1;
		while (ADCON0bits.GO){;}
		sum += ((unsigned short)ADRESH<<8) + ADRESL;
		// Sample sensor - ~30us
		ADCON0bits.GO = 1;
		while (ADCON0bits.GO){;}
		sum += ((unsigned short)ADRESH<<8) + ADRESL;
		// Additional delay - 100us
		Delay100us();
		// Total delay = 64 * 160us = 10.2ms
	}
	// Discard 1 bit (10bits * 64 sample = 16bits)
	sum >>= 1;	
	// Turn off ADC
	ADCON0 = 0b00000000; 	// adc off
	// Return result
	return (sum & 0xffff);
}
Example #3
0
unsigned short AdcSampleTemp(void)
{
	unsigned short result = 0;
	unsigned char i;
	InitAnalog(); 			// adc to default
	ADCON0 = 0b00000001; 	// adc on
	ADCON0 |= (TEMP_CHANNEL<<2);// adc channel

	// Sample multiple times
	for(i=0;i<64;i++)
	{
		// Sample sensor - ~30us * 64
		ADCON0bits.GO = 1;
		while (ADCON0bits.GO){;}
		result += ((unsigned short)ADRESH<<8) + ADRESL;
	}

	InitAnalog(); 			// Put everything back (Off)
	return result;
}
Example #4
0
/**
 *  @fn void MCUInit()
 *
 *  @brief Sets the microcontroller to a predetermined state. Handles initialization
 *         for all categories of peripherals: Analog, Architecture, Communication,
 *         Data Converters, GPIO, LCD, Special Modules, Timers.
 *
 */
void MCUInit()
{
  #if defined(__MCU_MSP430_SERIES)
    InitAnalog();				                                // Initialize the Analog modules
    InitArchitecture();			                                        // Initialize the Architecture modules
    InitCommunication();			                                // Initialize the Communication modules
    InitDataConverters();			                                // Initialize the Data Converter modules
    InitGPIO();				                                        // Initialize the GPIO modules
    InitLCD();				                                        // Initialize the LCD modules
    InitSpecialModules();			                                // Initialize the Special modules
    InitTimers();				                                // Initialize the Timers modules
  #endif
}
Example #5
0
void InitSDLJoy() {
    uint8_t i;

    g.PadState[0].JoyKeyStatus = 0xFFFF;
    g.PadState[1].JoyKeyStatus = 0xFFFF;

    for (i = 0; i < 2; i++) {
        g.PadState[i].JoyDev = &controller_data[i];
    }

    memset(&controller_data[0], 0, sizeof (struct controller_data_s));
    memset(&controller_data[1], 0, sizeof (struct controller_data_s));

    InitAnalog();
}
Example #6
0
//ext
XInstrument::XInstrument() {
	InitAnalog();
	m_pXRayTube = new XRayTube(this);   //1
	m_pSampleLid = new XSampleLid(this);//2
	m_pShamber = new XShamber(this);    //3
	m_pBeamStop = new XBeamStop(this);  //4
	m_pLight = new XLight();
	m_pKey = new XKey();
	pCh=new ChnConfig();

	if(!m_pXRayTube || !m_pSampleLid || !m_pShamber || !m_pBeamStop || !m_pLight || !m_pKey){
		printf("init instrument error \n");
		getch();
	}
	m_status=SwitchToIdle;
	//m_status=SwitchToStandBy;
	LoadCrc32Table("Crc32.tab");
	old1cvect=getvect(0x1c);
	setvect(0x1c,new1cv);
	ReceivingBxConfig=FALSE;
	FaultEncountered=FALSE;
	//ReceivingTiConfig=FALSE;
	//ReceivingTubeConfig = FALSE;
}