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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/05/03 12:15
Read: times


 
#40753 - RE: 8051 DAC
Responding to: ???'s previous message
Sara:
If the D/A converter is over 8 bits then in general you need to program the high and low half. For example if you had an unsigned int variable with the value you wanted to send out to the D/A converter then you could write it like this:
unsigned int DAC_Val;
...
DAC0H = (DAC_Val >> 8);
DAC0L = (DAC_Val & 0xFF);
...

Alternatively IF the DAC0H and DAC0L register addresses are directly adjacent <big>AND</big> the high / low byte order follows the byte ordering convention used by your C compiler then it may be possible to assign the unsigned int value directly to the DAC0 label like you asked about. I know in particular that in Keil C there is a compiler directive called sfr16 that is used to declare labels to mean an address that can be accessed in SFR address space to permit direct assigment of a 16-bit entity to the SFR. (Do note though that the C compiler ends up producing machine code that breaks the transfer up into two separate 8-bit writes to DAC0+0 and DAC0+1.

You never actually indicated in your posts which 8051 variant you were using so it is not possible to provide further real specific information. However there is additional thing to consider.

Since the D/A converter is more than byte wide (i.e. greater than 8 bits) then there is a likelyhood that there is a requirement to output the two bytes to the D/A in the proper order. Not knowing which part you are using you will have to check the data sheet yourself to see if this is necessary. I bring this up because if the D/A output were to take its new output analog value in real time as each of DAC0H and DAC0L were written then there would always be an intermediate output level that happened as the first byte is outputted while the opposite register is still holding the old value. The chip manufacturers most often solve this problem by having a temporary register in front of one side of the D/A input that takes the byte of the first write. Then when the second byte is written to the D/A the analog value is updated all at once using the value from this temporary register and the value from the 2<small>nd</small> byte written. Obviously for this to function correctly the two bytes need to be written in the correct order.

What this means is that you need to check if when you try to use the unsigned int transfer direct to the sfr16 label DAC0 that the resulting code outputs the bytes in the right order. It is really a 50/50 chance that is will be right....you need to check !

This is the reason that often when I write C code to assign values to SFRs that are paired like your DAC0 that I will write the code in the manner like I showed at the top of this post. That way I have direct control over the order of the writes and can comment the code to match the data sheet requirements.

Hope this helps
Michael Karas



List of 8 messages in thread
TopicAuthorDate
8051 DAC            01/01/70 00:00      
   RE: 8051 DAC            01/01/70 00:00      
      RE: 8051 DAC            01/01/70 00:00      
      RE: 8051 DAC            01/01/70 00:00      
         RE: 8051 DAC            01/01/70 00:00      
            RE: 8051 DAC            01/01/70 00:00      
   RE: 8051 DAC            01/01/70 00:00      
      RE: 8051 DAC            01/01/70 00:00      

Back to Subject List