CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to use the DMA module to work with arrays of 16 bit numb

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dmitrboristuk



Joined: 26 Sep 2020
Posts: 55

View user's profile Send private message

How to use the DMA module to work with arrays of 16 bit numb
PostPosted: Wed Apr 27, 2022 5:09 am     Reply with quote

Hello. Please tell me how to transfer 16 bit values from an array of numbers to the timer1 register. The trigger for the DMA module is an interrupt from timer0.
It is necessary to transfer the values from output[32] one by one each time an interrupt from Timer0 occurs. Thank you.
device PIC18F45K42
Code:

const unsigned int16 output[32] = {10, 100, 250, 580, 1005, 10, 10, 13, 45, 1000, 852, 10, 10, 10, 456, 10, 895, 12, 10, 25, 100, 200, 800, 2, 1000, 1000, 1000, 1000, 500, 850, 11, 10};
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Apr 27, 2022 7:05 am     Reply with quote

I have to say, why on earth use DMA?. Just have an interrupt for timer0,
and transfer the two bytes. Increment the counter saying where they are
to come from on each transfer. Given these are internal registers, so no
delays needed etc., the transfer will probably take less time than would
be involved in setting up DMA....

For the 16bit values, this is what DMA_WORD is for.
dmitrboristuk



Joined: 26 Sep 2020
Posts: 55

View user's profile Send private message

PostPosted: Wed Apr 27, 2022 7:38 am     Reply with quote

This will be the correct entry.
Code:

dma_start ( 0, DMA_SOURCE_ADDR_IS_PFM | DMA_DEC_SOURCE_ADDR | DMA_DEST_ADDR_UNCHANGED | DMA_HW_TRIGGER_STARTS_XFER | DMA_ONE_SHOT_FROM_SOURCE_COUNT , &TMR1 , &output[31] , 64 , 2 );
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 27, 2022 9:12 am     Reply with quote

I agree with Mr. T ,probably takes longer for DMA xfr than the 'normal' way.
It'd be interesting to see the listings to see how much more code(and time) DMA version would take.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Apr 27, 2022 9:40 am     Reply with quote

No. You can't have two counts.

You need to just have 32 as the count, and set the DMA to do word transfers
(in the setup_dma).
dmitrboristuk



Joined: 26 Sep 2020
Posts: 55

View user's profile Send private message

PostPosted: Wed Apr 27, 2022 11:17 am     Reply with quote

Gentlemen, thank you very much. That is, the fifth parameter is not the number of bytes, but the number of trigger operations. And I agree that the classic way is much more practical and convenient. But when it comes to learning new products, why not give it a try.
Just in case, I will clarify whether it is correct to write the address (&), and not the name of the array element.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Apr 27, 2022 11:45 am     Reply with quote

& is correct.

The array name (on it's own), is the address of the first element. For later
elements, you have to explicitly address the element. So use &.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group