|  |  | @ -5,7 +5,7 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "pt100.h" |  |  |  | #include "pt100.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | uint16_t adc_buffer[AVRG]; |  |  |  | uint16_t adc_buffer[AVRG]; | 
			
		
	
		
		
			
				
					
					|  |  |  | volatile float ch_values[9]; |  |  |  | volatile float ch_values[10]; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void adc_init(void){ |  |  |  | void adc_init(void){ | 
			
		
	
		
		
			
				
					
					|  |  |  |     ADCA.CTRLB = ADC_FREERUN_bm; |  |  |  |     ADCA.CTRLB = ADC_FREERUN_bm; | 
			
		
	
	
		
		
			
				
					|  |  | @ -70,15 +70,21 @@ ISR(DMA_CH0_vect){ | 
			
		
	
		
		
			
				
					
					|  |  |  |     ADCA.CTRLB = 0; // stop ADC
 |  |  |  |     ADCA.CTRLB = 0; // stop ADC
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint8_t old_pin = pin; |  |  |  |     uint8_t old_pin = pin; | 
			
		
	
		
		
			
				
					
					|  |  |  |     pin=(pin+1)%9; |  |  |  |     pin=(pin+1)%10; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     ADCA.CH0.MUXCTRL = pin << ADC_CH_MUXPOS_gp; // give MUX time to switch during averaging
 |  |  |  |     ADCA.CH0.MUXCTRL = pin << ADC_CH_MUXPOS_gp; // give MUX time to switch during calculation
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     float temp = avrg(adc_buffer, AVRG); |  |  |  |     float temp = avrg(adc_buffer, AVRG); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     temp = temp - ADC_0V_COUNT; |  |  |  |     temp = temp - ADC_0V_COUNT; | 
			
		
	
		
		
			
				
					
					|  |  |  |     temp = (temp)/ (4096-ADC_0V_COUNT) * ADC_MAX_VOLT; |  |  |  |     temp = (temp)/ (4096-ADC_0V_COUNT) * ADC_MAX_VOLT; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if(old_pin <= 8){ /* pt100 temperature channels */ | 
			
		
	
		
		
			
				
					
					|  |  |  |         temp = (temp * REF_OHMS)/(SUPPLY_VOLTS - temp); |  |  |  |         temp = (temp * REF_OHMS)/(SUPPLY_VOLTS - temp); | 
			
		
	
		
		
			
				
					
					|  |  |  |         temp = (temp-100)/0.3927; //pt100 formula
 |  |  |  |         temp = (temp-100)/0.3927; //pt100 formula
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         ch_values[old_pin] = temp; |  |  |  |         ch_values[old_pin] = temp; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if(old_pin == 9){ /* 24V supply voltage measurement */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // resistor devider 33k and 1k
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         ch_values[old_pin] = temp * 34; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     DMA.CH0.TRIGSRC = DMA_CH_TRIGSRC_ADCA_CH0_gc; |  |  |  |     DMA.CH0.TRIGSRC = DMA_CH_TRIGSRC_ADCA_CH0_gc; | 
			
		
	
		
		
			
				
					
					|  |  |  |     ADCA.CTRLB = ADC_FREERUN_bm; // start ADC again
 |  |  |  |     ADCA.CTRLB = ADC_FREERUN_bm; // start ADC again
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |