a further study into the use of the pic32mx250f128b, with side projects using the at91sam3x8e...

15
CORNELL UNIVERSITY ECE 4999: INDEPENDENT STUDY REPORT Under the supervision of Professor Bruce R. Land Syed Tahmid Mahbub Spring 2014 A further study into the use of the PIC32MX250F128B, with side projects using the AT91SAM3X8E (Arduino Due) and the Intel Galileo 

Upload: tahmidmc

Post on 15-Oct-2015

16.494 views

Category:

Documents


0 download

DESCRIPTION

Independent Study Report for ECE 4999 at Cornell University, Spring 2014.

TRANSCRIPT

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    CORNELL UNIVERSITY

    ECE 4999: INDEPENDENT

    STUDY REPORTUnder the supervision of Professor Bruce R. Land

    Syed Tahmid MahbubSpring 2014

    A further study into the use of the PIC32MX250F128B, with side projects using the

    AT91SAM3X8E (Arduino Due) and the Intel Galileo

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 2of 15

    TABLE OF CONTENTS

    1. INTRODUCTION . 32. AT91SAM3X8E TESTS . 33. PIC32 TESTS . 3

    a. PROTOTYPE BOARD .. 3b. OTHER TESTS .. 4c. CLOCK SWITCHING .. 5d. CORE TIMER .. 5e. 32-BIT TIMER .. 6

    f. FURTHER I/O .. 6g. DAC WITH ANALOG COMPARATOR REFERENCE MODULE . 7h. ADC . 8i. DMA . 8

    j. PWM . 9k. INTERRUPT . 11l. CAPTURE AND ANALOG COMPARATOR MODULES: CAPACITANCE METER 12m. PERIPHERAL LIBRARY AND LOW-LEVEL ACCESS .. 13

    4. TESTS WITH INTEL GALILEO . 145. FURTHER EXPANSION 156. ACKNOWLEDGEMENT 15

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 3of 15

    INTRODUCTION

    The independent study for this semesterSpring 2014 is a continuation of the independent

    study from last semester: a comparative study between the Atmel AT91SAM3X8E and Microchip

    PIC32MX250F128B 32-bit microcontrollers. However, this semester I shifted my focus mostly to the

    PIC32MX250F128B over the AT91SAM3X8E in order to get a better understanding of the PIC32 as this

    has better promise in terms of applicability especially in a hobbyist or classroom setting.

    Beyond working with just the PIC32, I experimented a bit with the Intel Galileo due to its

    Arduino compatibility. While the Arduino Due was used mostly for the convenient platform (instead of

    having to deal with the surface mount AT91 microcontroller, or its programmer and basic connection)

    provided for experimenting with the AT91SAM3X8E, the Arduino compatibility feature of the Intel

    Galileo presented an interesting opportunity to perform some simple basic tests to compare

    performance between the 84MHz AT91 platform and the 400MHz Intel Quark platform.

    AT91SAM3X8E TESTS

    I did not work much with the AT91SAM3X8E this semester. However, I did work on a simple mini

    oscilloscope that used the internal ADC along with a small TFT display obtained from Adafruit. That is as

    far as my experiments went with the AT91. It is still a nice option for quick prototyping or quick circuit

    design, given its plethora of hardware peripherals and available library functions. However, since this is

    not likely to be used in an educational (eg a microcontroller course) or a commercial (due to price of

    platform compared to microcontroller itself) setting, I chose to pursue the PIC32 in more detail (the

    PDIP package of the PIC32 also makes it an attractive option for hobbyist/prototyping purposes).

    PIC32 TESTS

    PROTOTYPE BOARD

    I initially made a verroboard prototype board for experimenting with the PIC32. This had the

    basic power connections along with connectors on the board to make it easy to take connections to

    other circuits. The idea was to be able to power it externally (without using the USB port of the laptop,which I did not like) along with the ability to have a more sturdy board(the Microstick II appeared a

    bit flimsy especially the connectors at the bottom that would come off the breadboard very easily).

    I then worked on the design of the simple proto board to make a finalized version on PCB. I

    ended up designing a simple small PCB that incorporates the PIC mounted on a DIP socket, along with

    the basic connections for power, optional connections for an external crystal oscillator, USB connector, a

    variable resistor whose wiper can be connected (via a jumper) to an analog pin, a programmer (PICKIT3)

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 4of 15

    header and an array of pins along the edge of the board that can easily be plugged into a breadboard.

    The pins consist of all the IO pins of the PIC32 along with the power (VDD, GND and VIN) connections.

    A detailed description of the verroboard prototype can be found on my blog at:

    http://tahmidmc.blogspot.com/2014/02/pic32-development-proto-board-on.html

    Details of the finalized prototype board, along with the design files (schematic + PCB designed

    with ExpressPCB) and images of the final mounted/assembled board can be found on my blog at the

    following link:

    http://tahmidmc.blogspot.com/2014/02/pic32-proto-board-details-schematic-pcb.html

    Here is a picture of the final prototype board that I have been using for all my experiments

    (connected to the PICKIT3 programmer):

    OTHER TESTS

    I spent some time just trying to understand the PIC32 internal architecture to get a grip of

    whats happening inside and why. While my independent studys focus was mainly on the PIC32

    peripherals, I felt like I had to understand what was going on inside especially when I could get a port pin

    to toggle at only about 5MHz with the PIC running at a 40MHz clock. This led me to learn a bit about the

    internal architecture of the PIC32, of not just the peripherals but also of the MIPS core. This, additional

    to the inspected assembly code, enabled me to understand why a lot of things were happening as they

    were (for example the 5MHz pin toggle). Besides that, it was pretty cool learning how the MIPS core

    http://tahmidmc.blogspot.com/2014/02/pic32-development-proto-board-on.htmlhttp://tahmidmc.blogspot.com/2014/02/pic32-development-proto-board-on.htmlhttp://tahmidmc.blogspot.com/2014/02/pic32-proto-board-details-schematic-pcb.htmlhttp://tahmidmc.blogspot.com/2014/02/pic32-proto-board-details-schematic-pcb.htmlhttp://tahmidmc.blogspot.com/2014/02/pic32-proto-board-details-schematic-pcb.htmlhttp://tahmidmc.blogspot.com/2014/02/pic32-development-proto-board-on.html
  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 5of 15

    worked as this was also the first time I was using a MIPS core. I enjoyed it so much that I actually got a

    book See MIPS Runthat will enable me to better understand the MIPS architecture.

    Beyond that, I played around with the PIC32 peripherals and just experimented with them.

    CLOCK SWITCHING

    The PIC32 offers the very useful feature of being able to change the clock frequency, and even

    clock source, on the fly. I have been able to quite easily switch from the internal 8MHz FRC oscillator (no

    PLL) to a 30MHz or a 40MHz oscillator with the internal FRC oscillator with PLL. Although I have not

    tested it myself, there also exists the option to switch between the internal and external oscillators.

    Clock switching is a very interesting module. It offers an interesting option in terms of power

    saving, since it allows switching on the fly. When all the processing power is needed, the clock can be

    switched to 40MHz frequency, while it may be reduced down, for example to 2sMHz, when high

    frequency isnt needed to conserve some power.

    An interesting note to be made about using PLL with the internal FRC oscillator is that, the PLL

    pre-divider is fixed to 2. For proper operation, it is stated that the input frequency to the frequency

    multiplier module be within 4MHz-5MHz. Since the internal oscillator by default has a frequency of

    8MHz, it makes sense that the pre-divider is fixed to 2.

    However, this is something that I (and Professor Land) did not realize at first and so while trying

    to get the PLL running, initially setting the PLL pre-divider to 4, and then setting the multiplier to 20 (and

    post-divider to 1) resulted in the PIC not working. Turning the multiplier down to 19 caused the PIC to

    run, but at 76MHz. This was because, despite us setting the pre-divider to 4, it was fixed internally to 2.Later changing the pre-divider to 2 and changing the post-divider to 2 fixed the problem and gave us

    40MHz (with the multiplier equal to 20).

    CORE TIMER

    Using the Core Timer available on the PIC32, I made a simple delay library. The idea was to have

    simple delay functions to have for use in cases where a software delay can be used without the need for

    great precision or accuracy in timing. I used this delay library as part of a simple LCD library (set of

    functions) I wrote for using for my own testing. The LCD library was written to facilitate the use of an

    alphanumeric HD44780-based LCD for use in circuits, supporting simple functions for transferring

    characters, strings and numbers at desired positions on the LCD, in 4-bit mode.

    Another interesting use of the Core Timer would be as a central clock/device for time-keeping.

    The Core Timer can be thought of as a sixthalbeit stripped down32-bit timer in the PIC32 and it can

    be always kept running in the background. Additionally, it increments every two clock cycles (System

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 6of 15

    clock cycles) and has compare and interrupt capability. So, this makes the Core Timer simple to use as a

    background time-keeping devicefor example to manage multi-tasking or multiple task scheduling in a

    simple code or operating system. A simple example would be the implementation of an Earliest

    Deadline First (EDF) RTOS similar to the Tiny Real Time (for the Atmel ATmega series of microcontrollers)

    OS that is currently used in the ECE 4760 course at Cornell University.

    Following this thought, the idea of an RTOS interested me for a few days. I looked through

    existing PIC32 operating systems and saw there are a good few available. However, I realized that I did

    not have much use for an RTOS right now and thus did not invest further time into learning to use an

    existing RTOS.

    32-BIT TIMER

    The PIC32MX250F128B has five 16-bit timers (ignoring the Core Timer). These are timers 1, 2, 3,

    4 and 5. Timer 2 and timer 3 can be combined to create a 32-bit timer; so can timer 4 and timer 5. This isstraightforward to do since setting timer 2/3 or timer 4/5 as a 32-bit timer requires the setting of just

    one bit in the control register T2CON or T4CON. Timer 2 and timer 4 are the master timers for the timer

    2/3 and 4/5 respectively. Timer 3 and timer 5 are the slave timers. Timer 2 and timer 4 settings

    configure the 32-bit timers 2/3 and 4/5 respectively. Timer 3 and timer 5 interrupt settings configure the

    interrupt settings for timers 2/3 and 4/5 respectively. The period register for timer 2/3 and timer 4/5 are

    PR2 and PR4 respectively.

    Setting up the 32-bit timers and using them are straightforward. I did a simple test to blink LEDs

    by using the 32-bit timer interrupts. Additionally, I used a 32-bit time base for the capacitance meter I

    constructed (I talk about this later).

    FURTHER I/O

    For another simple test of the IO, I wrote a simple matrix keypad library for personal use for a

    4x4 keypad. While this is straight forward, it served as a simple demonstration of the use of the IO

    module of the PIC32MX250F128B, which despite being quite simple is fairly powerful due to features

    such as selectable pull-ups and pull-downs, configurable open-drain outputs and 5V tolerance on certain

    pins. In this code, I accessed the individual port bits as such:

    PORTAbits.RA2 for accessing port for reading

    LATAbits.LATA3 for accessing port latch for writing

    This demonstrated another way of accessing individual bits of the ports instead of using (for

    write) the SET, CLR or INV registers (PORTASET, PORTACLR, PORTAINV for example). However, upon

    inspecting the output assembly, it was obvious that this method of port access was not efficient (too

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 7of 15

    many lines of assembly code needed) especially compared to the very efficient SET, CLR and INV

    registers which allow atomic bitwise manipulation of the ports and efficiently and consistently [3 lines

    of assembly code were required for every SET, CLR or INV operation/assignment].

    DAC WITH ANALOG COMPARATOR REFERENCE MODULE

    Beyond the IO, the PIC32 provides a plethora of peripherals with a horde of features. This also

    means that this allows one to hack the multitude of features to use a certain peripheral for a way

    beyond what was initially its target use.

    A simple example of such a scenario would be to use the internal comparator voltage reference

    module as a simple digital to analog converter (DAC). The comparator voltage reference module had

    two voltage ranges, each with 16 user selectable voltages. That makes a nice 4-bit DAC. The two ranges

    with all 32 values cannot be used as a 5-bit DAC due to the non-linearity of voltages between the two

    ranges (selecting voltages from either range from minimum to maximum possible). While the idea forthis was brought up last semester, I had not gotten around to testing how fast I can get reliable

    conversions out of this. Continuing from where I left off last semester, writing a simple conversion code

    and testing speed showed, interestingly, that this DAC can be used quite nicely at 100kHz. I have not

    tested beyond that since 100kHz with such a simple hack is nice and easily usable in a lot of applications

    not requiring a great number of digital steps. A more detailed explanation of this, along with pictures of

    the waveforms I obtained while using this for testing can be found on my blog, at the following link:

    http://tahmidmc.blogspot.com/2014/04/hacking-pic32-comparator-reference-to.html

    Here is an oscilloscope waveform that clearly illustrates the non-linearity in using all 32 values

    for the output waveform (interleaved among the two ranges):

    http://tahmidmc.blogspot.com/2014/04/hacking-pic32-comparator-reference-to.htmlhttp://tahmidmc.blogspot.com/2014/04/hacking-pic32-comparator-reference-to.htmlhttp://tahmidmc.blogspot.com/2014/04/hacking-pic32-comparator-reference-to.html
  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 8of 15

    ADC

    The ADC is another peripheral that I had used last semester but did not get around to testing the

    performance ofmore specifically, the maximum attainable conversion speeds. The maximum specified

    analog to digital conversion frequency of 1MHz (1 million samples per second) at 10-bit resolution was

    easily attainable using the standard timing specifications laid out in the datasheet electricalcharacteristics section. Of note here is that the datasheet recommends using an external reference

    voltage supply for sampling frequencies in excess of 400kHz. Additionally, the ADC provides further

    performance with the availability of options such as channel scanning, repeated conversions, conversion

    clocking options (by Timer 3, CTMU, auto-convert, etc.), input offset calibration and interrupt selection

    (interrupt can be triggered at the end of each sample, at the end of every 2 samples, . at the end of

    every 16 samples).

    An interesting hurdle I ran into when testing the ADC conversion rate is that initially I couldnt

    get to the 1MHz mark even when I followed all the timing specifications laid out in the datasheet. This

    turned out to be due to the way I was measuring the number of conversions. I was doing this byincrementing a counter in the ISR and then displaying the counter value onto a 7-segment display after

    one second. However, the interrupt latency was a limiting factor here since the maximum interrupt rate

    possible was slower than the maximum ADC conversion rate. See INTERRUPT section.

    This was resolved by changing an ADC interrupt setting from interrupt at the end of each

    sample to interrupt at the end of every 8 samplesand then multiplying the final counter value by 8.

    Since I was interested in the value of the counter variable to the nearest thousand, the error introduced

    by taking readings every 8 conversions and multiplying (since I might miss a few because of the last

    interrupt being after the timer interrupt which had a higher interrupt priority; the ADC was disabled in

    the timer interrupt) was insignificant.

    DMA

    A further huge part of the PIC32 that adds to its power is the DMA controller. Having never

    worked on DMA before, it took me a while to understand the concept of DMA and use it in the PIC32.

    However, once I got to that, setting up the DMA controller for DMA transfers was straightforward. I did

    my testing with low level register access available here:

    http://tahmidmc.blogspot.com/2014/05/simple-pic32-dma-example.html

    Something that I found very interesting is that the DMA controller/module maintains its own

    flags for detecting interrupt requests for data transfer start/abort requests. This is completely

    independent of the INT interrupt controller enable and flag settings/configuration.

    The results observed using DMA for single byte transfers and DMA bursts at different priority

    settings present an interesting picture of the DMA module. The DMA module has four channels with

    selectable priority. It is interesting to note here that the four channels cannot be used to transfer data

    http://tahmidmc.blogspot.com/2014/05/simple-pic32-dma-example.htmlhttp://tahmidmc.blogspot.com/2014/05/simple-pic32-dma-example.htmlhttp://tahmidmc.blogspot.com/2014/05/simple-pic32-dma-example.html
  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 9of 15

    concurrently. Different priority level settings dictate which DMA channel transfers data before

    another/others. Having the same priority level for multiple channels yields another interesting

    observation. Each channel has a natural priority associated with it but this does not act in the same

    way as the manually selectable transfers. The DMA controller selects the channel with the higher natural

    priority and transfers one 32-bit word data; then the next channel (that has a lower natural priority but

    the same user-selected priority level) is selected for a 32-bit word transfer. The DMA controller cycles

    through the multiple channels at the same user selectable priority and keeps on transferring a single 32-

    bit word on the channel with the highest natural priority before moving on to the next channel (with a

    lower natural priority) and so on until the block transfer is complete (all data is transferred).

    From here, I plan to do further experiments with the DMA module, specifically to use the DMA

    module for transferring data in a circuit for VGA display interfacing with the PIC32MX250F128B. I was

    planning to do this near the end of the semester but could not due to a lack of time. This is still

    something I want to do in my own time and so will probably work on it over the summer for myself.

    PWM

    I tested the compare module out by writing a simple code that used the compare module for

    pulse width modulation to drive a DC motor for open loop speed control. The duty cycle was displayed

    on a 3-digit 7 segment display. I interfaced the PIC32MX250F128B with a 3-digit 7 segment display as a

    demonstration of IO interfacing (with 7 segment displays) along with timer application and interrupt

    usage.

    Another simple test of PWM was a simple code for DDS to generate a sine wave output. Using a

    software-generated sine table, the compare module was used for the PWM while a simple RC low passfilter was used to obtain the sine wave output. After testing the DMA module, another channel of

    thought for analog waveform generation was opened. The most straightforward method is to use a DAC

    to output the analog voltages as required. Another common method is to use the PWM module as I

    spoke of above (DDS). The DMA module enables analog (arbitrary) waveform generation using both the

    above methods, with the advantage that there is no CPU overhead. A timer interrupt can be used as the

    triggering source for the DMA channel. This timer can be made to interrupt at regular intervals. The

    DMA channel could then transfer data from a source array/table to the PWM duty cycle register (for

    DDS) or the analog comparator reference module (simple DAC) or to a PORT where a DAC can be used to

    convert the digital signals from the PORT to the required analog levels.

    To summarize, there were no surprises when using the PWM module. The behavior is exactly as

    described and following the procedures laid out in the datasheet and the reference manual, this is a

    simple module to get working. The availability of the double buffered duty cycle registers ensures that

    the PWM is glitch-free, allowing the change of duty cycle any time required since the hardware takes

    care of the duty cycle update as required, at the end of the period.

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 10of 15

    A further use I put the PWM module in was in audio playback. Essentially, the concept is the use

    of DDS. I initially used no compression. I used a piece of computer software (Audacity) to convert WAV

    files to 8-bit WAV. Then, I used a piece of software (WAV2C) that I got from the internet that converted

    the 8-bit WAV file to a C header file containing the raw PCM data (a large array with 8-bit byte/unsigned

    character elements). This was stored in FLASH (by making the array a constant array). The C header file

    also had, as a comment, the required sampling frequency. This, I set to be the timer interrupt frequency

    (frequency of PWM). The PCM data was the duty cycle information every timer interrupt, the PWM

    duty cycle was updated with the next value in the table. This was output on to a pin where a low-pass

    filter was used before passing the signal onto the output (headphones or audio amplifier into speaker).

    I later tried using ADPCM, for compression, so that the PIC flash could be used to hold a larger

    amount of audio. However, I could not successfully implement this, as I could not wrap my head around

    the ADPCM algorithm. This remains one of the projects I wish to expand upon soon and complete (a

    project for myself).

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 11of 15

    INTERRUPT

    The PIC32 offers a versatile interrupt controller with user selectable interrupt priority levels

    (seven to be exact) and sub-priority levels (four selectable). Getting the interrupts to work was fairly

    simple and I had managed to do that last semester.

    What I hadnt gotten around to testing previously was the interrupt latency.

    To test the interrupt latency what I had done was to set up a timer for a 1 second interrupt.

    This was given the highest priority7. That means that the shadow register set should be used for this

    interrupt. Then I had the ADC set to interrupt upon a conversion (the ADC was given a lower interrupt

    priority 6). In the ADC ISR, the timer interrupt was enabled. However, the ADC result buffer was not

    read; neither was the ADC interrupt flag cleared. So, as soon as the PIC exited the ISR, the ISR was

    reentered. After one second, when the timer interrupted, the ADC interrupt was disabled. Initially, an

    ADC conversion was manually triggered to start everything off. In the ADC ISR, a counter variable was

    incremented. When the ADC interrupt was disabled after a second, the counter variable was displayed

    on a 3-digit 7 segment display to display the top 3 decimal digits (the program ensured that the

    counter variable value was less than 1 million). I got a reading of 385 indicating a value between

    385,000 and 386,000. The PIC was running at 30MHz. Rounded down, there were 385,000 interrupts in a

    second.

    The ADC interrupt is persistent. This means that the interrupt remains active and its interrupt

    flag also stays set until the source causing it is resolved. In the case of the ADC, this is the ADC

    conversion and to clear the interrupt and make it inactive, the result buffer must be read. Since I did not

    do this and the ADC interrupt is persistent, the ISR kept being re-executed as it was exited. To properly

    make a persistent interrupt inactive, the interrupt source must be cleared (in case of the ADC, read the

    result buffer) before the interrupt flag is cleared. This ensures proper deactivation of the interrupt and

    proper clearing of the interrupt flag.

    The other type of interrupt is non-persistent interrupts. An example of this is the Timer

    interrupts. A complete list of all the interrupt sources along with the associated IRQ #, vector # and type

    of interrupt (persistent or not) can be found in the PIC32MX250F128B datasheet. A small section of this

    (taken from the datasheet) for demonstrating what I meant is:

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 12of 15

    This was just my preliminary test (to get an idea of interrupt latency) and I cannot guarantee

    that this is an accurate figure for a performance metric for the interrupt latency. This just gave me an

    idea of the kind of performance to expect.

    According to Professor Bruce Lands interrupt test (source:

    http://people.ece.cornell.edu/land/courses/ece4760/PIC32/), a timer interrupt test revealed an

    interrupt rate of about 780kHz (with the PIC running at 40MHz). Since this was the highest priority

    interrupt, this is possibly the figure for the performance when the shadow register set. Assuming that

    both the tests performed are correct, the use of the shadow register set provides about a 50%

    improvement in interrupt performance.

    CAPTURE AND ANALOG COMPARATOR MODULES: CAPACITANCE METER

    I used the capture module along with the analog comparator module to design a simple

    capacitance meter. The idea is to time how long it takes the capacitor voltage to rise to 2.37V and based

    on this, use the formula for capacitor charge to find the value of the capacitance. The capture module is

    used along with the 32-bit Timer 2/3 as the time base for the timing. The analog comparator module is

    used to detect the voltage level. The analog comparator output goes low when the capacitor voltage

    crosses 2.37V and this triggers the input capture module to record the timer value which is the

    http://people.ece.cornell.edu/land/courses/ece4760/PIC32/http://people.ece.cornell.edu/land/courses/ece4760/PIC32/http://people.ece.cornell.edu/land/courses/ece4760/PIC32/
  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 13of 15

    indication of the time (some software calculation required to convert to actual time). The input capture

    module was set to trigger upon a falling edge on the external event (shorted with C1OUT pin).

    The input capture module does not allow direct triggering from the analog comparator output

    internally. So, I used the fact that the analog comparator module allows the comparator output to be

    output to a port pin (C1OUT pin). This was then set as the pin that triggers the input capture.

    The 2.37V reference to the comparator (non-inverting/+ pin) was provided from the internal

    comparator reference module. The inverting pin (- in) of the comparator was provided to an external pin

    this was connected to the capacitor since this was checking the capacitor voltage against the internal

    reference.

    The capacitance was then displayed on a 16x2 alphanumeric LCD using the LCD library that I

    wrote.

    PERIPHERAL LIBRARY AND LOW-LEVEL ACCESS

    Microchip provides a nice peripheral library for its PIC32 series along with documentation of the

    associated functions and macros, as well as some sample code for using the library. The nice thing about

    the library is that the functions are relatively low-level.

    I did use the peripheral library in a few cases, eg the Core Timer configuration. However, for

    most cases, I decided to use low-level register access to get a complete understanding of the internal

    peripherals.

    However it must be noted that the peripheral library functions arent at a level where theperipherals can be used with almost no idea of the internal peripheral mechanisms (as I mentioned

    above)like in the Arduino for example where there are high-level libraries for almost everything.

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 14of 15

    TESTS WITH INTEL GALILEO

    The Intel Galileo was released as an Arduino compatible development board (as a supposedly

    faster Arduino). I received one from Professor Bruce Land and thought of testing it out. Its Arduino

    compatibility made it interesting especially since it had a 400MHz Quark SoC running it. Comparing it to

    the AT91SAM3X8E (in the Arduino Due) was going to be interesting.

    However, a short amount of testing with the Intel Galileo proved to be very disappointing,

    illustrating several shortcomings in terms of performance that made it difficult to compare even to a

    lower end Arduino (Arduino Uno), let alone an Arduino Due.

    Not all functions and libraries are supported on Galileo; eg. pulseIn function used toread pulse widths of input PWM signals. Additionally, doing so with low-level access to

    special function registers, if a hardware peripheral module to do this was even present,

    would be a big headache it wouldnt be as simple as for the AT91 with everything

    relatively well documented in the datasheet; additionally, this should not be necessary

    since it was marketed as being Arduino-compatible.

    A simple square wave toggling ran at around 74 Hz which is pathetically slow. This isbecause the Arduino is emulated on the Linux OS on the Galileo additionally, the IO

    pins are through an I2C port expander. No pin toggling speed test was performed on the

    AT91 as its quite obvious that theres no way the AT91 is that slow.

    Alternatively, there is supposedly a fast modefor IO, a command can be sent to theGalileo for the specific I/O pin - this is done through the PCI port. However, even at fast

    mode, the maximum claimed toggle frequency is 2.3MHz.

    Cannot use external voltage reference (AREF) for analog-to-digital converter (ADC). The5V reference varies way too much to use for applications requiring precise ADCmeasurements (the 5V supply was observed to drop to 4.8V during testing).

    The ADC has a much lower impedance tolerance than the Arduinos ADC (a 10kpotentiometer gave us bad readings)to fix this might require a buffer. The AT91 ADC

    operates perfectly fine with a 10k variable resistor used as a test voltage divider.

    Physical touching of components near circuit caused the Linux kernel to crash, forcing usto manually reset the board (or even re-upload code as has happened once) to continue

    operations.

    Some of these tests were performed individually while some of the others were performed

    together with other members of the Cornell Cup team. It is possible that there have been updates to theIntel Galileo platform to overcome or improve upon these drawbacks. However, these are personal test

    results from about midway through the semester that discouraged me from using the Intel Galileo.

  • 5/25/2018 A further study into the use of the PIC32MX250F128B, with side projects using the AT9...

    http:///reader/full/a-further-study-into-the-use-of-the-pic32mx250f128b-with-side-pr

    Page 15of 15

    FURTHER EXPANSION

    I plan on personally using the PIC32 regularly for circuits for myself and in real world

    applications. Over the summer, I will be working on products such as sine wave inverters, MPPT solar

    charge controllers, AC voltage stabilizers and battery chargers. For these, I plan to use the

    PIC32MX250F128B due to the processing power and peripheral flexibility it provides. These will

    incorporate aspects of the PIC32MX250F128B I have learned and experimented with during my

    independent study and will be the culmination of my learning during the independent study.

    Additional to these, I have certain projects I am interested in doing just for fun. These include

    interfacing the PIC to a VGA monitor, playing with audio (specifically ADPCM which I experimented a

    bit with during the semester but could not strongly grip), interfacing a graphic TFT display (obtained

    from Adafruit the same one I used with the Arduino Due) with the PIC and possibly making a small

    oscilloscope with the PIC, and DC-DC switching regulators based on the PIC. Again, these will all expand

    on concepts I have learned over the course of my independent study.

    Finally, I plan on providing more information on the PIC32 peripherals (as learnt from my

    independent study) and my projects, on my blog. This includes documentation of the various peripherals

    I have used along with the sample code I have used for my independent study, along with required

    explanations. Due to a lack of time, I could not do so over the semester and will thus now put these up

    on my blog as the semester is now over and I have a bit more free time.

    ACKNOWLEDGEMENT

    I would like to thank Professor Bruce Land for his advice, help and support during the entirety ofthe period of my independent study and of my freshman year at Cornell University.