pic16f887 adc compare problem

Discussion in 'Embedded Systems and Microcontrollers' started by Dejan, Jul 31, 2009.

  1. Dejan

    Thread Starter New Member

    Apr 14, 2009
    7
    0
    I'm almost as new in programming pic microcontrollers in assembly language.
    What i tried to do in program, is to compare two results of AD conversion, by subtracting previous, from the current result of conversion. If the previous result is greater then the current, diode should be turned off and the program stops, otherwise it's turned on. Measured (input) voltage is from potentiometer 10k. Frequency is at 8 MHz. Problem is that diode is turned off, with no matter if the previous voltage is grater or not. On reset the situation is like it should be before reset, until the resistance is changed. It seems that the CARRY flag is cleared whenever input voltage is beeing changed. Help me please!!!!:(
     
  2. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    Hi,
    you have a typo in your 'diode_off' routine, it exits to itself rather than 'begin'

    I've not gone through it in great detail, but that should help.
     
  3. Dejan

    Thread Starter New Member

    Apr 14, 2009
    7
    0
    I wrote it that way, to find out where it stops. The program shouldn't go to diode_off routine until the current voltage is less than previous. Could the bouncing of potentiometer be the problem? The program works fine on simulator, and as long as i can see, after first subtraction he ends up in diode_off. Carry remains clear, although the current voltage is greater than previous
     
  4. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    My only other guess is noise on the ADC, you could be getting fractionally different readings each time.

    Single stepping the program & setting breakpoints is the only easy way to find bugs like this.

    Can you beg / borrow/ buy a Microchip ICD2 (In-circuit debugger)?
    Once you have used one of these you will not want to be without it!
     
Loading...