Пример #1
0
void tempInit( void ) {
    // Enable the RF Core
    SysCtrlPeripheralEnable( SYS_CTRL_PERIPH_RFC );
    // Connect temperature sensor to ADC
    HWREG( CCTEST_TR0 ) |= CCTEST_TR0_ADCTM;
    SOCADCSingleConfigure( SOCADC_12_BIT, SOCADC_REF_INTERNAL );
}
Пример #2
0
bool TemperatureSensor::enable(void) {
    // Enable RF Core (needed to enable temp sensor)
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
    
    // 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);

    return true;
}
Пример #3
0
/**************************************************************************//**
* @brief    This function initializes the ALS. The sensor is powered up and the
*           onboard ADC is configured.
*
*
* @return   None
******************************************************************************/
void
alsInit(void)
{
    //
    // Set ALS power pin (output high)
    //
    GPIOPinTypeGPIOOutput(BSP_ALS_PWR_BASE, BSP_ALS_PWR);
    GPIOPinWrite(BSP_ALS_PWR_BASE, BSP_ALS_PWR, BSP_ALS_PWR);

    //
    // Configure ALS output pin as hw controlled, no drive (same as for timer)
    //
    GPIOPinTypeTimer(BSP_ALS_OUT_BASE, BSP_ALS_OUT);

    //
    // Configure ADC, Internal reference, 512 decimation rate (12bit)
    //
    SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);
}
Пример #4
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();
}
Пример #5
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++)
        {
        }
    }
}