SPI to 12 bit DAC using -Load signal

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

  I was able to get a 12 bit dac working with the PSOC.  Painful, but here is how it worked:

   

   I connected up to a 12 bit dac from the PSoC using the SPI Master unit.

   

   The 12 bit dac requires the Load signal to go low and then high when the data should be loaded.  You can only send 12 bits at a time to the DAC, 16 bits does not work.

   

   I was able to accomplish this by connecting tx_interrupt through a NOT gate to a pin.  I then set the "Interrupt on Byte/Word transfer Complete" checkbox.

   

   I then set the bits to send to 12 bits.

   

   With this, you do a write to the transmit registe to get things primed.

   

uint16 *sp=sineBuffer;

   

 SPI_Master_WriteTxData(sp[index++]);

   

   Then, in  a forever loop, using a sine wave buffer for a test, (the buffer is placed in pointer sp):

   

for(;;)
    {
        /* Place your application code here. */
        if (SPI_Master_ReadTxStatus() & SPI_Master_STS_SPI_DONE) {
            SPI_Master_WriteTxData(sp[index++]);
            if (index >7 ) {
                index=0;
                sp=sineBuffer;
            }
        }
       
    }

   

   Now the interesting part.  DMA does not appear to work with a 12 bit SPI, unless I'm missing something. I suppose you could write two 8 bit bytes at incrementing addresses, but the DMA unit does not appear to want to do this unless it is always incrementing, and we only want to write to the transmit register.

0 Likes
10 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

When you write to the SPI FIFO, you always write to the same register (its a FIFO after all). No need to increase addresses. You need to increment the source address, though.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Not sure if these can help, reference material -

   

 

   

    

   

          

   

http://www.cypress.com/?rID=37793     AN52705     Getting Started with DMA

   

http://www.cypress.com/?rID=82680     AN84810     PSoC® 3 and PSoC 5LP Advanced DMA Topics

   

http://www.cypress.com/?rID=44335     AN61102 PSoC® 3 and PSoC 5LP - ADC Data Buffering Using DMA

   

http://video.cypress.com/video-library/search/dma/     Videos on DMA

   

https://www.youtube.com/results?search_query=dma+psoc Videos on DMA (some overlap)

   

 

   

Regards, Dana.

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

  After several days of work, I have come to the conclusion that the included SPI component will easily work with DMA in 8 bit mode.  I have been successful in working with the SPI in 8 bit mode.  That mode works well.

   

   Unfortunately, the 12 bit DAC device only accepts 12 bits of data.  Additonal data doesn't work, so you can not send two 8 bit bytes (with 12 bits of info) and get a good DAC output.

   

  If you put the SPI in 12 bit mode, it cannot work with the DMA engine, as the DMA engine only does 8 bit writes, whereas the SPI has a 16 bit register when in 12 bit mode, and you do a single 16 bit write.  I traced the API to verify this.

   

  The DMA engine is very simple, and very robust, and 8 bits only.  It is easy to work with, and I've not had any issues with it working if it is set up properly and the right signals are fed to it.  The DMA engine is not the problem.  Its design might be lacking, but it is a solid DMA unit, and gives far less trouble than, for example, Intel's DMA units.  

   

  It would be good if Cypress could upgrade their DMA engine to 16 bits, but if wishes were horses, everyone could ride.

   

  However, don't worry.  Of all the dozen or so DMA units I've worked with, the Cypress DMA unit is up there with the best of them. No one gets DMA 100% right.

   

  On the flip side, none of my designs are ever right, either.

   

  I am investigating creating my own component for this purpose.  

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

DMA width is max 32bits wide. 8 or 16 bits are not too complicated to maintain.

   

 

   

Bob

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

  OK. I'll bite.  How do I transfer to 12 bit SPI using DMA?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Some DMA ref material -

   

 

   

    

   

          

   

http://www.cypress.com/?rID=37793     AN52705     Getting Started with DMA

   

http://www.cypress.com/?rID=82680     AN84810     PSoC® 3 and PSoC 5LP Advanced DMA Topics

   

http://www.cypress.com/?rID=44335     AN61102 PSoC® 3 and PSoC 5LP - ADC Data Buffering Using DMA

   

http://video.cypress.com/video-library/search/dma/     Videos on DMA

   

https://www.youtube.com/results?search_query=dma+psoc Videos on DMA (some overlap)

   

 

   

 

   

As an aside you are using external 12 bit DAC, is that because of speed needs ? If

   

you want an internal one, low speed/settling time, you can get one up to 16 bits with a PWM

   

followed by LPF/Integrator.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Memory to SPI (untested)

   

 

   

Bob

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

 Yes, we need 12 bits and 20khz or higher speed.

   

   Once you get past 8 bits with the SPI, DMA transfers start failing, even with 2 bytes per burst.

   

  The DMA unit appears to only work with 8 bit SPI, based on my tests.

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

 @ Bob  Tested.

   

   That code fails with 12 bit SPI (2 bytes per burst) 

   

   That code works with 8 bit SPI.  Only change is number of bits for the SPI unit.

   

    I'm working on some logic to enable/disable the SPI clock and trigger the load signal after 12 bits, in 8 bit mode.

   

  Your design and my design were identical.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I filed a technical case about that. I'll keep you informed as soon as there are any results.

   

 

   

Bob

0 Likes