View previous topic :: View next topic |
Author |
Message |
tripper269
Joined: 06 May 2013 Posts: 33 Location: Toronto
|
dsPIC33 SPI with DMA |
Posted: Thu Jan 03, 2019 10:28 am |
|
|
Hello All,
I am working on a project where FPGA and dsPIC33 are communicating through SPI. FPGA is a main processor, Master in SPI and sends temperature/Voltages setting to dsPIC33. Also read back temperature/Voltages readings. Is it possible for dsPIC33 to focus on temperature and voltage PID loops and read/write set points and feedback for temperature and voltages with SPI - DMA. I tried with SPI interrupt, it works but slow down the speed for SPI. I want to make it more faster. FPGA and dsPIC33 both running with 40Mh clock. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Jan 03, 2019 10:56 am |
|
|
Yes. Heck, temperature is a slow response almost not worthy of full blown PID controller. 'voltage' might be different though.
2+ decades ago, I was controlling a 3d helicopter using a 16F877/20MHz in realtime via the internet so with a 'powerhouse' dsPIC33 it should be very, very easy to control whatever you're controlling.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Jan 03, 2019 11:50 am |
|
|
You need to tell us more about the comms required.
Key thing with SPI, is that you have to use two DMA channels. One for
the transmission, and one for the reception.
A lot depends on the 'nature' of the SPI involved.
Ideally you need a fixed length 'packet'.
So a description of the data involved and the transactions involved.
Are there transfers both ways at the same time, or is there a setup
transmission followed by reads?
Is there anything to synchronise this or does it just happen as fast
as possible? |
|
|
tripper269
Joined: 06 May 2013 Posts: 33 Location: Toronto
|
|
Posted: Thu Jan 03, 2019 12:29 pm |
|
|
I am using two DMA channels, for Rx and Tx. It will be fixed length packet, one or two bytes. The transfer will be on both sides at same time and it should work as fast as possible. whenever CPU is free, it should be able to write/read from DMA.
Thanks for reply. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Jan 03, 2019 12:33 pm |
|
|
You really want to be looking at a much larger packet.
You receive a DMA interrupt when the entire transfer is finished.
At this point you process the data.
Now using only a two byte packet, would mean that this would be
happening every two bytes.
DMA, does not involve the CPU. The CPU can be working while
DMA is occurring. The RAM is 'dual ported', so both the CPU
and the DMA controller can be accessing it at the same time. So
DMA does not happen 'when the CPU is idle', it is occurs all the time.
If you want just a two byte packet, then you probably need to be
triggering the DMA using a timer, rather than having it run 'as fast
as possible'. The DMA controller will then transfer the two byte
packet after it is triggered by the timer, and you get the completion
interrupt after the bytes have been transferred. This transfer will
be done at the same time as the CPU is working.
This is slightly different on the PIC33, compared to some of the
more basic PIC's. On the lower chips the DMA instead 'cycle steals',
only accessing the RAM, when the CPU is not doing so. I suspect
you are thinking of this way of functioning. On the PIC33, the DMA
system is more capable. |
|
|
|