• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

My brain hurts. I'm supposed to know this stuff.

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    My brain hurts. I'm supposed to know this stuff.

    Problem 3—An embedded 16-bit microcontroller is connected to an 8-bit DAC, where the DAC is connected to
    the high-order half of the data bus.

    What is the purpose of y in the following driver?

    Code:
    #define DAC (*(unsigned *) 0x8000)
    void DAC_out (unsigned x)
    {
    static unsigned y;
    x += y;
    y = x & 0x00FF;
    DAC = x;
    }
    WTF?

    I haven't a clue.

    It's part of an EQ test out of circuit cellar issue 119.
    Last edited by zeitghost; 25 June 2013, 13:30.

    #2
    Weird, y remembers the last value of x therefore you can switch bits on but not switch them off again, since y is added to current x.

    Comment


      #3
      y appears to be keeping track of the low order part of the result of cumulative addition of x to itself. Presumably something to do with keeping the result accurate over many iterations because the value of x is truncated when it's written to the DAC?
      Last edited by doodab; 25 June 2013, 14:46.
      While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

      Comment


        #4
        Why don't you just tippex it out?

        Sometime you have to think around a problem...

        Comment


          #5
          Ah got it. Because it's an 8 bit DAC, you maintain the lower at bits at 0x8000 and only change the upper bits.

          Badly explained but I know what I mean

          Comment


            #6
            Yes, but why?

            If the DAC is connected to bits 8 to 15, wtf does y have to do with owt?

            Some of those EQ questions are mind bending.

            But only if you don't know the answer, like.

            Plus there's no way to find the answer now since the question was posed about 13 years ago.

            Comment


              #7
              What Doodab said. y is accumulating the unused lower order bits so that every now and again it'll add one to the higher order bits that are used. Without it, a stream of 0x0080s would only ever send zero to the hardware and the signal is discarded; with it you get alternating 0x00 and 0x01s.
              Will work inside IR35. Or for food.

              Comment


                #8
                One assumes that the caller is putting whatever data needs to be written in the high order byte.

                I still can't get my head around this.

                Here's another question:

                Problem 3—What is the difference between an
                interpreter and a compiler?


                Slight difference in level, what?

                Similarly:

                Problem 1—Why is it a generally a bad idea to
                write lengthy ISRs?

                Comment


                  #9
                  Here's another question - why are you doing this?

                  Comment


                    #10
                    Originally posted by Platypus View Post
                    Here's another question - why are you doing this?
                    It marginally relieves the tedium.

                    Comment

                    Working...
                    X