bigmac wrote:
Hello,
I am not entirely sure what is causing the problem, but writing 0 to the COCO bit after the first conversion has commenced will abort that conversion, and is totally unnecessary because it has no affect on the state of the COCO flag. Get rid of the line.
Hello Bigmac..glad to see you agaiin 
I had added the COCO line out of desperation and wasn't there earlier.
Within the ISR code, you have not read the value within ADCRL prior to disabling the ADC module. Therefore any read of ADCRL from outside the ISR will not give a valid result. Read ADCRL from within the ISR code, and this action will also clear the COCO flag (although disabling the ADC module will also do this).
This I have done with no effect.
Some other comments about your code, not related to the current problem. I notice that you tend to write separately to individual bits of a register. While this is less code efficient that writing to all bits simultaneously, in some cases it is not really advisable, even though it may currently work.
This is done for trial.So that I don't have to figure out the value all the time.Only changing the concerned bit does it..
Registers such as SOPT1 are write once. Therefore, if more than one bit requires changing from its powerup default value, all bits must be simultaneously written. Even though you are currently changing only a single bit, it is good practice to write all bits, to allow for future changes to the code.
Each write of the ADCSC1 register will abort any conversion in progress, and start a new conversion. I assume that writing a single bit anywhere within the register will also do this - probably not what you would intend. The solution is to simultaneously write to all bits to commence a conversion, e.g. ADSC1 = 0xA2; // Commence continuous conversion, Ch 2
I would also do the same for ADSC2 and ADCCFG registers, but that is a personal preference.
I will incorporate that in final version.
Regards,
Mac
I have put a resistor divider to simulate this process where the upper arm is a Preset and the lower is a fixed Resistor.
The code jumps to the ADC interrupt routine all the time even if the voltage is 0V.
Now when I set the ADCCVL value to 0xFF ,everything is behaving as it should.
I checked for some values above 0x80 and I found that above 0x88 for ADCCVL, code is waiting for ADC interrupt ,otherwise every step lands in the ADC interrupt routine.
What could be this?
Thanks and regards..