Question

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;
    }
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top