Posts

Showing posts with the label PIC32MX

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...

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://tahmidmc.blogspot.com/2014/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://tahmidmc.blogspot.com/2014/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)....

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...

A Comparative Study between two 32-bit microcontrollers - the Atmel AT91SAM3X8E and the Microchip PIC32MX250F128B

As previously mentioned ( http://tahmidmc.blogspot.com/2013/09/200000-views-ithaca-arm-and-dmips.html ) I’m doing an independent study under the supervision of Professor Bruce Land here at Cornell University. A semester has passed and I will be continuing my independent study next semester. The independent study (that I'm doing and will be continuing) is on exploring and comparing the peripheral modules of the Microchip PIC32MX250F128B (on the Microstick II platform) and the Atmel AT91SAM3X8E (on the Arduino Due platform). This semester, I've done a good amount of introductory exploration of the two 32-bit microcontrollers. Here are the links to the datasheets of the two microcontrollers on which my independent study is based: AT91SAM3X8E: www.atmel.com/Images/doc11057.pdf PIC32MX250F128B: http://ww1.microchip.com/downloads/en/DeviceDoc/61168E.pdf The Microchip PIC32MX250F128B is a 32-bit RISC microcontroller based on the MIPS M4K core. In this independent study, I have used th...

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

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