Difference between revisions of "NU32: Using the dsPIC33FJ12MC201 QEI to SPI board"

From Mech
Jump to navigationJump to search
 
(8 intermediate revisions by one other user not shown)
Line 1: Line 1:
'''THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT [[NU32|THE NU32 PAGE]].'''


Using the dsPIC33FJ12MC201 breakout board for quadrature decoding.
Using the dsPIC33FJ12MC201 breakout board for quadrature decoding.


Line 5: Line 8:
== Overview ==
== Overview ==


[[Media:dsPIC33FJ12MC201.pdf|Datasheet]]
[[Media:dsPIC33FJ12MC201.pdf|Datasheet]], [http://ww1.microchip.com/downloads/en/devicedoc/93002A.pdf Specifics on the QEI module]


The dsPIC series of PIC microcontrollers are inexpensive 16 bit microcontrollers, specializing in the ability do fast digital signal processing.
The dsPIC series of PIC microcontrollers are inexpensive 16 bit microcontrollers, specializing in the ability do fast digital signal processing.
Line 13: Line 16:
== Details ==
== Details ==
The breakout board has been pre-programmed to read a quadrature signal on pins RP7 and RP8 (pins 11 and 12). It will keep track of the net motion of the encoder as a 16 bit integer, initializing to 32767. The dsPIC will report the 16 bit unsigned number over SPI communication when a '1' is sent.
The breakout board has been pre-programmed to read a quadrature signal on pins RP7 and RP8 (pins 11 and 12). It will keep track of the net motion of the encoder as a 16 bit integer, initializing to 32767. The dsPIC will report the 16 bit unsigned number over SPI communication when a '1' is sent.

[[Image:NU32_dsPIC33FJ12MC201_sch.png|thumb|500px|The dsPIC33FJ12MC201 breakout board schematic|center]]

== Wiring ==

[[Image:NU32_dsPIC33FJ12MC201_wireup.png|thumb|400px|How to connect the dsPIC33FJ12MC201 breakout board to the PIC32|center]]


== Library Functions ==
== Library Functions ==
[[Media:NU32_dsPIC_QEU_example.zip | This code]] is an example of how to read the encoder count using the NU32.
[[Media:NU32_dsPIC_QEI_example.c | This code]] is an example of how to read the encoder count using the NU32.


The functions are:
The functions are:
*void NU32_dsPIC_initialize(void) - enables SPI4 as master at 8MHz
*void initEncoderSPI(void) - enables SPI4 as master at 8MHz
*int NU32_dsPIC_getCount(void) - sends a '1' to the dsPIC, returns the value returned by the dsPIC
*int getEncoder(void) - sends a '1' to the dsPIC, returns the value returned by the dsPIC


NU32_dsPIC_Example.c in the .zip file above demonstrates how to use the breakout board.
NU32_dsPIC_Example.c above demonstrates how to use the breakout board.


== Sample Code ==
== Sample Code ==


To initialize the SPI communication, call NU32_dsPIC_initialize(), :
To initialize the SPI communication, call initEncoderSPI(), :


<pre>
<pre>
initEncoderSPI();
NU32_dsPIC_initialize();
</pre>
</pre>


To read the encoder count, call NU32_dsPIC_getCount(), :
To read the encoder count, call getEncoder(), :


<pre>
<pre>
int count = NU32_dsPIC_getCount();
int count = getEncoder();
</pre>
</pre>



Latest revision as of 05:35, 16 January 2016

THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT THE NU32 PAGE.


Using the dsPIC33FJ12MC201 breakout board for quadrature decoding.

The dsPIC33FJ12MC201 breakout board

Overview

Datasheet, Specifics on the QEI module

The dsPIC series of PIC microcontrollers are inexpensive 16 bit microcontrollers, specializing in the ability do fast digital signal processing.

The dsPIC33FJ12MC201 is a low pin count chip that runs on 3.3V at 80MHz without an external oscillator. It has the ability to remap peripheral functionality to any pins (labeled RPx). It also has a special peripheral called QEI, or Quadrature Encoder Interface. The QEI module receives the quadrature square waves from an encoder and keeps track of the net motion of the encoder as a 16 bit unsigned integer.

Details

The breakout board has been pre-programmed to read a quadrature signal on pins RP7 and RP8 (pins 11 and 12). It will keep track of the net motion of the encoder as a 16 bit integer, initializing to 32767. The dsPIC will report the 16 bit unsigned number over SPI communication when a '1' is sent.

The dsPIC33FJ12MC201 breakout board schematic

Wiring

How to connect the dsPIC33FJ12MC201 breakout board to the PIC32

Library Functions

This code is an example of how to read the encoder count using the NU32.

The functions are:

  • void initEncoderSPI(void) - enables SPI4 as master at 8MHz
  • int getEncoder(void) - sends a '1' to the dsPIC, returns the value returned by the dsPIC

NU32_dsPIC_Example.c above demonstrates how to use the breakout board.

Sample Code

To initialize the SPI communication, call initEncoderSPI(), :

  initEncoderSPI();

To read the encoder count, call getEncoder(), :

  int count = getEncoder();

More Information

The internal count of the encoder will "roll over" at 0 or 65535. It is up to you to note that if the encoder count has made an unreasonable change, it has probably rolled over!