Difference between revisions of "ME333 Sample Code"
Line 16: | Line 16: | ||
Problem 6: [[Media:Ch3_makefile.txt|makefile]] (save as "makefile"; make sure there is no .txt extension) |
Problem 6: [[Media:Ch3_makefile.txt|makefile]] (save as "makefile"; make sure there is no .txt extension) |
||
== Chapter 4 == |
|||
[[Media:Ch4_LCD.h|LCD.h]], [[Media:Ch4_LCD.c|LCD.c]], [[Media:Ch4_LCDwrite.c|LCDwrite.c]] |
|||
== Chapter 5 == |
== Chapter 5 == |
||
[[Media:Ch5_timing.c|timing.c]] |
[[Media:Ch5_timing.c|timing.c]] |
||
== Chapter 6 == |
|||
[[Media:Ch6_INT_core_timer.c|INT_core_timer.c]], [[Media:Ch6_INT_ext_int.c|INT_ext_int.c]], [[Media:Ch6_INT_timing.c|INT_timing.c]] |
|||
== PIC32 Code == |
== PIC32 Code == |
Revision as of 13:03, 3 February 2013
A Crash Course in C
Section A.1: HelloWorld.c
Section A.4: printout.c, datasizes.c, overflow.c, typecast.c, invest.c
Section A.4.16: helper.h, helper.c, main.c
Problems, Section A.5: bubble.c, lights.c, hexdump.c
Chapter 1
simplePIC.c, simplePIC_standalone.c, talkingPIC.c, NU32bootloaded.ld, NU32.c, NU32.h
Chapter 3
Problem 6: makefile (save as "makefile"; make sure there is no .txt extension)
Chapter 4
Chapter 5
Chapter 6
INT_core_timer.c, INT_ext_int.c, INT_timing.c
PIC32 Code
DIP PIC32 with reconfigurable pins (1/2xx) (11/21)
- Reconfiguring the pins.
Simple PIC
- simplePIC.c: Flashes LEDs on the NU32 unless the USER button is pressed.
NU32 library, header file, procdefs, and terminal comm test
- NU32.c: NU32 board library.
- NU32.h: NU32 header file.
- procdefs.ld: Linker file for NU32.
- NU32_serial_comm.c: Serial communication test with the terminal.
- NU32_serial_plot.c: Plot data with serial communication in NU32_Utility.
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.
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
- TMR_16bit.c: Set up a 16-bit timer to count the PBCLK.
- TMR_16bit_external_clocks.c: Count two external clock sources, such as the A and B channel from a motor encoder.
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.
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
USB (9/24)
- HID to Processing on a PC
- CDC to PC
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
Comparator (10/5)
- turn a light on or off based on potentiometer reading
- 16-value analog output?
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
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)
Using the RTCC (10/19)
- Keeping time: set time from a PC, display current time on same PC
- alarm clock demo?
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 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)
- PC to PIC (Peak card?)
- some CAN chip? sensor?
Analog to digital (11/16)
- 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.
Applications
DSP and FFT
- DSP_sample_square_wave.zip: Examples of FIR and FFT in both MATLAB and on the PIC32.
- DSP_mips32_fft.zip: Example of using the Q31 mips library for FFT. Contains a C source file and a header file.
Reading a quadrature encoder with the dsPIC33FJ12MC201 breakout board
- NU32_dsPIC_QEI_example.c: Read the encoder count at 250Hz, send to the computer at 5Hz
Controlling a stepper motor with the TB6612
- NU32_stepper_example.c: Use the TB6612 to step the motor at 25 Hz steps (1 rev in 16s)
Controlling an RC servo motor
- NU32_rcservo_pwm_example.c: Use a PWM pin to set the position of the servo (note you only have 5 PWM pins)
- NU32_rcservo_digio_example.c: Use any digital IO pin and a timer to set the position of the servo
LCD code
Data logging on a uSD card
- Using the Microchip FAT32 library, AN1045