This week I did some programming on PIC32 ADC and SPI functions. The goal is to transfer ADC value from PIC through SPI to a FPGA chip. FPGA chip will act as a ‘Master’ while PIC32 will be the ‘Slave’. I will be coding for PIC32 only therefore the following will only be applicable to PIC32 with MPLABX IDE and Harmony Library.
Examples for PIC32 ADC and SPI
Microchip Harmony provide several examples on initialization of ADC and SPI, follow the ‘Help Harmony Manual (page 276 for ADC examples, page 1884 for ADC Driver library) whereas (page 327 for SPI examples, page 2574 SPI Driver Library).
Technical
First I set up PIC32 as ‘SPI Slave’, it is understood that for PIC32 devices SPI peripheral can have 8bit, 16bit and 32bit data width, while 10/12bit conversion for ADC module. Besides, there are 12analog pins that I will be using to read from and transfer the data into FPGA. The method I am using is to have a, 16bit data width SPI with a 12bit ADC conversion, while to control which analog pins to read from is to create switch case. To have a better understanding on SPI follow this link (SPI)
Case Study
FPGA will send data ranging from 0 to 12. If PIC32 ‘Slave’ receive a number 5, PIC32 will return a 12bit ADC value from Analog pin 5 to FPGA. With this a simple transaction to read PIC32’s ADC value from FPGA can be achieved.
More into ADC
For MZ series the ADC module is capable to achieve high speed successive approximation register (SAR) analog to digital converter. from my experiment (testing out the code) I still have not fully grasp the concept behind the ADC module sampling logic, for it consist of a method call ‘Sample and Hold’ (S&H) which is really unique.
0 Comments