Difference between revisions of "ME333 Unofficial Sample Code"

From Mech
Jump to navigationJump to search
Line 19: Line 19:
* '''TESTED 1/15/2013''' [[Media:NU32.c|NU32.c]]: NU32 board library.
* '''TESTED 1/15/2013''' [[Media:NU32.c|NU32.c]]: NU32 board library.
* '''TESTED 1/15/2013''' [[Media:NU32.h|NU32.h]]: NU32 header file.
* '''TESTED 1/15/2013''' [[Media:NU32.h|NU32.h]]: NU32 header file.
* '''TESTED''' [[Media:app.ld|app.ld]]: Linker file for NU32.
* '''EDITS''' [[Media:NU32_serial_comm.c|NU32_serial_comm.c]]: Serial communication test with the terminal.
* '''EDITS''' [[Media:NU32_serial_comm.c|NU32_serial_comm.c]]: Serial communication test with the terminal.
* [[Media:NU32_serial_plot.c|NU32_serial_plot.c]]: Plot data with serial communication in NU32_Utility.
* [[Media:NU32_serial_plot.c|NU32_serial_plot.c]]: Plot data with serial communication in NU32_Utility.

Revision as of 22:08, 15 January 2013

Code for ME333 instructors to test before it goes live.

Code with TESTED has been tested and is ready to go live.

Code with EDITS has been updated but not fully test.

Code without any marking has not been looked at yet.


PIC32 Code

Simple PIC

  • TESTED 1/15/2013 simplePIC.c: Flashes LEDs on the NU32 unless the USER button is pressed.


NU32 library, header file, procdefs, and terminal comm test

  • TESTED 1/15/2013 talkingPIC.c: echoes strings sent from keyboard back to computer screen
  • TESTED 1/15/2013 NU32bootloaded.ld: Use this when creating executables to be bootloaded on NU32 (not app.ld).
  • TESTED 1/15/2013 NU32.c: NU32 board library.
  • TESTED 1/15/2013 NU32.h: NU32 header file.
  • EDITS NU32_serial_comm.c: Serial communication test with the terminal.
  • NU32_serial_plot.c: Plot data with serial communication in NU32_Utility.

LCD code (to be moved into NU32.c)

Serial Sample code for Invest.c

Communication Examples

  • Serial to a terminal
  • Serial to MATLAB
  • Serial to Processing
  • Output to the LCD

Digital I/O

  • DIGIO_sfrs.c: Digital I/O and change notification using SFR manipulation.
  • DIGIO_plib.c: Digital I/O and change notification using the peripheral library.

Counter/timer

Interrupts

  • INT_core_timer.c: Interrupt on core timer period match.
  • INT_ext_int.c: Interrupt on rising edge of external interrupt line INT0.
  • Peripheral timer interrupt.

Output compare (PWM)

  • OC_PWM_nolib.c: Set up PWM by setting SFRs.
  • OC_PWM_lib.c: Set up PWM using peripheral library functions.
  • OC_square_wave.c: Alternate between two different PWM duty cycles at 1 Hz. PWM is at 100 kHz and can be low-pass filtered to get a square wave analog output.

Analog to digital

  • ADC_Read2.c: Reads two analog inputs repetitively and prints the results to the user's terminal.
  • ADC_Read2_LCD.c Reads two analog inputs repetitively and prints the results to the LCD.
  • Something else, scanning mode, asynchronous results check on the buffer, and/or interrupt generated when some results are ready.

Using the UART

  • Simple RS232 communication: one UART to another on the same PIC
  • Uart_pic2pic.c: Simple RS232 communication: PIC to PIC
  • Uart_hfc.c: RS232 with hardware flow control
  • Talking to a PC with an FTDI cable

Using I2C

  • I2C1 to I2C2 on one PIC
  • PIC to PIC
  • MAX518 8bit I2C DAC
  • NAU7802 24bit I2C ADC
  • PCF8570 2kbit I2C SRAM

Using SPI

  • SPI1 to SPI2 on one PIC
  • PIC to PIC
  • MCP4922 12bit SPI DAC
  • MCP3008 10bit SPI ADC
  • Microchip 23k256 256kbit SPI SRAM

Comparator

  • turn a light on or off based on potentiometer reading
  • 16-value analog output?

Input Capture

  • create a PWM signal (duty cycle controlled by a potentiometer) and read in to an input capture, display the pulse width or duty cycle

Applications

DSP and FFT

Reading a quadrature encoder with the dsPIC33FJ12MC201 breakout board

Controlling a stepper motor with the TB6612

Controlling an RC servo motor


Extra PIC32 Code

USB

  • HID to Processing on a PC
  • CDC to PC

Watchdog Timer

  • Press a button every so often or watch the PIC reset itself (and perhaps a light stays off until you manually reset it or something)

Using the RTCC

  • Keeping time: set time from a PC, display current time on same PC
  • alarm clock demo?

Programming the onboard flash

  • Flash self programming: displays saved data at power on, allows user to enter new data (button presses, whatever), displays the new data, and when you power cycle, PIC displays the most recent data on startup

Sleep, Idle, Freeze

  • config bits?
  • demonstrate little current usage in sleep mode; wake up at predefined intervals or on certain signals and do something (and see the spike in current usage?)

Using CAN

  • Three PICs establishing a CAN bus: each PIC has a button and the state of the LEDs on each NU32 changes depending on which buttons are pressed (confirm communication between PICs)
  • PC to PIC (Peak card?)
  • some CAN chip? sensor?

DIP PIC32 with reconfigurable pins (1/2xx) (11/21)

  • Reconfiguring the pins.

Data logging on a uSD card

  • Using the Microchip FAT32 library, AN1045