Posts

Showing posts with the label PIC32MX250F128B

Introduction to the PIC32 - The Basics, Getting Started, IO ports and the First Program

View on Scribd View in Google Docs Download PDF (4shared)

Interfacing a color TFT display with the PIC32MX250F128B

Image
I have been working on interfacing the PIC32MX250F128B with a small 2.2" TFT display from Adafruit. It's a nice little display that is fairly easy to communicate with, using SPI communication. The display I'm using is: http://www.adafruit.com/product/1480 Adafruit provides nice open-source libraries for their products. However, they are for Arduino and thus cannot be directly reused for the PIC32. I went through the library and ported it over for the PIC32, in C. I have attached my project file as a .zip file and you can download it to go through the library header and source files, as well as the demo code. I've tried heavily commenting the code so that it is self-explanatory. As far as hardware goes, with the demo code, the pin connections for the display are: BL (backlight): I left it unconnected, but you can connect it to 3.3V for backlight. SCK: connected to RB14 on the PIC MISO: left unconnected, since I'm not reading anything from the screen MOSI: connected ...

PIC32 DMA+SPI+DAC : Analog output synthesis with zero CPU overhead

Image
I have previously shown how to use the PIC32 SPI module to use the 12-bit DAC MCP4822: http://electel.blogspot.com/2016/10/pic32-spi-using-mcp4822-12-bit-serial.html . While that does allow you to generate analog outputs as desired, it requires you to use CPU cycles to process the timer interrupt and accordingly drive the SPI module. Since the PIC32 contains DMA channels, the process can be completely offloaded from the CPU. For an idea of the PIC32 DMA module, refer to my previously written article: http://electel.blogspot.com/2016/05/simple-pic32-dma-example.html Fig. 1 - The generated sine wave at fpwm = 400kHz and 32 elements in the sine table So, the simple way of offloading the SPI update to the DMA module would be to let the DMA channel transfer data to the SPI buffer. The SPI module is configured for 16-bit data transfer (since the MCP4822 write command requires 2 bytes). This means that the cell size for the DMA channel has been set to 2 (2 bytes to transfer once triggered). T...

PIC32 SPI: Using the MCP4822 12-bit serial dual DAC

Image
I recently got a few pieces of the MCP4822 DAC. You can check out the datasheet here: http://ww1.microchip.com/downloads/en/DeviceDoc/22249A.pdf I found them to be neat little devices. In a small 8-pin PDIP package, the MCP4822 comes with 2 12-bit DACs, which you can easily configure over SPI. This was a great opportunity to get a simple PIC32 SPI application going. I worked on this today to see how fast I can get the DAC output going. Here's the pinout of the MCP4822: Fig. 1 - MCP4822 pinout (taken from datasheet) The MCP4822 can be supplied a voltage in the range of 2.7V to 5.5V. Since I use 3.3V for my PIC32, I used the same 3.3V supply for the VDD for the MCP4822. Pin 5 is the active low signal LDAC that is used to synchronize the two DAC channels. When this pin is brought low, the data in the DAC's input register is copied to the output and both outputs are updated at the same time. I just had this tied to ground. VoutA and VoutB are the two output pins. The other pins are...

PIC32 Tic-Tac-Toe: Demonstration of using touch-screen, TFT and the Protothreads threading library

Image
I had previously used the Adafruit TFT display using my library (ported from the Adafruit Arduino library). I decided to optimize the library to improve drawing speed. The same display I use comes with a 4-wire resistive touch-screen as well. I decided to write a simple library for the touch-screen and give Protothreads a try. To incorporate all this, I thought it would be cool if I used these to make a simple game. Tic-tac-toe came to mind as a fun little demo. I'm sure everyone's familiar with the game so I won't explain the rules there. The touch-screen is simply two resistive sheets placed on top of each other on top of the TFT screen. When it is pressed down at a given place, the two sheets make contact and a voltage divider is formed. Using the IO's and the ADC, this voltage is read in the X and Y directions to register a touch. Here is a very good pictorial depiction of the resistive touch screen (taken from the Atmel AVR341 document ): So in order to...

