コード例 #1
0
void SendTemperature(uint8 channel, int16 adcOffset, int32 opampGainFactor) {
#define NUM_ADC_READINGS 16
    // Select the desired thermocouple input
    AMux_1_Select(channel);
    
    // Wait for op-amp to settle
    CyDelay(1);
    
    // Discard a result from ADC (probably unnecessary)
    ADC_SAR_Seq_1_IsEndConversion(ADC_SAR_Seq_1_WAIT_FOR_RESULT);
    
    // Average together a bunch of ADC readings
    // (note the hardware is already averaging 256 samples at a time)
    int32 adcReadingTotal = 0;
    uint8 i = 0;
    for (i = 0; i < NUM_ADC_READINGS; i++) {
        ADC_SAR_Seq_1_IsEndConversion(ADC_SAR_Seq_1_WAIT_FOR_RESULT);
        adcReadingTotal += ADC_SAR_Seq_1_GetResult16(0) - adcOffset;
    }
    int16 adcReading = adcReadingTotal / NUM_ADC_READINGS;
    
    // Convert to microvolts
    int32 hotJunctionVolts = ADC_SAR_Seq_1_CountsTo_uVolts(0, adcReading);
    
    // Reading was amplified by op-amp
    hotJunctionVolts = hotJunctionVolts * 100 / opampGainFactor;
    
    // Adjust for temperature at cold side of thermocouple
    int32 coldJunctionVolts = Thermocouple_1_GetVoltage(ROOM_TEMPERATURE);
    
    // Read temperature (100 * degrees C)
    int32 temperature = Thermocouple_1_GetTemperature(hotJunctionVolts + coldJunctionVolts);
    
    // Send over serial
    sprintf(
        serialBuf,
        "T%d=%ld (adc=%hd uvHot=%ld uvCold=%ld)\r\n",
        channel + 1,
        temperature,
        adcReading, hotJunctionVolts, coldJunctionVolts
    );
    UART_1_UartPutString(serialBuf);
}
コード例 #2
0
ファイル: campbell.c プロジェクト: kLabUM/IoT
uint8 campbell_cond_br_read(float* Rs){
    
    uint8 i, chan = 0u;
    
    AMux_1_Select(chan);
    // if i == 5, Mux could not be reset to 0

    ADC_DelSig_1_StartConvert();    
    CyDelay(1u);     
    
    for (i = 0u; i < 100; i++) {
        
        if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS)){
            
            if (chan == 0)
            {                
            
                ADC_DelSig_1_StopConvert(); // Stop the conversion so signals don't 
                                        // get mixed when switching the mux
                chan = 1u;
                AMux_1_Select(chan);
                res1 = ADC_DelSig_1_GetResult16();
    			dvpp = ADC_DelSig_1_CountsTo_Volts(res1) ;

                CyDelay(1u);
                ADC_DelSig_1_StartConvert();  
                CyDelay(49u);
            }
            else {            
                ADC_DelSig_1_StopConvert(); // Stop the conversion so signals don't 
                                        // get mixed when switching the mux
                AMux_1_DisconnectAll();
                
                res2 = ADC_DelSig_1_GetResult16();
        		vpp1 = (ADC_DelSig_1_CountsTo_Volts(res2)/2);
                vpp2 = vpp1 - dvpp;
                
                break;
            }                                                       
        }
        CyDelay(1u); 
    }
    
    
    //*Rs_half = 2*(vpp2-(vpp1)/2)/(vpp1);    // BR_HALF: Voltage divider between Cond LO and GND
    //*Rs_full = 2*(vpp2-(vpp1)/2)/(vpp1);    // BR_FULL: Reversed Differential measurement bewteen Cond HI and cond LO
    
    //*Rs_half = vpp2/vpp1;    // BR_HALF: Voltage divider between Cond LO and GND
    *Rs = vpp2/vpp1;    // BR_FULL: Reversed Differential measurement bewteen Cond HI and cond LO
    
    // ADC range is configured as min(v1) +/- 6.114
    // Readings are expected to be between min(v1) to +6.114
    // and misreading min(v1) as max(v1) results in overflow (eg values like 7.8 and 11)
    if (vpp1 > 6.114 || vpp2 > 6.114) {                                            
        return 0u;
    // Range of excitation signal is 2-2.5 VAC        
    } else if (vpp1 > 2.6) {
        return 0u;
    // vpp2 should always be less than vpp1        
    } else if (*Rs > 1) {
        return 0u;        
    } else if (*Rs < 0) {
        return 0u;
    } else {
        return 1u;
    }
}
コード例 #3
0
ファイル: campbell.c プロジェクト: kLabUM/IoT
uint8 campbell_temp_br_read(float* VsVx){
    
    uint8 i, chan = 2u;
    float mult = 1.0, ratio = 0.0, R = 0.0;
    
    if (! campbell_temp_start()) {
        return 0u;
    }
    
    AMux_1_Select(chan);
    ADC_DelSig_1_StartConvert();    
    CyDelay(100u);     
    
    for (i = 0u; i < 100; i++) {
        
        if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS)){
            
            if (chan == 2)
            {                
            
                ADC_DelSig_1_StopConvert(); // Stop the conversion so signals don't 
                                        // get mixed when switching the mux
                
                
                res1 = ADC_DelSig_1_GetResult16();
    			Vx = ADC_DelSig_1_CountsTo_Volts(res1) ;
                mult = 8/Vx;                // See Sec 12 http://s.campbellsci.com/documents/au/manuals/cs547a.pdf
                                            // Multiplier scales Vx to 8000 mV
                chan = 3u;
                AMux_1_Select(chan);  
                //ADC_DelSig_1_SelectConfiguration(2u, 1u);
                CyDelay(1u);
                ADC_DelSig_1_StartConvert(); 
                CyDelay(99u);                 
            }
            else {            
                ADC_DelSig_1_StopConvert(); // Stop the conversion so signals don't 
                                        // get mixed when switching the mux
                AMux_1_DisconnectAll();
                
                res2 = ADC_DelSig_1_GetResult16();
        		Vs = ADC_DelSig_1_CountsTo_Volts(res2) ;                
                break;
            }                    
        }
        CyDelay(1u); 
    }
        
    if (! campbell_temp_stop()) {
        return 0u;
    }     
    
    //*VsVx = mult * VsVx * 8000;   
    
    ratio = Vs/Vx;                          // Added to adjust for using 100 kOhm instead of 1 kOhm
    R = (100000 - (ratio*349000)) / ratio;  // Added to adjust for using 100 kOhm instead of 1 kOhm  
    *VsVx = 1000 / (R + 250000) * 8000;     // Now that Rs is known, use original equation
                                            // note: Datasheet says 800, but 8000 yields correct results

        // According to Therm107 Datasheet, http://s.campbellsci.com/documents/au/manuals/107.pdf
    // VsVx*8000 should range between 0 and 30
    if (*VsVx > 0 && *VsVx < 30) {                                            
        return 1u;      // Result is valid
    } else {
        return 0u;
    }
}