This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

AT89C51 ADC in Timer Interrupt Problem

Hi there,

This may be a compiler/driver issue or it may be a hardware issue but I am wondering if anyone else has seen a similar problem to this.

We have code to read an ADC channel and this works fine. We have code to generate timer interrupts and handle CAN communications and this works fine.

However, when we call the ADC channel read from inside a timer interrupt (timer1, specially used just for this) it appears to completely screw up the CAN transmission. We get transmission on odd channels, bad data, all sorts.

Before I post lots of code as each system is quite complex, has anyone ever heard of this or a similar problem ? I have checked all the 89C51 errata sheets and gone through the assembly code produced by the Kiel and nowhere does there seem to be any connection between the two. Even with the ADC read in the interrupt it only occupies 2% of the processor time so I don't think it's to do with load or latency. I have made sure the ADC interrupt is off so it doesn't create an interrupt within an interrupt.

Thanks for any help,

Dirk

Parents
  • Before I post lots of code as each system is quite complex,

    One thing you should do is reduce the code to the minimum necessary to duplicate the problem. Start a new project and remove everything that isn't necessary. This will make it much easier for you (or someone on this board, if you decide to post the code) to spot where the problem is.

Reply
  • Before I post lots of code as each system is quite complex,

    One thing you should do is reduce the code to the minimum necessary to duplicate the problem. Start a new project and remove everything that isn't necessary. This will make it much easier for you (or someone on this board, if you decide to post the code) to spot where the problem is.

Children
  • SOLVED!!!!

    Thanks for the help guys but I have now solved the mystery. It was caused by another read of the ADC from some old part of the code that I inherited. Eventually the two collided (sort of as Stephan mentioned).

    I guess this is always a problem of inheriting code and having to bind in new devices.

    I still have no idea why this screwed the CAN up but I guess it was that the EOC of the ADC was missed or something and that the code just started missing things. Anyway, it just required including the extra read of the ADC into the timer loop and hey presto, problem gone.

    Cheers for the help.

    Dirk