I am testing this functionality using a 3 V peak-to-peak sine wave with a frequency of 50 Hz. I have shifted the waveform upwards by 1.5 V so to avoid having any negative values going into the ADC pins of the micro-controller.
To sample at equally spaced intervals I am using timer interrupts, In a very similar way to this example here. Instead of switching on an LED, I am doing an ADC conversion.
Before using the following formula:
I need to make sure that I am sampling at given intervals, and to test this I have set my timer clock to provide a 20ms delay before entering the ADC function by doing so:
Code: Select all
T0CTCR = 0x0; //Set Timer Mode
T0PR = 60000-1; //Increment T0TC at every 60000 clock cycles
//60000 clock cycles @60Mhz = 1 mS
T0MR0 = 21-1; //Zero Indexed Count-hence subtracting 1
T0MCR = (1<<0) | (1<<1);//Set bit0 & bit1 to Interrupt & Reset TC on MR0
Code: Select all
VICVectAddr0 = (unsigned )timer0ISR; //Pointer Interrupt Function (ISR)
VICVectCntl0 = (1<<5) | 4; //(bit 5 = 1)->to enable Vectored IRQ slot
VICIntEnable = (1<<4); // Enable timer0 interrupt
The ADC function I am using works well on DC voltages and I can also confirm that the timer is indeed giving a 20 ms delay before entering the ADC function.
Am I missing something obvious here or could there be some other variables I am not taking into consideration? Any ideas would be appreciated.