Difference between revisions of "ME333 Sample Code"
NickMarchuk (talk | contribs) |
|||
(49 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
== A Crash Course in C == |
|||
'''Section A.1''': [[Media:CCCHelloWorld.c|HelloWorld.c]] |
|||
'''Section A.4''': [[Media:CCCprintout.c|printout.c]], [[Media:CCCdatasizes.c|datasizes.c]], [[Media:CCCoverflow.c|overflow.c]], [[Media:CCCtypecast.c|typecast.c]], [[Media:CCCinvest.c|invest.c]] |
|||
'''Section A.4.16''': [[Media:CCChelper.h|helper.h]], [[Media:CCChelper.c|helper.c]], [[Media:CCCmain.c|main.c]] |
|||
'''Problems, Section A.5''': [[Media:CCCbubble.c|bubble.c]], [[Media:CCClights.c|lights.c]], [[Media:CCChexdump.c|hexdump.c]] |
|||
== Chapter 1 - Quickstart == |
|||
[[Media:simplePIC.c|simplePIC.c]], [[Media:simplePIC_standalone.c|simplePIC_standalone.c]], [[Media:talkingPIC.c|talkingPIC.c]], [[Media:NU32bootloaded.ld|NU32bootloaded.ld]], [[Media:NU32.c|NU32.c]], [[Media:NU32.h|NU32.h]] |
|||
== Chapter 3 - Looking Under The Hood: Software == |
|||
Problem 6: [[Media:Ch3_makefile.txt|makefile]] (save as "makefile"; make sure there is no .txt extension) |
|||
== Chapter 4 - Using Libraries == |
|||
[[Media:Ch4_code.zip|All Chapter 4 code (zip)]] |
|||
-> LCD code, has a bug |
|||
== Chapter 5 - Time and Space == |
|||
[[Media:Ch5_timing.c|timing.c]] |
|||
-> add a timing.c with coreTimer? |
|||
== Chapter 6 - Interrupts == |
|||
[[Media:Ch6_code.zip|All Chapter 6 code (zip)]] |
|||
-> these are all plib, check all or change to registers, some plib fns did not work last year |
|||
== Chapter 7 - Digital Input and Output == |
|||
[[Media:Ch7_code.zip|All Chapter 7 code (zip)]] |
|||
== Chapter 8 - Counters / Timers == |
|||
[[Media:Ch8_code.zip|All Chapter 8 code (zip)]] |
|||
== Chapter 9 - Output Compare == |
|||
[[Media:Ch9_code.zip|All Chapter 9 code (zip)]] |
|||
== Chapter 10 - Analog Input == |
|||
[[Media:Ch10_code.zip|All Chapter 10 code (zip)]] |
|||
== Chapter 11 - UART == |
|||
[[Media:Ch11_code.zip|All Chapter 11 code (zip)]] |
|||
== Chapter 12 - SPI Communication == |
|||
[[Media:Ch12_code.zip|All Chapter 12 code (zip)]] |
|||
== Chapter 13 - I2C Communication == |
|||
[[Media:Ch13_code.zip|All Chapter 13 code (zip)]] |
|||
== Chapter 14 - USB == |
|||
[[Media:Ch14_code.zip|All Chapter 14 code (zip)]] |
|||
== Chapter 15 - Input Capture == |
|||
[[Media:Ch15_code.zip|All Chapter 15 code (zip)]] |
|||
== Chapter 16 - Comparator == |
|||
[[Media:Ch16_code.zip|All Chapter 16 code (zip)]] |
|||
== Chapter 17 - Watchdog Timer == |
|||
[[Media:Ch17_code.zip|All Chapter 17 code (zip)]] |
|||
== Chapter 18 - Storing Data in Flash Memory == |
|||
[[Media:Ch18_code.zip|All Chapter 18 code (zip)]] |
|||
== Chapter 19 - Power Saving: Sleep, Idle, and Freeze == |
|||
[[Media:Ch19_code.zip|All Chapter 19 code (zip)]] |
|||
== Chapter 20 - Real-time Clock and Calendar == |
|||
[[Media:Ch20_code.zip|All Chapter 20 code (zip)]] |
|||
== Chapter 21 - Controller Area Network (CAN) == |
|||
[[Media:Ch21_code.zip|All Chapter 21 code (zip)]] |
|||
== Chapter 22 - Direct Memory Access == |
|||
[[Media:Ch22_code.zip|All Chapter 22 code (zip)]] |
|||
== Chapter 23 - Sensors and Signal Conditioning == |
|||
[[Media:Ch23_code.zip|All Chapter 23 code (zip)]] |
|||
== Chapter 24 - Digital Signal processing == |
|||
[[Media:Ch24_code.zip|All Chapter 24 code (zip)]] |
|||
== Chapter 25 - Brushed Permanent Magnet DC Motors == |
|||
[[Media:Ch25_code.zip|All Chapter 25 code (zip)]] |
|||
== Chapter 26 - DC Motor Control == |
|||
[[Media:Ch26_code.zip|All Chapter 26 code (zip)]] |
|||
== Chapter 27 - Brushless Motor Control == |
|||
[[Media:Ch27_code.zip|All Chapter 27 code (zip)]] |
|||
== Chapter 28 - Stepper Motors and RC Servos == |
|||
[[Media:Ch28_code.zip|All Chapter 28 code (zip)]] |
|||
== Chapter 29 - Connecting to an Android Device == |
|||
[[Media:Ch29_code.zip|All Chapter 29 code (zip)]] |
|||
== Final Project == |
|||
* [[Media:NU32_to_dsPIC_example.c|NU32_to_dsPIC_example.c]] Reading an encoder with the dsPIC breakout board |
|||
* [[Media:dsPIC.c|dsPIC.c]] dsPIC support files |
|||
* [[Media:dsPIC.h|dsPIC.h]] dsPIC support files |
|||
* [[Media:DesiredTrajectory.h|DesiredTrajectory.h]] Desired Trajectory for Part 8 and 9 |
|||
== OLD PIC32 Code == |
|||
'''DIP PIC32 with reconfigurable pins (1/2xx)''' (11/21) |
|||
* Reconfiguring the pins. |
|||
'''Simple PIC''' |
'''Simple PIC''' |
||
Line 9: | Line 154: | ||
* [[Media:procdefs.ld|procdefs.ld]]: Linker file for NU32. |
* [[Media:procdefs.ld|procdefs.ld]]: Linker file for NU32. |
||
* [[Media:NU32_serial_comm.c|NU32_serial_comm.c]]: Serial communication test with the terminal. |
* [[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. |
|||
''' |
'''Interrupts''' |
||
* [[Media:INT_core_timer.c|INT_core_timer.c]]: Interrupt on core timer period match. |
|||
* [[Media:ADC_Read2.c|ADC_Read2.c]]: Reads two analog inputs repetitively and prints the results to the user's terminal. |
|||
* [[Media: |
* [[Media:INT_ext_int.c|INT_ext_int.c]]: Interrupt on rising edge of external interrupt line INT0. |
||
* Peripheral timer interrupt. |
|||
'''Digital I/O''' |
'''Digital I/O''' |
||
Line 20: | Line 167: | ||
* [[Media:DIGI0_plib.c|DIGIO_plib.c]]: Digital I/O and change notification using the peripheral library. |
* [[Media:DIGI0_plib.c|DIGIO_plib.c]]: Digital I/O and change notification using the peripheral library. |
||
''' |
'''Counter/timer''' |
||
* [[Media: |
* [[Media:TMR_16bit.c|TMR_16bit.c]]: Set up a 16-bit timer to count the PBCLK. |
||
* [[Media: |
* [[Media:TMR_16bit_external_clocks.c|TMR_16bit_external_clocks.c]]: Count two external clock sources, such as the A and B channel from a motor encoder. |
||
'''LCD code''' |
|||
* [[Media:LCD.c|LCD.c]]: LCD library. |
|||
* [[Media:LCD.h|LCD.h]]: LCD header file. |
|||
* [[Media:LCDtest.c|LCDtest.c]]: Test program for LCD library. |
|||
'''Output compare (PWM)''' |
'''Output compare (PWM)''' |
||
Line 37: | Line 178: | ||
* [[Media:OC_square_wave.c|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. |
* [[Media:OC_square_wave.c|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''' (11/16) |
|||
'''Counter/timer''' |
|||
* [[Media:ADC_Read2.c|ADC_Read2.c]]: Reads two analog inputs repetitively and prints the results to the user's terminal. |
|||
* [[Media:ADC_Read2_LCD.c|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 == |
|||
* [[Media:TMR_16bit.c|TMR_16bit.c]]: Set up a 16-bit timer to count the PBCLK. |
|||
* [[Media:TMR_16bit_external_clocks.c|TMR_16bit_external_clocks.c]]: Count two external clock sources, such as the A and B channel from a motor encoder. |
|||
'''DSP and FFT''' |
|||
* [[Media:DSP_sample_square_wave.zip|DSP_sample_square_wave.zip]]: Examples of FIR and FFT in both MATLAB and on the PIC32. |
|||
* [[Media:DSP_mips32_fft.zip|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''' |
|||
* [[Media:NU32_dsPIC_QEI_example.c | NU32_dsPIC_QEI_example.c]]: Read the encoder count at 250Hz, send to the computer at 5Hz |
|||
'''Controlling a stepper motor with the TB6612''' |
|||
* [[Media:NU32_stepper_example.c | NU32_stepper_example.c]]: Use the TB6612 to step the motor at 25 Hz steps (1 rev in 16s) |
|||
'''Controlling an RC servo motor''' |
|||
* [[Media:NU32_rcservo_pwm_example.c|NU32_rcservo_pwm_example.c]]: Use a PWM pin to set the position of the servo (note you only have 5 PWM pins) |
|||
* [[Media:NU32_rcservo_digio_example.c|NU32_rcservo_digio_example.c]]: Use any digital IO pin and a timer to set the position of the servo |
Latest revision as of 14:31, 2 December 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 - Quickstart
simplePIC.c, simplePIC_standalone.c, talkingPIC.c, NU32bootloaded.ld, NU32.c, NU32.h
Chapter 3 - Looking Under The Hood: Software
Problem 6: makefile (save as "makefile"; make sure there is no .txt extension)
Chapter 4 - Using Libraries
-> LCD code, has a bug
Chapter 5 - Time and Space
-> add a timing.c with coreTimer?
Chapter 6 - Interrupts
-> these are all plib, check all or change to registers, some plib fns did not work last year
Chapter 7 - Digital Input and Output
Chapter 8 - Counters / Timers
Chapter 9 - Output Compare
Chapter 10 - Analog Input
Chapter 11 - UART
Chapter 12 - SPI Communication
Chapter 13 - I2C Communication
Chapter 14 - USB
Chapter 15 - Input Capture
Chapter 16 - Comparator
Chapter 17 - Watchdog Timer
Chapter 18 - Storing Data in Flash Memory
Chapter 19 - Power Saving: Sleep, Idle, and Freeze
Chapter 20 - Real-time Clock and Calendar
Chapter 21 - Controller Area Network (CAN)
Chapter 22 - Direct Memory Access
Chapter 23 - Sensors and Signal Conditioning
Chapter 24 - Digital Signal processing
Chapter 25 - Brushed Permanent Magnet DC Motors
Chapter 26 - DC Motor Control
Chapter 27 - Brushless Motor Control
Chapter 28 - Stepper Motors and RC Servos
Chapter 29 - Connecting to an Android Device
Final Project
- NU32_to_dsPIC_example.c Reading an encoder with the dsPIC breakout board
- dsPIC.c dsPIC support files
- dsPIC.h dsPIC support files
- DesiredTrajectory.h Desired Trajectory for Part 8 and 9
OLD 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.
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