2

Hello I'm using the PIC24H microprocessor and I wrote a simple program that takes input from a POT using analog input which is then set to a modulus value of delay. It does seem to set the delay, but progression from left to right is seemingly random and inconsistent. Help would be awesome! Thank you!

int main (void){
    AD1CON1bits.ADON=0;
    AD1CON1=0x00E0;
    AD1CON1bits.AD12B=1;
    AD1CON3=0x8000;
    AD1CON2=0x8000;
    AD1CHS0=0x0000;
    AD1CON1bits.ADON=1;

    int wtdState;
    int delay;
    int temp;

// Set Analog Input Pin
    _CN2PUE=0;
    _TRISA0=1;
    _PCFG0=0;

//Set Digital Output Pins
    _ODCB15=0;
    _TRISB15=0;
    _LATB15=0;

    _ODCB14=0;
    _TRISB14=0;
    _LATB14=1;

    while(1){

    wtdState = _SWDTEN;
    _SWDTEN=1;
    AD1CON1bits.SAMP=1;
    Nop();
    while(!AD1CON1bits.DONE){}

    _SWDTEN = wtdState;

    temp = ADC1BUF0;
    delay = temp%225+25;

    __delay_ms(delay);
    _LATB15=1;
    __delay_ms(delay);
    _LATB15=0;
    }
}
Matt
  • 3,592
  • 5
  • 21
  • 26

1 Answers1

2

it seems that by taking the mod you are making the noise significant, perhaps you should divide instead.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • Wouldn't division change linearity significantly? – Matt Apr 08 '13 at 03:47
  • I don't thinks so.. you get a value back from the adc... then you need to translate that from your adc domain to you other domain... translation via multiplication of some constant... the constant will be bigger than one to increase the magnitude, and less than one to decrease it. – Grady Player Apr 08 '13 at 04:07
  • Oh I see I think I agree with you haha. Thank you ver much! – Matt Apr 08 '13 at 04:50
  • Well it appears that you have fixed my problem Grady Player! Thanks again bro! – Matt Apr 08 '13 at 05:06