예제 #1
0
파일: main.c 프로젝트: bill-he/jackbill350
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*  main() performs following functions:
*  1: Initializes the LCD
*  2: Starts ADC
*  3: Starts ADC converstion.
*  4: Gets the converted result and displays it in LCD.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
int main()
{
    int16 output;

    /* Start the components */

    LCD_Start();
    ADC_DelSig_1_Start();

    /* Start the ADC conversion */
    ADC_DelSig_1_StartConvert();

    /* Display the value of ADC output on LCD */
    LCD_Position(0u, 0u);
    LCD_PrintString("ADC_Output");

    for(;;)
    {
        if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS))
        {
            output = ADC_DelSig_1_GetResult16();
            
            /* Saturate ADC result to positive numbers. */
            if(output < 0)
            {
                output = 0;
            }
            LCD_Position(1u, 0u);
            LCD_PrintInt16(output);
        }
    }
}
예제 #2
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;
    }
}
예제 #3
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;
    }
}
예제 #4
0
파일: main.c 프로젝트: wuweijia1994/PSOC
void main()
{
	CYGlobalIntEnable; /* Enable global interrupts */
	
	ADC_DelSig_1_Start();/* Configure and power up ADC */
	LCD_Char_1_Start(); /* Initialize and clear the LCD */
	
	/* Move the cursor to Row 0 Column 0 */
	LCD_Char_1_Position(ROW_0,COLUMN_0); 
	/* Print Label for the pot voltage raw count */
	LCD_Char_1_PrintString("TEMP NOW:    C");
	
	LCD_Char_1_Position(ROW_1,COLUMN_0);
	LCD_Char_1_PrintString("TEMP SET:    C");
	
	ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */
	
	/* Start capsense and initialize baselines and enable scan */
	CapSense_Start();
	CapSense_InitializeAllBaselines();
	CapSense_ScanEnabledWidgets();

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
	//Start the pwm;
	PWM_1_Start();
    for(;;)
    {
		/* If scanning is completed update the baseline count and check if sensor is active */
		while(CapSense_IsBusy());
		
		/* Update baseline for all the sensors */
		CapSense_UpdateEnabledBaselines();
		CapSense_ScanEnabledWidgets();
		
		/* Test if button widget is active */
		stateB_1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN);
		stateB_2 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN);
	
        /* Wait for end of conversion */
		ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);
		/* Get converted result */
		voltageRawCount = ADC_DelSig_1_GetResult16();
		//Change voltageRawCount to Temperature;
		temp = voltageRawCount / 3.870 * 0.1017 + 0.5;
		cold = (9999 - (temp > temp_set ? temp - temp_set : 0) * 50);
		if(cold < 1000)
			cold = 1000;
		if(cold > 9999)
			cold = 9999;
		//Change the pwm;
		PWM_1_WriteCompare(cold);
		/* Set range limit */
		if (temp > 0x7FFF)
		{
			temp = 0;
		}
		else
		{
		/* Continue on */
		}
		if(show < 10)
		{
			show++;
		}
		else
		{
			show = 0;
			UpdateDisplay(temp, 0); /* Print result on LCD */
			UpdateButtonState(stateB_1, stateB_2);
		}
    }
}