# How to change the reading from an ADC of 10 bits to the timer 0 registers using a PIC18f4550?

I a reading an anlogue value using the 10 bits ADC from the Channel 0. I have implemented an interruption using timer 0, where I set some value for the registers of timer 0 (TMR0H and TMR0L - 8 bits) and wait for the over flow.

Refergin to the question, I want to use the reading of 10 bits from the ADC for the 2 8 bits registers of timer 0. I came up with the idea of multiplying the reading from the ADC by 64(16bits reading approximately), then some how transfer that value to TMR0H and TMR0L. I know that by making the multiplication I am lossing some data.

I havent found a way of accomplish the change between the 16 bits register to the 2 8 bits registers. I tried using bit masking with shift operators.

void interrupt ISR(){
//Check if it is TMR0 Overflow ISR
if(INTCONbits.TMR0IE && INTCONbits.TMR0IF){//TMR0 Overflow ISR
if(giro){
if(aux && PORTD == aux){
PORTD = 0x01;
}else{
PORTD <<=1;
}
}else{
if(PORTD == 0x01){
PORTD = aux;
}else{
PORTD >>= 1;
}
}

TMR0H  = (auxADC && 0xFF00) >> 8;
INTCONbits.TMR0IF = 0;
}
}


There is no problem compiling the code, but when debuggin the code with the pickit 3 the values of TMR0H and TMR0L dont change properly, they dont update with the low and high part of auxADC.

Thanks a lot!

• What happens when you try that? – Scott Seidman Sep 7 '16 at 19:27
• question updated... – Mac Sep 7 '16 at 19:36
• Think about posting software questions in stackoverflow ;) They have better answers for Software – Julien Sep 7 '16 at 19:45
• Start by trying to right ANY number into the low and high registers, maybe 0xABCD, just so you know if your issue is writing to the timer, or processing your ADC number – Scott Seidman Sep 7 '16 at 19:46

And to answer you main question: you used logical and && instead bitwise and &
TMR0H  = (auxADC & 0xFF00) >> 8;