Difference between revisions of "ME333 Sample Code"

From Mech
Jump to navigationJump to search
Line 11: Line 11:
* [[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.


'''Analog to digital'''


'''Interrupts'''
* [[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.
* [[Media:INT_core_timer.c|INT_core_timer.c]]: Interrupt on core timer period match.
* [[Media:INT_ext_int.c|INT_ext_int.c]]: Interrupt on rising edge of external interrupt line INT0.


'''Digital I/O'''
'''Digital I/O'''
Line 21: Line 22:
* [[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.


'''Interrupts'''
'''Counter/timer'''


* [[Media:INT_core_timer.c|INT_core_timer.c]]: Interrupt on core timer period match.
* [[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.
* [[Media:INT_ext_int.c|INT_ext_int.c]]: Interrupt on rising edge of external interrupt line INT0.


'''LCD code'''
'''LCD code'''
Line 38: Line 39:
* [[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.


'''Counter/timer'''
'''Analog to digital'''


* [[Media:TMR_16bit.c|TMR_16bit.c]]: Set up a 16-bit timer to count the PBCLK.
* [[Media:ADC_Read2.c|ADC_Read2.c]]: Reads two analog inputs repetitively and prints the results to the user's terminal.
* [[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.
* [[Media:ADC_Read2_LCD.c|ADC_Read2_LCD.c]] Reads two analog inputs repetitively and prints the results to the LCD.

'''Using RS232'''
* Simple UART communication
* UART with hardware flow control

'''Using SPI'''
* MCP4922 12bit SPI DAC
* MCP3008 10bit SPI ADC
* Microchip 23k256 256kbit SPI SRAM

'''Using I2C'''
* MAX518 8bit I2C DAC
* NAU7802 24bit I2C ADC
* PCF8570 2kbit I2C SRAM

'''Programming the on board flash'''
* Flash self programming

'''Using the RTCC'''
* Keeping time

'''Using CAN'''
* Creating a CAN bus

'''Applications'''


'''DSP and FFT'''
'''DSP and FFT'''
Line 57: Line 83:
* [[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
* [[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


'''Using RS232'''
* Simple UART communication
* UART with hardware flow control


'''Using I2C'''
* MAX518 8bit I2C DAC
* NAU7802 24bit I2C ADC
* PCF8570 2kbit I2C SRAM

'''Using SPI'''
* MCP4922 12bit SPI DAC
* MCP3008 10bit SPI ADC
* Microchip 23k256 256kbit SPI SRAM

'''Using CAN'''
* Creating a CAN bus


'''Data logging on a uSD card'''
'''Data logging on a uSD card'''
* Using the Microchip FAT32 library, AN1045
* Using the Microchip FAT32 library, AN1045

'''Programming the on board flash'''
* Flash self programming

'''Using the RTCC'''
* Keeping time

Revision as of 13:56, 16 August 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

LCD code

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 RS232

  • Simple UART communication
  • UART with hardware flow control

Using SPI

  • MCP4922 12bit SPI DAC
  • MCP3008 10bit SPI ADC
  • Microchip 23k256 256kbit SPI SRAM

Using I2C

  • MAX518 8bit I2C DAC
  • NAU7802 24bit I2C ADC
  • PCF8570 2kbit I2C SRAM

Programming the on board flash

  • Flash self programming

Using the RTCC

  • Keeping time

Using CAN

  • Creating a CAN bus

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


Data logging on a uSD card

  • Using the Microchip FAT32 library, AN1045