Ejemplo n.º 1
0
static void
measure_temp_timer(void)
{
    int16_t val;
    msg_t msg;

    /* Take an ADC measurement */
    SOCADCSingleStart(SOCADC_AIN6);
    while(!SOCADCEndOfCOnversionGet())
        ;

    /* Read the sample */
    val = SOCADCDataGet();
    val >>= SOCADC_12_BIT_RSHIFT;

    temp_samples[temp_sample_index++] = val;
    if (temp_sample_index >= TEMP_SAMPLES)
    {
        temp_sample_index = 0;
        WS_TIMER_SET_NOW(send_temp_message_timer);
    }

    /* Ensure we take enough samples to average every minute */
    WS_TIMER_SET(measure_temp_timer, SAMPLE_INTERVAL/TEMP_SAMPLES);
}
Ejemplo n.º 2
0
bool TemperatureSensor::readTemperature(void) {    
    // Trigger single conversion on internal temp sensor
    SOCADCSingleStart(SOCADC_TEMP_SENS);
    
    // Wait until conversion is completed
    while(!SOCADCEndOfCOnversionGet())
    {
    }

    // Get data and shift down based on decimation rate
    temperature = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
    
    return true;
}
Ejemplo n.º 3
0
void readTemperature( RetVal *retVal ) {
    uint16_t reading;
    float temperature;
    
    // Enable the temperature sensor
    HWREG( RFCORE_XREG_ATEST ) = 0x01;

    SOCADCSingleStart( SOCADC_TEMP_SENS );
    while( !SOCADCEndOfCOnversionGet() ) {}

    reading = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
    temperature = convertToTemperature( reading );
    
    retVal->retType = RET_TYPE_FLOAT;
    retVal->floatRet = temperature;
}
Ejemplo n.º 4
0
/**************************************************************************//**
* @brief    This function triggers and returns ADC conversion from the ALS
*           output. A 12-bit ADC conversion results in a value of [0, 4095].
*
* @return   Returns the value read from the light sensor
******************************************************************************/
uint16_t
alsRead(void)
{
    uint16_t ui1Dummy;

    //
    // Trigger single conversion on AIN6 (connected to LV_ALS_OUT).
    //
    SOCADCSingleStart(SOCADC_AIN6);

    //
    // Wait until conversion is completed
    //
    while(!SOCADCEndOfCOnversionGet())
    {
    }

    //
    // Get data and shift down based on decimation rate
    //
    ui1Dummy = SOCADCDataGet();
    return(ui1Dummy >> SOCADC_12_BIT_RSHIFT);
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2538_demo_process, ev, data)
{

  PROCESS_EXITHANDLER(broadcast_close(&bc))

  PROCESS_BEGIN();

  counter = 0;
  broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
  printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
  while(1) {
    etimer_set(&et, CLOCK_SECOND*10);

    //ivanm
    // Configure ADC, Internal reference, 512 decimation rate (12bit)
    //
    SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);
    //
    // Trigger single conversion on AIN6 (connected to LV_ALS_OUT).
    //
    SOCADCSingleStart(SOCADC_VDD);
    //
    // Wait until conversion is completed
    //
    while(!SOCADCEndOfCOnversionGet())
    {
    }
    //
    // Get data and shift down based on decimation rate
    //
    ui1Dummy = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
    printf("konverzija(ADC) = 0x%08x\n",ui1Dummy);
    PROCESS_YIELD();

    if(ev == PROCESS_EVENT_TIMER) {
      leds_on(LEDS_PERIODIC);
      printf("Counter = 0x%08x\n", counter);
      err = s_measure(&temperature, checksum, TEMP);

             	  			if (err == 0)
             	  			{
             	  				//printf("Temperature (ADC value) = 0x%4x\n", temperature);

             	  				err = s_measure(&humidity, checksum, HUMI);

             	  				if (err == 0)
             	  				{
             	  					//printf("Humidity (ADC value) = 0x%4x\n", humidity);

             	  					//tc=sht11_TemperatureC(temperature);
             	  					//hc=sht11_Humidity(temperature,humidity);
             	  					tc=0;
             	  					hc=0;
             	  					printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
             	  				}
             	  				else
             	  					printf("SHT11 error - could not read humidity!\n");
             	  			}
             	  			else
             	  				printf("SHT11 error - could not read temperature!\n");

      etimer_set(&et, CLOCK_SECOND);
      rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
                 rt_callback, NULL);
    } else if(ev == sensors_event) {
      if(data == &button_select_sensor) {
    	  if (swt==0)
    	  {
    		packetbuf_copyfrom(&temperature, sizeof(temperature));
    	  	broadcast_send(&bc);
        	swt=1;
    	  }
          else
          {
        	packetbuf_copyfrom(&humidity, sizeof(humidity));
    	  	broadcast_send(&bc);
        	swt=0;
          }

      } else if(data == &button_left_sensor || data == &button_right_sensor) {
        leds_toggle(LEDS_BUTTON);
      } else if(data == &button_down_sensor) {
        cpu_cpsid();
        leds_on(LEDS_REBOOT);
        watchdog_reboot();
      } else if(data == &button_up_sensor) {
        sys_ctrl_reset();
      }
    } else if(ev == serial_line_event_message) {
      leds_toggle(LEDS_SERIAL_IN);
    }
    counter++;
    /* put measaruement sht11 here*/

  }

  PROCESS_END();
}
Ejemplo n.º 6
0
//*****************************************************************************
//
// Main function. Sets up the ADC to use the temperature sensor as input. Note 
// that you must enable to RF Core in order to use the ADC.
// The function runs a while forever loop converting the readout from ADC
// to temperature values and print it on the console.
//
//*****************************************************************************
int
main(void)
{
    uint16_t ui16Dummy;
    double dOutputVoltage;
    char pcTemp[20];

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // (no ext 32k osc, no internal osc)
    //
    SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);

    //
    // Set IO clock to the same as system clock
    //
    SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
     
    //
    // Enable RF Core (needed to enable temp sensor)
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
    
    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Systick operation.
    //
    InitConsole();

    //
    // Display the setup on the console.
    //
    UARTprintf("ADC temp sens\n");
    
    //
    // Connect temp sensor to ADC
    //
    HWREG(CCTEST_TR0) |= CCTEST_TR0_ADCTM;

    //
    // Enable the temperature sensor 
    //
    HWREG(RFCORE_XREG_ATEST) = 0x01;
    
    //
    // Configure ADC, Internal reference, 512 decimation rate (12bit)
    //
    SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);
     
    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Trigger single conversion on internal temp sensor
        //
        SOCADCSingleStart(SOCADC_TEMP_SENS);
        
        //
        // Wait until conversion is completed
        //
        while(!SOCADCEndOfCOnversionGet())
        {
        }

        //
        // Get data and shift down based on decimation rate
        //
        ui16Dummy = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
        
        //
        // Convert to temperature
        //
        dOutputVoltage = ui16Dummy * CONST;       
        dOutputVoltage = ((dOutputVoltage - OFFSET_0C) / TEMP_COEFF);
        
        //
        // Convert float to string
        //
        sprintf(pcTemp, "%.1f", dOutputVoltage);
                
        //
        // Print the result on UART
        //
        UARTprintf("ADC raw readout: %d\n", ui16Dummy);
        UARTprintf("Temperature: %s", pcTemp);
        UARTprintf(" C\n");
        
        //
        // Simple delay
        //
        for(int i=0;i<1000000;i++)
        {
        }
    }
}