Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/24/04 10:48
Read: times


 
#81820 - actual problem
Responding to: ???'s previous message
hi,

actual problem is that 8051 is 8-bit MCU. It has poor 16-bit support. There are no native machine commands which allow to read/write memory with 16-bit values (in fact, there are CALL/RET[i] but they work with stack area).
Due it, MCU core is not able to "snap" 16-bit value. When MCU does something with 16-bit value then MCU takes one byte, then process for second byte. If an ISR comes between these two steps and modifyes the value, then MCU may provide wrong results. For example,

- you have integer variable X in program.
- you increace this variable inside ISR. For example, variable X is extra counter of timer 0 which counts ticks (1/50sec. or like that);
- time to time you copy value of X to integer variable Y inside main loop. It looks like:
//...
unsigned int x, y;
//...
// somewhere inside ISR of timer 0:
x++;
//...
// main
// x = 0; // initialization
//...
// y = x;
//...
So what may happen: To copy X to Y, MCU takes one byte, then copy second byte. If the timer ISR comes between these two steps then it may happen:
- assume x = 0x00FF;
- MCU takes 0xFF and put it to variable Y low byte;
- ISR comes, increase X and so x = 0x0100;
- MCU takes 0x01 and put it to variable Y high byte;
- x = 0x0100 but y = 0x01FF;

Here is the problem. I think you see how to fix it. There are some ways:
- disable interrupt temporally;
- check that copied value is the same as source, if not - copy it again;
- use two buffers and flag to disable/reload one of buffers when it needs.
- some other for yor taste.

Regards,
Oleg

List of 6 messages in thread
TopicAuthorDate
Integer operation in Interrupt with keil            01/01/70 00:00      
   Same subject as the post I'm replying to            01/01/70 00:00      
   Keil Knowledgebase            01/01/70 00:00      
      not really relevant            01/01/70 00:00      
   actual problem            01/01/70 00:00      
   no...            01/01/70 00:00      

Back to Subject List