Beispiel #1
0
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;
    }
}
Beispiel #2
0
/*******************************************************************************
* Function Name: AMux_1_Select
********************************************************************************
* Summary:
*  This functions first disconnects all channels then connects the given
*  channel.
*
* Parameters:
*  channel:  The channel to connect to the common terminal.
*
* Return:
*  void
*
*******************************************************************************/
void AMux_1_Select(uint8 channel) 
{
    AMux_1_DisconnectAll();        /* Disconnect all previous connections */
    AMux_1_Connect(channel);       /* Make the given selection */
    AMux_1_lastChannel = channel;  /* Update last channel */
}
Beispiel #3
0
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;
    }
}