Difference between revisions of "ME333 Sample Code"

From Mech
Jump to navigationJump to search
Line 37: Line 37:
* [[Media:ADC_Read2_LCD.c|ADC_Read2_LCD.c]] Reads two analog inputs repetitively and prints the results to the LCD.
* [[Media:ADC_Read2_LCD.c|ADC_Read2_LCD.c]] Reads two analog inputs repetitively and prints the results to the LCD.


'''Using the UART'''
'''Using the UART''' (9/14)
* Simple RS232 communication: one UART to another on the same PIC
* Simple RS232 communication: one UART to another on the same PIC
* Simple RS232 communication: PIC to PIC
* Simple RS232 communication: PIC to PIC
Line 43: Line 43:
* Talking to a PC with an FTDI cable
* Talking to a PC with an FTDI cable


'''Using SPI'''
'''Using SPI''' (9/19)
* SPI1 to SPI2 on one PIC
* SPI1 to SPI2 on one PIC
* PIC to PIC
* PIC to PIC
Line 50: Line 50:
* Microchip 23k256 256kbit SPI SRAM
* Microchip 23k256 256kbit SPI SRAM


'''Using I2C'''
'''Using I2C''' (9/28)
* I2C1 to I2C2 on one PIC
* I2C1 to I2C2 on one PIC
* PIC to PIC
* PIC to PIC
Line 57: Line 57:
* PCF8570 2kbit I2C SRAM
* PCF8570 2kbit I2C SRAM


'''USB'''
'''USB''' (9/24)
* HID to Processing on a PC
* HID to Processing on a PC
* CDC to PC
* CDC to PC


'''Input Capture'''
'''Input Capture''' (10/12)
* create a PWM signal (duty cycle controlled by a potentiometer) and read in to an input capture, display the pulse width or duty cycle
* create a PWM signal (duty cycle controlled by a potentiometer) and read in to an input capture, display the pulse width or duty cycle


'''Comparator'''
'''Comparator''' (10/5)
* turn a light on or off based on potentiometer reading
* turn a light on or off based on potentiometer reading
* 16-value analog output?
* 16-value analog output?


'''Watchdog Timer'''
'''Watchdog Timer''' (10/16)
* 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)
* 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)


'''Programming the onboard flash'''
'''Programming the onboard flash''' (10/26)
* 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
* 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'''
'''Sleep, Idle, Freeze''' (11/2)
* config bits?
* 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?)
* 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 the RTCC'''
'''Using the RTCC''' (10/19)
* Keeping time: set time from a PC, display current time on same PC
* Keeping time: set time from a PC, display current time on same PC
* alarm clock demo?
* alarm clock demo?


'''Using CAN'''
'''Using CAN''' (11/9)
* 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)
* 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)
* some CAN chip? sensor?
* some CAN chip? sensor?

Revision as of 10:49, 11 September 2012

Simple PIC

  • simplePIC.c: Flashes LEDs on the NU32 unless the USER button is pressed.

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

Interrupts

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

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.

Using the UART (9/14)

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

Using SPI (9/19)

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

Using I2C (9/28)

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

USB (9/24)

  • HID to Processing on a PC
  • CDC to PC

Input Capture (10/12)

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

Comparator (10/5)

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

Watchdog Timer (10/16)

  • 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)

Programming the onboard flash (10/26)

  • 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 (11/2)

  • 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 the RTCC (10/19)

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

Using CAN (11/9)

  • 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)
  • some CAN chip? sensor?

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

LCD code

Data logging on a uSD card

  • Using the Microchip FAT32 library, AN1045