Checking ADC noise

Status
Not open for further replies.
Note that T3.1 has a choice of internal or external voltage reference. Which one to use depends on the input signal being absolute or ratiometric.

No doubt that 32 counts of offset error can make small differences between mean/median/trimmed-mean insignificant. The easy solution to good teensy ADC performance - use an external ADC that has the specs you need.

I had some success with causing the T3.1 to recalibrate before each raw sample. This can be done by changing resolution and then changing it back. But is very slow. I started on measuring temp to predict/remove offset - but didn't get far enough for a conclusion.
 
Hello friends

I have a method for better reading from analog read. There is a lot of noise when analog.update() is right after by analog.getValue(). That's why I executed analog.update () in another task. The ADC values are now very stable.

Code:
//*************************************************************************
// Main loop
//*************************************************************************
void loop() {
	unsigned long currentMillis = millis();
	
	// read Midi datas (every 1ms) --------------------------------------
	if (currentMillis - previousTime_midi >= interval_midi){
		midi_handel();
		set_Voices_Lamp();
		previousTime_midi = currentMillis;
	}
	
	// read ADC (every 15ms) --------------------------------------------
	if (currentMillis - previousTime_ADC >= interval_ADC){
		analog1.update();
		analog2.update();
		analog3.update();
		analog4.update();
		previousTime_ADC = currentMillis;
	}
	
	// read Encoder  and Potentiometers (every 25ms) --------------------
	if (currentMillis - previousTime_pot >= interval_pot){
		
		if(read_Encoder() == true){		// Encoder menu site
			Menu_page = oldPosition;
			if(Menu_page == Menu_Osc){
				Osc_menu();
			}
			else if(Menu_page == Menu_AmpEnv){
				AMP_envelope_menu();
			}
			else if(Menu_page == Menu_FilterEnv){
				Filter_envelope_menu();
			}
			else if(Menu_page == Menu_Filter){
				Filter_menu();
			}
		}
		
	// read Potentiometers
		if (read_pots() == true){
			if (Menu_page == Menu_Osc){
				set_OSC_values();
			}
			else if (Menu_page == Menu_AmpEnv){
				set_AMP_envelope();
				draw_AMP_envLine();
				refresh_pot_values();
			}
			else if (Menu_page == Menu_FilterEnv){
				set_Filter_envelope();
				draw_Filter_envLine();
				refresh_pot_values();
			}
			else if (Menu_page == Menu_Filter){
				set_Filter_values();
				draw_filter_curves(Filter_typ);
				refresh_pot_values();
			}
		}
	}
	
	// Measurement CPU usage (every 200ms) ------------------------------
	if (currentMillis - previousTime_cpu >= interval_cpu) {
		print_CPU_usage();
		previousTime_cpu = currentMillis;
	}
}

//*************************************************************************
// read Potentiometers with averaging calculation
//*************************************************************************
boolean read_pots (void)
{
	boolean pot_change = false;
	int adc_sum = 0;
	
	// read Potentiometer 1
	for (uint8_t i = 0; i < 16; i++){
		//analog1.update();				// averaging calculation
		adc_sum = adc_sum + ((analog1.getValue()) >> 3);
	}
	pot_1 = adc_sum / 16;
	if(pot_1_old  != pot_1){
		pot_1_old = pot_1;
		pot_1_change = true;
		pot_change = true;
	}
	
	// read Potentiometer 2
	adc_sum = 0;
	for (uint8_t i = 0; i < 16; i++){
		//analog2.update();
		adc_sum = adc_sum + ((analog2.getValue()) >> 3);
	}
	pot_2 = adc_sum / 16;
	if(pot_2_old  != pot_2){
		pot_2_old = pot_2;
		pot_2_change = true;
		pot_change = true;
	}
	
	// read Potentiometer 3
	adc_sum = 0;
	for (uint8_t i = 0; i < 16; i++){
		//analog3.update();
		adc_sum = adc_sum + ((analog3.getValue()) >> 3);
	}
	pot_3 = adc_sum / 16;
	if(pot_3_old  != pot_3){
		pot_3_old = pot_3;
		pot_3_change = true;
		pot_change = true;
	}
	
	// read Potentiometer 4
	adc_sum = 0;
	for (uint8_t i = 0; i < 16; i++){
		//analog4.update();
		adc_sum = adc_sum + ((analog4.getValue()) >> 3);
	}
	pot_4 = adc_sum / 16;
	if(pot_4_old  != pot_4){
		pot_4_old = pot_4;
		pot_4_change = true;
		pot_change = true;
	}
	
	boolean temp_flag = pot_change;
	pot_change = false;
	return temp_flag;
}
 
Status
Not open for further replies.
Back
Top