Data Transfer from Ping-Pong Buffers to Internal Memory

Data stored in the ping-pong buffers by the ADC can be transferred to the internal Program Flash Memory (PFM) in a two-step process. First, the contents of the ping-pong buffers are transferred to buffer RAM using DMA. Next, the NVMUI is used to write the buffer RAM contents to a designated page in the PFM. The DMA setup configurations are listed in Table 3-3.
Table 1. DMA Setup Configuration (DMA5)
DMA5 Setup
SSA Source Address Beginning of ping buffer
SSZ Source Size 512 (2 banks for ping and pong buffers)
SMR Source Memory Region GPR
SMODE Source Address Mode SPTR is incremented
DSA Destination Address Beginning of buffer RAM
DSZ Destination Size 256 (1 bank for buffer RAM)
DMODE Destination Address Mode DPTR is incremented
SIRQEN Start Trigger Enable No (stops when DCNT reloads)
SIRQ Start Trigger N/A
SSTP Source Counter Reload Stop N/A
DSTP Destination Counter Reload Stop N/A
AIRQEN Abort Trigger Enable No (stops when DCNT reloads)
AIRQ Abort Trigger N/A
How It Works:
  1. 1.Transfer the contents of the ping buffer to buffer RAM by manually starting the DMA transfer. The DMA stops as soon as the buffer RAM is full (DCNT reloads). Then, proceed to the next step to write to PFM. In the next iteration (when the pong buffer is ready to be transferred), simply start the DMA again manually. SPTR continues into the pong buffer region, whereas DPTR rolls back into buffer RAM again. When the buffer RAM is full and DMA stops again (DCNT reloads), the SPTR rolls back into the ping buffer region(1).
  2. 2.The buffer RAM contents can be written to PFM word-by-word at every sampling timer interrupt so that the CPU stalls are minimized(2,3). The transfer is performed using the write operation in the new NVMUI module in PIC18F57Q43.
  3. 3. Update write address location and number of pages written in the metadata.
Important:
  1. 1.In this application, the ping and the pong buffers are adjacent to each other in data memory. If ping and pong buffers are separated in the data memory, then SSA needs to be reconfigured after every 256 iterations.
  2. 2.To write to PFM, word write is used instead of page write because page write stalls the CPU for typically 10 ms. This seriously affects the data sampling rate of ADC. However, a word write typically takes about 50 µs, which can work with a 10 kHz ADC sampling rate.
  3. 3.PFM word writes stall the CPU for typically 50 μs, which is about 50% time between two ADC samples (100 μs sampling period). Therefore, an interrupt from the sampling timer is used to ensure that PFM writes occur after the ADC has finished sampling and storing data.