Shop OBEX P1 Docs P2 Docs Learn Events
MCP4922 Assembly Code? — Parallax Forums

MCP4922 Assembly Code?

I've gotten the MCP4922 spin code on the OBEX and it works well, but slowly. I need something faster for audio, so I tried writing it in assembly. But, it isn't working. It should be very simple, so if someone can take a look and see what I'm doing wrong, I would be most appreciative! Thanks!

Comments

  • I didn't see anything glaring, but I tend to like left-shifting data out as I have that working in so many objects.

    As we say in Hollywood, "For your consideration..." I don't have a chip to test, but I can write simple code. I like to develop PASM objects in a single file like this. When everything is working I pare out the test stuff, and remove the prefix ("mcp4922_" in this case) from method calls.

    Hopefully, this will help you sort out the device.
  • JonnyMacJonnyMac Posts: 8,926
    edited 2017-11-17 02:26
    Of course, about 3ms after I submit the code above I look at it and think, "I should have done that differently. Here's what I am talking about.
    pub mcp4922_set_value(cfg, value) | work
    
      dacval := (1 << 31) | ((cfg & $0F) << 12) | (0 #> value <# $FFF)
    
    Instead of masking the value with $FFF, this version uses the max operator to limit the value to 12 bits.

    BTW, the reason for setting bit31 of decval is to allow %0000 for the configuration bits, and 0 for the dac value -- the background triggers on a non-zero value.
  • I couldn't get yours to work. Not sure what the problem was. But I found the issue with mine. Not enough time for the clock to be high. It needed 2 NOPs before setting low again. That seemed to be all it was. Thanks again for looking at it!
Sign In or Register to comment.