PIC32MX250F128B ipl7: odd shadow register set behavior and observations

This issue has now been solved. Scroll to the bottom for the update. I started working on a pure sine wave inverter based on the PIC32MX250F128B. The first stage was to just get the SPWM working and test that before proceeding to add the power stage, feedback and other control, etc. This led me to some interesting observations regarding the PIC32MX250F128B interrupts, especially the use of the shadow register set and a related problem. I set up Timer 2 to be the time base for sine wave generation (DDS/SPWM) using OC1. In the Timer 2 interrupt, the duty cycle update request is performed (OC1RS is updated). Timer 2 interrupt priority was set to 7. This all worked fine. The initial ISR definition was: void __ISR(_TIMER_2_VECTOR, ipl7) T2int(void) { ..... } However, when I used the ADC (input from potentiometer for amplitude control - a start at implementing feedback), accessing any of the ADC registers in the while (1) loop in main stopped the PIC32 from working.  I then added ...

A further study into the use of the PIC32MX250F128B, with side projects using the AT91SAM3X8E (Arduino Due) and the Intel Galileo

Download PDF from: http://www.4shared.com/office/kRJ8hVWPce/A_further_study_into_the_use_o.html

Simple PIC32 DMA example

I've been testing the PIC32 DMA recently. The PIC32 has a DMA (direct memory access) module that allows the data transfer in the PIC32 without CPU intervention during data transfer - thus freeing up CPU to perform other tasks while the data is transferred). First, I did a simple test to just see if it works (I've also done some DMA timing testing - I'll talk about them soon in another article). The first test was to just use the DMA module to transfer data from a constant array (from FLASH) to PORTA (LATA for output). This would be visually seen as LEDs connected to PORTA blinking. The code is: //================================ /***************************************************  * Programmer: Syed Tahmid Mahbub  * Target PIC: PIC32MX250F128B  *  * Date: 05/08/2016 - 05/10/2016  *  * Program to test DMA operation  * DMA will transfer const (from FLASH) to PORTA  ***************************************************/ #include "plib.h"  ...

Hacking the PIC32 Comparator Reference to obtain a DAC

Image
The PIC32MX250F128B has a myriad of peripheral features that makes this cheap little 28-pin 32-bit microcontroller extremely powerful. However, it does lack a digital-to-analog converter (DAC). A simple approach to digital-to-analog conversion is to use one of the PWM channels and then to use an RC low-pass filter at the output. However, there is another neat little feature of the device that can be exploited or rather utilized to obtain a rather crude DAC – the analog comparator module. Rather, the analog comparator reference module. The PIC32MX250F128B contains an internal voltage reference module that was created to be used as a reference voltage for the internal analog comparator module. However, it does allow you to output this reference voltage to an output pin. Analog voltage output with digital control? Sounds like a DAC. The voltage reference module is built off of a 16-tap resistor ladder network with two selectable ranges – from 0 to 0.67 CVREF or from 0.25 to 0.75 CVREF. CV...

PIC32 Proto Board: Details, Schematic, PCB and Pictures

Image
I previously showed you my PIC32 proto board I made on verroboard ( http://electel.blogspot.com/2016/02/pic32-development-proto-board-on.html ). To make the proto board “more of a product” and easy to reproduce, I was working to make the proto board on a PCB. I used ExpressSCH to draw the schematic, and used ExpressPCB to design the PCB. Once designed, Professor Bruce Land got the PCB made from ExpressPCB themselves. The PCB is just to be a basic board with the PIC32MX250F128B placed on it. The power supply connections are provided as are external oscillator connections (if needed). Additionally, there is a nice convenient power supply input connector (standard 2.5mm jack/plug). All the IO pins along with power (Vin and +3.3V) and ground are placed on a SIL connector at the edge of the board so that the board can be conveniently placed on a breadboard for experimenting and prototyping (see pictures below). It's a nice little 2-layer PCB measuring only 3.1 inches by 1.8 inches. I c...