13 Replies Latest reply on Jun 10, 2015 5:47 PM by userc_40753

    Sequencing SAR transfer to UART using DMA






      I'm trying to transfer data acquired from a sequencing SAR ADC to a UART block using DMA.




      I used the code provided by the DMA Wizard.




      The trouble is, I always get the data from the first TD and never from the second one.




      Normally I used the ADC_SAR_Seq_1_SAR_SAR_WRK0_PTR (assuming I only have 1 instance of the sequencing SAR ADC) address to get the ADC value. But in this case, it only provides one of the channels' value (I have 2 channels, by the way).




      I tried messing around and I found out that the sequencing SAR ADC is a sort of macro that includes two DMA transfers. I found out the final structure that houses the values from the 2 channels (in my case, its called ADC_SAR_Seq_1_finalArray[2].




      I tried to transfer the data directly from there to the UART's TX register, but I still get only the first channel's value.




      Am I missing something here? Or is there another way to do it?




      I'll put the project as an attachment.




      I'm pretty new to PSoC Creator so any in-depth comments and (positive) criticism is very welcomed.



        • 2. Re: Sequencing SAR transfer to UART using DMA
                  ADC_SAR_Seq Problems   
          • 3. Re: Sequencing SAR transfer to UART using DMA

            Your DMA does not work for some reasons:


            The conversion results are stored in sram and you defined peripheral base as the source. The array is stored in








            declared in ADC_SAR_Seq_1.c. Take care of the fact that data is stored in reverse order ie Channel1, Channel0.



            • 4. Re: Sequencing SAR transfer to UART using DMA



              Anything wrong with your reply-window? When using ms internet explorer try to enable the "Compatibility Mode" under "Extras"





              • 5. Re: Sequencing SAR transfer to UART using DMA





                I tried to fix the address base, but it didn't work.




                However, I tried to play around with the TD configs, and I ended up using this :




                    /* Configuring the TD for this DMA transfer :
                     *  TD handle                   : DMA_1_TD
                     *  Transfer count              : 1
                     *  Next TD                     : DMA_1_TD[1]
                     * Overall, we are using a ping-pong mode here
                    CyDmaTdSetConfiguration(DMA_1_TD[0], 2, DMA_1_TD[1], CY_DMA_TD_AUTO_EXEC_NEXT);
                    CyDmaTdSetConfiguration(DMA_1_TD[1], 2, DMA_1_TD[0], CY_DMA_TD_AUTO_EXEC_NEXT);
                    /* Configuring the TD address for the transfer */
                    CyDmaTdSetAddress(DMA_1_TD[0], LO16((uint32)ADC_SAR_Seq_1_SAR_SAR_WRK_PTR), LO16((uint32)UART_1_TXDATA_PTR));
                    CyDmaTdSetAddress(DMA_1_TD[1], LO16((uint32)ADC_SAR_Seq_1_SAR_SAR_WRK_PTR), LO16((uint32)UART_1_TXDATA_PTR));




                Which works, except that it gives me results a bit too fast (I was hoping that a reading comes out every half a second or so, since I fixed a hardware soc attached to a 2 Hz clock for the SAR).




                I was wondering if this is a synchronization problem between the DMAs in the sequencing SAR and the DMA that I'm using to transfer data to the UART. And also possibly the UART not buffering my data correctly.




                Any ideas? I thought of overwriting the C sources of the SAR DMAs but I prefer not to, if there is another way that is.




                New version of the project is attached.

                • 6. Re: Sequencing SAR transfer to UART using DMA

                  What do you mean by 'giving results a bit too fast'? The DMA will write to the UART as fast as the UART can accept the data. Or do you mean you get data more often than twice a second (more than 4 values per second)?




                  If your DMA gets triggered by the EOC signal of the SAR ADC, there should not be a sync problem - at this moment the SAR ADCs DMA has copied the values over to the final memory location, and will touch them only after the next conversion.

                  • 7. Re: Sequencing SAR transfer to UART using DMA



                    The source for your DMA is in sram!!! you should define


                    extern int16 ADC_SAR_Seq_1_finalArray[ADC_SAR_Seq_1_NUMBER_OF_CHANNELS];


                    and use this as your source for DMA. As you can see it is defined as 16-bit var which must be taken into account when transferring to UART.




                    Additionally there is absolutely no requirement to use ping-pong DMA (2 chained TDs) it only complicates the situation.







                    • 8. Re: Sequencing SAR transfer to UART using DMA





                      Thanks for all of your comments.




                      I finally got it working as I wanted. Now I can transfer both values to UART.




                      There are still some small bugs like the trailing zeros, but for now, that's not a problem.




                      Final version attached.




                      Thanks again.

                      • 9. Re: Sequencing SAR transfer to UART using DMA

                         If I'm not mistaken, the DMA_1_BYTES_PER_BURST parameter sets how many bursts the transfer will do, doesn't it?




                        So that means if I set that to 1, and I set the transferCount parameter as 4 in CyDmaTdSetConfiguration, the DMA executes 1 burst of 4 bytes?

                        • 10. Re: Sequencing SAR transfer to UART using DMA



                          Yes, that seems to be right.





                          • 11. Re: Sequencing SAR transfer to UART using DMA

                            I think this is 4 bursts of 1 byte/burst, and the transfer count indicates


                            when the transaction is complete ?




                            Regards, Dana.

                            • 12. Re: Sequencing SAR transfer to UART using DMA

                              That probably was too early in the morning for me!


                              Datashett says for DmaInitialize():






                              uint8 burstCount: Specifies the size of bursts (1 to 127) into which TDs on this channel


                              should be divided. The burst size should be multiples of the spoke size.

                              If this value is zero, each transfer is done as a single burst. In this case, the transfer count


                              parameter for each TD determines the number of bytes to transfer in one burst.






                              So it means that you may set your TD to transfer say 2000 bytes, but this should be done in 100 bursts of each having 20 bytes by specifying 20 for burstCount parameter.





                              • 13. Re: Sequencing SAR transfer to UART using DMA

                                 Hello all. I need a little help.




                                I need to get at least 10000 samples, using a 1Msps ADC (8 or 10 bits), then I have to compare these samples with a threshold, if any samples were out of this threshold I have to send the samples to a computer using Uart or USB.




                                I did a project like this using Psoc 4, but it has only 4K of sram and I could sample only 1200 samples. The project is attached.




                                I bought recently the CY8CKIT-059 PSoC® 5LP Prototyping Kit to try to solve this problem because it has more Sram, but the project didn't work.




                                Any one could help me unfortunately I dont know how to work with DMA yet.