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

From Mech
Jump to navigationJump to search
Line 1: Line 1:
Using the dsPIC33FJ12MC201 breakout board for quadrature decoding.
*** UNDER CONSTRUCTION NDM 2/17/2012***


[[Image:NU32_dsPIC33FJ12MC201.jpg|thumb|200px|The dsPIC33FJ12MC201 breakout board|center]]
Using the dsPIC33FJ for quad decode


== Overview ==
== Overview ==


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

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 ==
== 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 board


== Library Functions ==
== Library Functions ==
[[Media:NU32SerialExample.zip | This code]] How to get the count
[[Media:NU32_dsPIC_QEU_example.zip | 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 NU32_Initialize(void) - enables UART1 and UART4 at 115200 baud. UART4 starts with the interrupt at priority level 3, UART1 starts with no interrupt enabled
*int NU32_dsPIC_getCount(void) - sends a '1' to the dsPIC, returns the value returned by the dsPIC
*void NU32_EnableUART1Interrupt(void) - enables the UART1 interrupt
*void NU32_WriteUART1(const char *) - call with the character array you wish to send, make the array with sprintf()
*void NU32_ReadUART1(char *, int) - call with the array you want to read into, and the maximum size of the array. The code will wait at this function and buffer all characters received until you send a '\r' or '\n' (by pressing [enter] on your keyboard)


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


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


To initialize the serial communication, call NU32_Initialize(), :
To initialize the SPI communication, call NU32_dsPIC_initialize(), :


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


To read the encoder count, call NU32_dsPIC_getCount(), :
To write a string to the computer, use NU32_WriteUART1(charArray). The special characters '\r' and '\n' are carriage return and newline. Using them together puts the cursor on the next line.


<pre>
<pre>
int count = NU32_dsPIC_getCount();
NU32_WriteUART1("\r\nHello World!\r\n");
</pre>
</pre>

To write a string with the value of a variable in it, use sprintf(charArray,"%d") and NU32_WriteUART1(charArray).


== More Information ==
== 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!

NA

Revision as of 11:38, 28 February 2012

Using the dsPIC33FJ12MC201 breakout board for quadrature decoding.

The dsPIC33FJ12MC201 breakout board

Overview

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.

Library Functions

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

The functions are:

  • void NU32_dsPIC_initialize(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

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

Sample Code

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

  NU32_dsPIC_initialize();

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

  int count = NU32_dsPIC_getCount();

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!