Ejemplo n.º 1
0
int16_t getLDRVoltageForLED(uint8_t selectedPort, uint16_t selectedPins)
{
  //enable desired pins to turn on LED
  
  GPIO_setOutputHighOnPin(selectedPort, selectedPins);
  
  
  //delay so LDR can settle
  __delay_cycles(LED_DELAY);
  
  //read from LDR
  ADC_startConversion(__MSP430_BASEADDRESS_ADC__,ADC_SINGLECHANNEL);
  
  //wait for completion interrupt from ADC
  while(!isADCFinished()) 
  {
    __delay_cycles(1000);
  }
 
  int16_t temp = lastConversionValue();
  
   //disable LED
  GPIO_setOutputLowOnPin(selectedPort, selectedPins);
   
  return temp;
}
Ejemplo n.º 2
0
uint16_t ADC_shittyBusyRead(uint8_t source){
	source &= 0x1f;

	ADC_stopConversion();

	uint16_t i=0;
	for(i=0;i<1000;i++){
		__no_operation();
	}
	adcInterrupted = 0;

	ADC_setNumberOfChannels(2);
	ADC_setChannelSource(0, source);
	ADC_setChannelSource(1, source);

	//enable ADC complete interrupt and change code to interrupt based ADC
	ADC14->rCLRIFGR0.r = 0; //clear all pending ADC interrupts

	ADC_startConversion();

	while(!adcInterrupted){
		__no_operation();
	}

	//	ADC_busyWaitTillFinished();

	ADC_stopConversion();

	return ADC_readMem(0);
}
Ejemplo n.º 3
0
uint16_t * ADC_busyRead(){
	adcInterrupted = 0;
	ADC_startConversion();
	while(!adcInterrupted){
		__no_operation();
	}

	uint8_t i=0;
	for(i=0;i<32;i++){
		adcSamples[i] = adcInternalBuffer[i];
	}

	return adcSamples;
}
Ejemplo n.º 4
0
void tempSensor()
{
    //Initialize the ADC Module
    /*
     * Base Address for the ADC Module
     * Use Timer trigger 1 as sample/hold signal to start conversion
     * USE MODOSC 5MHZ Digital Oscillator as clock source
     * Use default clock divider of 1
     */
    ADC_init(ADC_BASE,
        ADC_SAMPLEHOLDSOURCE_2,
        ADC_CLOCKSOURCE_ADCOSC,
        ADC_CLOCKDIVIDER_1);

    ADC_enable(ADC_BASE);

    //Configure Memory Buffer
    /*
     * Base Address for the ADC Module
     * Use input A12 Temp Sensor
     * Use positive reference of Internally generated Vref
     * Use negative reference of AVss
     */
    ADC_configureMemory(ADC_BASE,
        ADC_INPUT_TEMPSENSOR,
        ADC_VREFPOS_INT,
        ADC_VREFNEG_AVSS);

    ADC_clearInterrupt(ADC_BASE,
            ADC_COMPLETED_INTERRUPT);

    // Enable the Memory Buffer Interrupt
    ADC_enableInterrupt(ADC_BASE,
            ADC_COMPLETED_INTERRUPT);

    ADC_startConversion(ADC_BASE,
                        ADC_REPEATED_SINGLECHANNEL);

    // Enable internal reference and temperature sensor
    PMM_enableInternalReference();
    PMM_enableTempSensor();

    // TimerA1.1 (125ms ON-period) - ADC conversion trigger signal
    Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam_A1);

    //Initialize compare mode to generate PWM1
    Timer_A_initCompareMode(TIMER_A1_BASE, &initCompParam);

    // Start timer A1 in up mode
    Timer_A_startCounter(TIMER_A1_BASE,
        TIMER_A_UP_MODE
        );

    // Delay for reference settling
    __delay_cycles(300000);

    //Enter LPM3.5 mode with interrupts enabled
    while(*tempSensorRunning)
    {
        __bis_SR_register(LPM3_bits | GIE);                       // LPM3 with interrupts enabled
        __no_operation();                                         // Only for debugger

        if (*tempSensorRunning)
        {
        	// Turn LED1 on when waking up to calculate temperature and update display
            P1OUT |= BIT0;

            // Calculate Temperature in degree C and F
            signed short temp = (ADCMEM0 - CALADC_15V_30C);
            *degC = ((long)temp * 10 * (85-30) * 10)/((CALADC_15V_85C-CALADC_15V_30C)*10) + 300;
            *degF = (*degC) * 9 / 5 + 320;

            // Update temperature on LCD
            displayTemp();

            P1OUT &= ~BIT0;
        }
    }

    // Loop in LPM3 to while buttons are held down and debounce timer is running
    while(TA0CTL & MC__UP)
    {
        __bis_SR_register(LPM3_bits | GIE);         // Enter LPM3
        __no_operation();
    }

    if (*mode == TEMPSENSOR_MODE)
    {
        // Disable ADC, TimerA1, Internal Ref and Temp used by TempSensor Mode
        ADC_disableConversions(ADC_BASE,ADC_COMPLETECONVERSION);
        ADC_disable(ADC_BASE);

        Timer_A_stop(TIMER_A1_BASE);

        PMM_disableInternalReference();
        PMM_disableTempSensor();
        PMM_turnOffRegulator();

        __bis_SR_register(LPM4_bits | GIE);         // re-enter LPM3.5
        __no_operation();
    }
}