> From: NEIL GANDLER > > I just tried using the A/D module in a program using the > PIC16C74. A weird phenomenon has occured. For the first > sample of a particular channel, the reading is correct, > whether I internally program the use of an external low impedence 2.5v > reference or choose VDD +5v as my reference. But when my program > attempts successive > readings on this channel, the results are errors, as if by > calculation, the channel being measured is compared to a > changed reference slightly lower than Vdd. For example >[cut] By a process of elimination, the problem is (most probably) not - the PIC chip - the reference or test voltage (assuming they are not somehow perturbed by the output to port D or anything else subsequent to the first sample). - timing related. - the code as it executes from hard reset or power-up to the first sample. Assuming that you have _proven_ that the program loop actually behaves as expected i.e. it really does execute SRV1 again... Therefore, the problem must be an incorrect machine state obtained some time after the first sample. Hard reset (as opposed to just executing from location zero) initialises the machine state in a predictable way. You must have some implicit dependence on this state. Subsequent samples are relying on this state, which has been changed after the first sample. Possible reasons for this may be - Not setting the register bank correctly - Not setting the PCLATH page bit correctly - Inadvertently enabling interrupts - Inadvertent write to INDF when FSR is haywire. - Not defining working registers correctly e.g. in your mysterious "1 sec delay routine" you could be using a register which is not 'ORG'd correctly. Once, when porting an '84 program to the '74, I forgot to redefine the base location of the registers (0Ch in the '84 and 20h in the '74). The following steps may help track the problem: - Try using the simulator anyway: although it doesn't simulate the analogue voltage (I think), it should show any problems with initialisations or bank-switching. - Don't turn the ADC off and on each time through the loop (like a tungsten light bulb, this can blow it - no, just joking). Set the ADON bit _outside_ the loop. - Send me the complete code and I'll have a look. Regards, SJH Canberra, Australia