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(aux && PORTD == aux){
                        PORTD = 0x01;
                        PORTD <<=1;
                    if(PORTD == 0x01){
                        PORTD = aux;
                        PORTD >>= 1;

        TMR0H  = (auxADC && 0xFF00) >> 8;
        TMR0L  = auxADC && 0xFF;
        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!

  • \$\begingroup\$ What happens when you try that? \$\endgroup\$ – Scott Seidman Sep 7 '16 at 19:27
  • \$\begingroup\$ question updated... \$\endgroup\$ – Mac Sep 7 '16 at 19:36
  • \$\begingroup\$ Think about posting software questions in stackoverflow ;) They have better answers for Software \$\endgroup\$ – Julien Sep 7 '16 at 19:45
  • \$\begingroup\$ 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 \$\endgroup\$ – Scott Seidman Sep 7 '16 at 19:46

I know that by making the multiplication I am lossing some data.

Multipliing your 10bit ADC result (stored in 16bit variable) by 64 will not make you lose data as the result fits into 16 bit (TMR0 register)

And to answer you main question: you used logical and && instead bitwise and &

TMR0H  = (auxADC & 0xFF00) >> 8;
TMR0L  = auxADC & 0xFF;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.