# Add Noise to the Signal

To verify the ADC features, artificial noise can be generated with various methods and then this noise can be added to the input signal.

• Generating periodic noise with the AVR, using PWM, and adding it to the input signal.
• Generating random noise with the AVR, using DAC, and adding it to the input signal.
Note: Pseudo-random noise can be generated from any device with onboard DAC.

The example code to generate random noise:

unsigned int i;
unsigned int k;
unsigned char random_buf[512];
for (i=0;i<512;i++)
{
random_buf[i]= rand()%256;
}
dac_init();
while (1)
{
DAC.DATA = random_buf[k++];
if (k>512)
{
k=0;
}
}

random_buf[512] is an array of random numbers 0 to 255 using standard library function ‘rand()’.

To generate a true random noise signal, sufficiently high DAC conversion rate is needed. It can be ensured by selecting the CPU clock frequency of the device which generates random DAC noise higher than the device using it as input noise signal.

The circuit illustrated in Figure 1 can be used to add noise to the signal to be measured.

Figure 1. Adding Noise to the Signal Circuit
Note: Precautions may be taken so that the voltage level of the mixed signal may not go above the selected ADC reference voltage. Device characteristics do not recommend input voltage signal above ADC reference voltage.

For periodic noise, a PWM signal can be generated. To get the worst-case scenario of periodic noise in the test setup, the PWM frequency can be selected close to the ADC sampling frequency.

In the example source code, the default CPU clock is 3.33 MHz. ADC clock is 3.33 MHz/4 = 832.5 kHz.

In Free-Running mode, the sampling rate RS is calculated by: