Difference between revisions of "DsPIC30F 5011 Development Board"

From OpenCircuits
Jump to navigation Jump to search
m (Reverted edits by ColeenRosales (Talk) to last revision by Russ hensel)
 
(502 intermediate revisions by 51 users not shown)
Line 1: Line 1:
 +
This project aims to provide the development tools for building a [[Multi-purpose_Embedded_System | multi-purpose MCU board]]. Description is based on Microchip dsPic33FJ256GP506 (was dsPic30F5011), but information provided in this wiki may give useful directions for developing similar embedded systems with different platforms.
 +
 
==Introduction==
 
==Introduction==
  
===Features of dsPIC30F5011===
+
===Features of dsPic33FJ256GP506===
*2.5 to 5V
+
*3.0 to 3.3 V
*Up to 30MIPs
+
*Up to 40 MIPs
*High current/sink source I/O pins: 25mA
+
*Maximum current sink/source for I/O pins: 4 mA
 +
*16-bit arithmetics
 
*DSP Instruction Set
 
*DSP Instruction Set
 
*Dual programming techniques: ICSP and RTSP
 
*Dual programming techniques: ICSP and RTSP
*UART: up to 2 modules
+
*Memory
*I<sup>2</sup>C: up to 1Mbps
+
**256&nbsp;KB flash (86K instructions)
*10-bit A/D, 1.1 Msps
+
**16&nbsp;KB RAM (incl. 2&nbsp;KB DMA RAM)
 +
**No EEPROM
 +
*Communications ports
 +
**UART
 +
**I<sup>2</sup>C: up to 1&nbsp;Mbit/s
 +
**SPI
 +
*ADC
 +
*10-bit A/D, 1.1 Msps
 
*12-bit A/D, 500 ksps
 
*12-bit A/D, 500 ksps
*66Kb flash, 4Kb RAM, 1Kb EEPROM
+
*No DAC (PWMs only)
*No DAC
+
*Pin-to-pin compatible with other dsPICs
 
+
{| border="1" cellspacing="0" cellpadding="5"
===Web Page===
+
|+ Comparison between different dsPICs
*[http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2529&param=en024856 Microchip Official Website]
+
! dsPic !! *Price<br>US$ !! MIPs
 
+
! Flash<br>(kB)!! RAM<br>(kB) !! EEPROM<br>(kB)
===Forum===
+
! I/O !! ADC<br>12-bit !! IC !! OC !! Motor<br>Ctrl !! Timers
*[http://direct.forum.microchip.com/default.aspx Microchip]: Official forum by Microchip
+
! QEI !! UART !! SPI !! I2C !! CAN !! Codec
**[http://direct.forum.microchip.com/tt.aspx?forumid=49 MPLAB ICD 2]: Subforum on ICD 2 programmer
+
|-
**[http://direct.forum.microchip.com/tt.aspx?forumid=57 MPLAB IDE]: Subforum on IDE
+
| 33FJ256GP506 || 6.11 || 40
**[http://direct.forum.microchip.com/tt.aspx?forumid=101 MPLAB C30 Compiler, ASM30, Link30 forum]: Subforum on C compiler. Refer to [http://ww1.microchip.com/downloads/en/DeviceDoc/C30_Users_Guide_51284e.pdf MPLAB C30 C Compiler User's Guide] Chapter 3
+
| 256 || 16 || 0
**[http://direct.forum.microchip.com/tt.aspx?forumid=153 dsPIC30F Topics]: Subformum on dsPIC30F
+
| 53 || 18 || 8 || 8 || 0 || 9x16bit<br>4x32bit
 
+
| 0 || 2 || 2 || 2 || 1 || 1
*[http://www.gnupic.org/ GNUPIC]: Discussion on PIC in Linux Systems
+
|-
**[http://www.linuxhacker.org/cgi-bin/ezmlm-cgi?1:dds:5443#b Debian]
+
| 33FJ128GP206 || 4.62 || 40
 +
| 128 || 8 || 0
 +
| 53 || 18 || 8 || 8 || 0 || 9x16bit<br>4x32bit
 +
| 0 || 2 || 2 || 1 || 0 || 1
 +
|-
 +
| 33FJ128GP306 || 4.81 || 40
 +
| 128 || 16 || 0
 +
| 53 || 18 || 8 || 8 || 0 || 9x16bit<br>4x32bit
 +
| 0 || 2 || 2 || 2 || 0 || 1
 +
|-
 +
| 33FJ128GP706 || 5.49 || 40
 +
| 128 || 16 || 0
 +
| 53 || 18 || 8 || 8 || 0 || 9x16bit<br>4x32bit
 +
| 0 || 2 || 2 || 2 || 2 || 1
 +
|-
 +
| 33FJ128MC506 || 4.97 || 40
 +
| 128 || 8 || 0
 +
| 53 || 16 || 8 || 8 || 8 || 9x16bit<br>4x32bit
 +
| 1 || 2 || 2 || 2 || 1 || 0
 +
|-
 +
| 33FJ128MC706 || 5.38 || 40
 +
| 128 || 16 || 0
 +
| 53 || 16 || 8 || 8 || 8 || 9x16bit<br>4x32bit
 +
| 1 || 2 || 2 || 2 || 1 || 0
 +
|-
 +
|}
 +
<nowiki>*</nowiki>For reference only, subject to change
  
 +
===Forums===
 +
*[http://forum.microchip.com/ Microchip]: Official forum by Microchip
 +
**See MPLAB ICD 2, MPLAB IDE, MPLAB C30 Compiler, ASM30, Link30 forum, dsPIC30F Topics, dsPic33 topics
 
*[http://www.htsoft.com/forum/all/ubbthreads.php/Cat/0/C/6 HI-TECH Software Forum]: Discussion on dsPICC, a C compiler developed by HI-TECH
 
*[http://www.htsoft.com/forum/all/ubbthreads.php/Cat/0/C/6 HI-TECH Software Forum]: Discussion on dsPICC, a C compiler developed by HI-TECH
 
+
*[http://sourceforge.net/forum/forum.php?forum_id=382005 FreeRTOS Real Time Kernel]: Open Discussion and Support on FreeRTOS
*[http://piclist.com/techref/piclist/index.htm PICList]: Discussion on older PIC systems (not dsPIC)
+
*[http://www.nabble.com/MicroControllers---GNUPIC-f2057.html Nabble]: MicroControllers - GNUPIC
 
 
*[http://groups.google.com/group/pickit-devel PicKit]: Discussion on PICkit/PICkit 2 programmers
 
  
 
===References===
 
===References===
*dsPIC30F
+
*dsPIC33F
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70043F.pdf Family Overview]
+
**[http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2573 dsPIC33F Family Reference Manual Sections]
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70046E.pdf Family Reference Manual]: Contains detailed descriptions on dsPIC30F register definitions and example codes
+
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70286C.pdf dsPIC33FJXXXGPX06/X08/X10 Data Sheet]
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70116F.pdf 5011 Data Sheet]
+
**[http://ww1.microchip.com/downloads/en/DeviceDoc/80306E.pdf dsPIC33FJXXXGPX06/X08/X10 Rev. A2/A3/A4 Silicon Errata]
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70102G.pdf Flash Programming Specification]
+
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70152G.pdf Flash Programming Specification]
**[http://ww1.microchip.com/downloads/en/DeviceDoc/70157B.pdf Programmer Reference Manual]
 
 
*ICD2 Programmer
 
*ICD2 Programmer
**[http://ww1.microchip.com/downloads/en/DeviceDoc/51331B.pdf ICD2 User's Guide]
+
**[http://ww1.microchip.com/downloads/en/DeviceDoc/51331C.pdf ICD2 User's Guide]
 
*MPLAB
 
*MPLAB
 
**[http://ww1.microchip.com/downloads/en/DeviceDoc/51519B.pdf MPLAB IDE User's Guide]
 
**[http://ww1.microchip.com/downloads/en/DeviceDoc/51519B.pdf MPLAB IDE User's Guide]
 
*C30 Compiler
 
*C30 Compiler
**[http://ww1.microchip.com/downloads/en/DeviceDoc/C30_Users_Guide_51284e.pdf MPLAB C30 C Compiler User's Guide]: Contains commands for using pic30-elf-gcc
+
**[http://ww1.microchip.com/downloads/en/DeviceDoc/C30_Users_Guide_51284e.pdf MPLAB C30 C Compiler User's Guide]: Contains commands for using pic30-elf-gcc
 
**[http://ww1.microchip.com/downloads/en/DeviceDoc/16bit_Language_Tool_Libraries_51456c.pdf 16-bit Language Tools Libraries]: Contains summaries and examples of using DSP libraries, standard C libraries and device libraries
 
**[http://ww1.microchip.com/downloads/en/DeviceDoc/16bit_Language_Tool_Libraries_51456c.pdf 16-bit Language Tools Libraries]: Contains summaries and examples of using DSP libraries, standard C libraries and device libraries
 
**[http://ww1.microchip.com/downloads/en/DeviceDoc/Asm30_Link_Util_51317e.pdf MPLAB ASM30, MPLAB LINK30 and Utilities User's Guide]
 
**[http://ww1.microchip.com/downloads/en/DeviceDoc/Asm30_Link_Util_51317e.pdf MPLAB ASM30, MPLAB LINK30 and Utilities User's Guide]
**[http://ww1.microchip.com/downloads/en/DeviceDoc/51322d.pdf dsPIC30F Language Tools Quick Reference Card]
+
 
 +
===Code Examples===
 +
*[http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1408 Microchip Example Codes for dsPic]
 +
 
 +
===Related Development===
 +
*[[Ethernet Module]]
 +
*[[Modulation Plugin]]
 +
 
  
 
==Programming Methods==
 
==Programming Methods==
 
 
*There are 2 programming methods: In-Circuit Serial Programming (ICSP) and Run-Time Self-Programming (RTSP)
 
*There are 2 programming methods: In-Circuit Serial Programming (ICSP) and Run-Time Self-Programming (RTSP)
 
*ICSP allows the devices to be programmed after being placed in a circuit board.
 
*ICSP allows the devices to be programmed after being placed in a circuit board.
 
*RTSP allows the devices to be programmed when an embedded program is already in operation.
 
*RTSP allows the devices to be programmed when an embedded program is already in operation.
  
===ICSP===
+
===ICSP: External Programmer (ICD2)===
*Two types of ICSP are available: '''ICSP''' and '''Enhanced ICSP'''. Both of them require setting ^MCLR to V<sub>IHH</sub> (9V – 13.25V).
+
*Two types of ICSP are available: '''ICSP''' and '''Enhanced ICSP'''. Both of them require setting MCLR# to V<sub>IHH</sub> (9V – 13.25V).
 
*Standard ICSP
 
*Standard ICSP
 
**Use external programmer (e.g. MPLAB<sup>®</sup> ICD 2, MPLAB<sup>®</sup> PM3 or PRO MATE<sup>®</sup> II) only.
 
**Use external programmer (e.g. MPLAB<sup>®</sup> ICD 2, MPLAB<sup>®</sup> PM3 or PRO MATE<sup>®</sup> II) only.
 
**Required low-level programming to erase, program and verify the chip.
 
**Required low-level programming to erase, program and verify the chip.
 
**Slower, because codes are serially executed.
 
**Slower, because codes are serially executed.
**Program memory can be erased using ''Normal-Voltage'' (4.5 – 5.5V) or ''Low-Voltage'' (2.5V – 4.5V).
 
  
 
*Enhanced ICSP
 
*Enhanced ICSP
Line 71: Line 112:
 
**PE contains a small command set to erase, program and verify the chip, avoiding the need of low-level programming.
 
**PE contains a small command set to erase, program and verify the chip, avoiding the need of low-level programming.
  
*Hardware Interface
+
====Hardware Interface====
 
{| border="1" cellspacing="0" cellpadding="5"
 
{| border="1" cellspacing="0" cellpadding="5"
|+ Table 2.1 Pin Used by ICSP
+
|+ Pin Used by ICSP
 
! Pin Label !! Function !! Pin Number
 
! Pin Label !! Function !! Pin Number
 
|-  
 
|-  
| ^MCLR || Programming Enable|| 7
+
| MCLR# || Programming Enable|| 7
 
|-
 
|-
 
| V<sub>DD</sub> || Power Supply || 10, 26, 38, 57
 
| V<sub>DD</sub> || Power Supply || 10, 26, 38, 57
Line 90: Line 131:
  
 
{| border="1" cellspacing="0" cellpadding="5"
 
{| border="1" cellspacing="0" cellpadding="5"
|+ Table 2.2 Available Programmers in the Market
+
|+ Available Programmers in the Market
 
! Product Name
 
! Product Name
 
! Interface with PC
 
! Interface with PC
 
! Interface with Device
 
! Interface with Device
! Price (US)
+
! *Price (US)
! Postage (US)
+
! Remarks
! Total (US)
 
 
|-  
 
|-  
 
| [http://direct.www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046&part=DV164005 MPLAB<sup>®</sup> ICD 2]
 
| [http://direct.www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046&part=DV164005 MPLAB<sup>®</sup> ICD 2]
| USB/RS232
+
| USB or RS232
 
| [http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en010046&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046&part=DV164005# 6-PIN RJ-12 connector]
 
| [http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en010046&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046&part=DV164005# 6-PIN RJ-12 connector]
 
| $159.99
 
| $159.99
 
| -
 
| -
| -
 
|-
 
| [http://www.kanda.com/index.php3?cs=1&bc=direct&bw=%2Fbrowse.php3%3Fnode%3D114%26semisupport%3D PRESTO PIC Programmer Plus]
 
| USB
 
| ?
 
| $200.16
 
| $15.00
 
| $215.16
 
 
|-
 
|-
| [http://www.etekronics.com/product_info.php?cPath=24&products_id=48  Full Speed USB Microchip ICD2<br> Debugger and Programmer]
+
| [http://www.sureelectronics.net Clone Microchip ICD2] (Now Using)
 
| USB
 
| USB
| 6-PIN ICSP connector<br>6-PIN RJ-12 connector
 
| $72.00
 
| $12.00
 
| $84.00
 
|-
 
| [http://www.etekronics.com/product_info.php?cPath=24&products_id=47 Mini Microchip Compatible ICD2<br> Debugger and Programmer]
 
| RS232
 
| 6-PIN ICSP connector<br>6-PIN RJ-12 connector
 
| $45.00
 
| $10.00
 
| $55.00
 
|-
 
| [http://www.inexglobal.com/microcontroller.php ICDX30]
 
| RS232
 
| 6-pin RJ-11
 
| $51.00
 
| $47.46
 
| $98.46
 
|-
 
| [http://www.sure-electronics.net/englishsite/icd2/icd2.htm Clone Microchip ICD2]
 
| RS232
 
 
| 6-pin flat cables
 
| 6-pin flat cables
| $30.00
+
| $52.35
| $12.00
+
| Do not work with new MPLAB versions (works for 7.50), communication to MPLAB may sometime hang (see [http://www.sureelectronics.net/pdfs/DB-DP003.pdf manual])
| $42.00
 
 
|-
 
|-
 
|}
 
|}
 +
<nowiki>*</nowiki>For reference only (exclude shipping), subject to change
  
  
 
{| border="1" cellspacing="0" cellpadding="5"
 
{| border="1" cellspacing="0" cellpadding="5"
|+ Table 2.3 DIY ICD 2 Programmer Circuit
+
|+ DIY ICD 2 Programmer Circuit
 
! Source !! Schematic !! PIC16F877A Bootloader
 
! Source !! Schematic !! PIC16F877A Bootloader
 
|-  
 
|-  
Line 157: Line 168:
 
|}
 
|}
  
*Software Interface
 
**The program can be written and compiled in an Integrated Development Environment (IDE) using either Assembly or C. The complied codes are then loaded to the device through the external programmer.
 
  
 +
====Software Interface====
 +
*The program can be written and compiled in an Integrated Development Environment (IDE) using either Assembly or C. The complied codes are then loaded to the device through the external programmer.
  
 
{| border="1" cellspacing="0" cellpadding="5"
 
{| border="1" cellspacing="0" cellpadding="5"
|+ Table 2.4 Summary of IDE
+
|+ Summary of IDE
 
! Product Name !! Features !! OS !! Price (US$)
 
! Product Name !! Features !! OS !! Price (US$)
 
|-  
 
|-  
Line 175: Line 186:
 
| $895.00 (Free student version<sup>1</sup>)
 
| $895.00 (Free student version<sup>1</sup>)
 
|-
 
|-
| [http://linux.softpedia.com/get/Science-and-Engineering/Electronic-Design-Automation-EDA-/Piklab-8099.shtml Piklab 0.12.0]
+
| [http://piklab.sourceforge.net/ Piklab]
 
| Assembler and C-Compiler
 
| Assembler and C-Compiler
 
| Linux
 
| Linux
| Free<sup>2</sup>
+
| Free
 
|}
 
|}
# Full-featured for the first 60 days. After 60 days only optimization level 1 can be enabled in the compiler. The compiler will continue to function after 60 days, but code size may increase.
+
# Full-featured for the first 60 days. After 60 days, some code optimization functions are disabled. The compiler will continue to function after 60 days, but code size may increase.
# The current version supports external programmer ICD 2, but not yet tested.
 
 
 
===RTSP===
 
*RTSP works in normal voltage (^MCLR no need to raise to V<sub>IHH</sub>).
 
*No literature has mentioned the incorporation of Programming Executive (PE). Presumably, since Enhanced ICSP needs to set ^MCLR to V<sub>IHH</sub>, RTSP cannot use PE.
 
*Refer to bootloader section.
 
  
 
+
===RTSP: COM Port (Bootloader)===
==Circuit Design and PCB==
+
*RTSP works in normal voltage (MCLR# no need to raise to V<sub>IHH</sub>).
 
+
*No literature has mentioned the incorporation of Programming Executive (PE). Presumably, since Enhanced ICSP needs to set MCLR# to V<sub>IHH</sub>, RTSP cannot use PE.
===IC Requirements===
+
*Refer to [[DsPIC30F_5011_Development_Board#Bootloader_Development | bootloader section]].
{|border="1" cellspacing="0" cellpadding="5"
 
|+ Table 3.1 IC Requirements
 
! Part No. !! Description
 
! Min Temp !! Max Temp !! Min Volt !! Max Volt !! Typ Cur !! Max Cur
 
|-valign="top"
 
| [http://ww1.microchip.com/downloads/en/DeviceDoc/70116F.pdf dsPIC30F5011-30I/PT] || uP
 
| -40<sup>o</sup>C || 85<sup>o</sup>C
 
| 2.5V <sup>[1]</sup>|| 5.5V
 
|    || 250mA
 
|-
 
| [http://datasheets.maxim-ic.com/en/ds/MAX3222-MAX3241.pdf MAX3232ESE] || RS232 driver
 
| -40<sup>o</sup>C || 85<sup>o</sup>C
 
| 3.0V || 5.5V
 
| 0.3mA || 1.0mA
 
|-
 
| [http://www.analog.com/UploadedFiles/Data_Sheets/ADM483E.pdf ADM483E ANZ] || RS485 driver
 
| -40<sup>o</sup>C || 85<sup>o</sup>C
 
| 4.5V || 5.5V
 
| 0.036mA ||
 
|-
 
| [http://focus.ti.com/lit/ds/symlink/dac6574.pdf DAC6574DGS] || 10-bit Quad-DAC I<sup>2</sup>C
 
| -40<sup>o</sup>C || 105<sup>o</sup>C
 
| 2.7V || 5.5V
 
| 0.6mA || 0.9mA
 
|-
 
| [http://www.semiconductors.philips.com/acrobat/datasheets/74HC_HCT14_3.pdf 74HC14D] || Quad-Schmitt Trigger
 
| -40<sup>o</sup>C || 125<sup>o</sup>C
 
| 2.0V || 6.0V
 
| || 50mA
 
|-
 
| Overall ||
 
| -40<sup>o</sup>C || 85<sup>o</sup>C
 
| 4.5V || 5.5V
 
| || <310mA <sup>[2]</sup>
 
|-
 
|}
 
#Minimum voltage measured is 3.3V (with 2 LEDs blinking) running at 30MHz.
 
#Measured current at 5V is 180mA (with 2 LEDs blinking only)
 
 
 
===Module Board===
 
*Functions
 
**Primary communication with other module boards via RS232 over short distance.
 
**Secondary communication with benchtop via RS458 over longer distance.
 
**Digital control I/O for 1 laser (e.g. on/off, detect temp overheat, current alarm)
 
**Analog input for data acquisation on power, current and temperature
 
**Analog output for power and current control
 
 
 
{|border="1" cellspacing="0" cellpadding="5"
 
|+ Table 3.2 Module
 
! Digital Input !! Digital Output !! Analog Input !! Analog Output
 
|-valign="top"
 
| 1. ICSP
 
| 1. LED<br> 2. Bi-color LED<br> 3. RS232<br> 4. RS458<br> 5. Case temp overheat<br> 6. Laser on/off 1,2<br> 7. Interlock<br> 8. Digital ctrl<br> 9. Current 0,1 alarm<br>
 
| 1. Case temp<br> 2. pow 0,1<br> 3. cur0<br> 4. temp0
 
| 1. 10-bit DAC
 
|-
 
|}
 
 
 
===Benchtop===
 
*Functions
 
**Primary communciation with module boards via RS485
 
**Secondary communication with other benchtops via RS232
 
**Digital I/O control for 2 lasers
 
**Analog inputs on power, current and temperature
 
**Analog outputs for power and current control
 
**LCD display and rotary key for user input
 
 
 
{|border="1" cellspacing="0" cellpadding="5"
 
|+ Table 3.3 Base Benchtop
 
! Digital Input !! Digital Output !! Analog Input !! Analog Output
 
|-valign="top"
 
| 1. ICSP<br> 2. Rotary Key<br> 3. Push Buttons
 
| 1. LED<br> 2. RS232<br> 3. RS458<br> 4.LCD display<br> 5. Buzzer<br> 6. Digital Ctrl 0,1
 
| 1. Case temp<br> 2. CurrentDetect 0,1<br> 3. PowerDetect 0,1,2,3<br> 4. TempDetect
 
| 1. 10-bit DAC (PowerCurrentCtrl 0,1)
 
|-
 
|}
 
  
  
Line 280: Line 208:
 
**MPLAB C30 C Compiler (*.c -> *.s)
 
**MPLAB C30 C Compiler (*.c -> *.s)
 
**MPLAB ASM30 Assembler (*.s -> *.o)
 
**MPLAB ASM30 Assembler (*.s -> *.o)
**MPLAB LINK30 Linker (*.o -> *.exe)
+
**MPLAB LINK30 Linker (*.o -> *.bin)
  
 
*PA optimizer, simulator, runtime libraries, header files, include files, and linker scripts are not covered by GNU. Reference is [http://direct.forum.microchip.com/tm.aspx?m=107208 here].
 
*PA optimizer, simulator, runtime libraries, header files, include files, and linker scripts are not covered by GNU. Reference is [http://direct.forum.microchip.com/tm.aspx?m=107208 here].
  
 
*Microchip has integrated ASM30, LINK30, assembly header files, linker scripts in MPLAB IDE, which is free for download.
 
*Microchip has integrated ASM30, LINK30, assembly header files, linker scripts in MPLAB IDE, which is free for download.
*MPLAB C30 costs US$895. A 60-day free student version is also available. After 60-days, the optimizer is automatically disabled, while other tools can still function properly. Refer to Table 2.4.
+
*MPLAB C30 costs US$895. A 60-day free student version is also available. After 60-days, the optimizer is automatically disabled, while other tools can still function properly.
  
 
*C-libraries contained in C30 includes (Refer to [http://ww1.microchip.com/downloads/en/DeviceDoc/16bit_Language_Tool_Libraries_51456c.pdf 16-Bit Language Tools Libraries] from Microchip).
 
*C-libraries contained in C30 includes (Refer to [http://ww1.microchip.com/downloads/en/DeviceDoc/16bit_Language_Tool_Libraries_51456c.pdf 16-Bit Language Tools Libraries] from Microchip).
Line 291: Line 219:
  
 
{|border="1" cellspacing="0" cellpadding="5"
 
{|border="1" cellspacing="0" cellpadding="5"
|+ Table 4.1 C Libraries in MPLAB C30
+
|+ C Libraries in MPLAB C30
 
! Library !! Directory <br>(\\Microchip\MPLAB C30) !! Major functions
 
! Library !! Directory <br>(\\Microchip\MPLAB C30) !! Major functions
 
|-valign="top"
 
|-valign="top"
Line 298: Line 226:
 
| Vector, Matrix, Filter, etc.
 
| Vector, Matrix, Filter, etc.
 
|-valign="top"
 
|-valign="top"
| 16-Bit Peripheral Libraries <br>(e.g. libp30F5011-coff.a)
+
| 16-Bit Peripheral Libraries
 
| \lib <br> \src\peripheral <br> \support\h
 
| \lib <br> \src\peripheral <br> \support\h
 
| ADC12, IOPort, UART, I<sup>2</sup>C, etc.
 
| ADC12, IOPort, UART, I<sup>2</sup>C, etc.
Line 320: Line 248:
 
**Current MPLAB ASM30 Assembler: v2.04
 
**Current MPLAB ASM30 Assembler: v2.04
 
**Current MPLAB C30 Compiler: v2.04
 
**Current MPLAB C30 Compiler: v2.04
 +
*'''Important Note''': Only the compiler is free. The header files and library are owned by Microchip.
  
*[http://gcc.gnu.org/ml/gcc/2005-02/msg01144.html John Steele Scott] has made templates that can be readily used by Debian-based systems. Someone at http://noel.feld.cvut.cz/dspic/ has done the necessary conversion to *.deb already.
+
{|border="1" cellspacing="0" cellpadding="5"
**Download '''pic30-1.32-debian.tar.bz2''' for Template v1.32. (For v2.01, please goto [http://thread.gmane.org/gmane.comp.hardware.microcontrollers.gnupic/3768/focus=3768  pic30-debian-2.01.tar.bz2]).
+
|+ Pic30 C-Compiler Toolchain Templates for Conversion to Debian-based systems
**Download '''pic30-binutils_1.32-1_i386.deb''' for the assember.
+
! Toolchain Source !! Instruction !! Remarks
**Download '''pic30-gcc_1.32-1_i386.deb''' for the compiler.
 
 
 
*'''Important Note''': Only the compiler is free. The header files and library is owned by Microchip.
 
**Thomas Sailer suggested to download the Student version of C30 compiler and then build the libraries without source code. A package template for Fedora system is available [http://www.baycom.org/~tom/dspic/ here].
 
**Instructions for filling the upstream direction is available [http://forum.microchip.com/printable.aspx?m=139360 here].
 
**Alteratively, [https://gna.org/projects/pic30-libc/ Stephan Walter] has started a project to develop C Runtime Library for dsPIC.
 
***Current libraries in version 0.1.1 include: assert.h, cdefs.h, ctype.h, errno.h, inttypes.h, stdint.h, stdio.h, stdlib.h, string.h
 
 
 
*Burning Program Codes to Target Board
 
#Use 'dspicprg and dspicdmp' utilities developed by [http://homerreid.ath.cx/misc/dspicprg/ Homer Reid] to burn hex code (*.hex) to devices. See Reference [http://forum.microchip.com/tm.aspx?m=94243 here]. Through serial port only?
 
#Use [http://piklab.sourceforge.net/ Piklab IDE]. Details on file format not known.
 
#Use [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 MPLAB IDE] to burn hex code (*.hex) to devices.
 
 
 
 
 
==Programming Tips==
 
 
 
===Memory Map for 5011===
 
+-------------------------------------+ 0x000000 to 0x00AFFE<br>
 
|..............Flash.................|<br>
 
|.........(22K x16 bits)..........|<br>
 
+-------------------------------------+ 0x00B000 to 0x7FFBFE<br>
 
|............Reserved..............|<br>
 
+-------------------------------------+ 0x7FFC00 to 0x7FFFFE<br>
 
|.............EEPROM............|<br>
 
|...........(1K x 8 bits)..........|<br>
 
+-------------------------------------+ 0x800000 to 0x8005BE<br>
 
|................PE..................|<br>
 
+-------------------------------------+ 0x8005C0 to 0x8005FE<br>
 
|..............Unit ID...............|<br>
 
+-------------------------------------+ 0x800600 to 0xF7FFFE<br>
 
|............Reserved..............|<br>
 
+-------------------------------------+ 0xF80000 to 0xF8000E<br>
 
|........Config Registers.......|<br>
 
+-------------------------------------+ 0xF80010 to 0xFEFFFE<br>
 
|............Reserved..............|<br>
 
+-------------------------------------+ 0xFF0000 to 0xFF0002<br>
 
|..............Device ID...........|____________________________'''0x0080'''<br>
 
+-------------------------------------+ 0xFF0002 to 0xFF0004<br>
 
|............Reserved..............|<br>
 
+-------------------------------------+ 0xFFFFFE<br>
 
 
 
===Data Location===
 
{| border="1" cellspacing="0" cellpadding="5"
 
|+ Table 5.1 Data Location
 
! Type !! Description !! Example
 
 
|-valign="top"
 
|-valign="top"
| _XBSS(N) <sup>[1]</sup>
+
| [http://www.baycom.org/~tom/dspic/ v2.00]
| RAM Data in X-memory, aligned at N, no initilization
+
| Download pic30-gcc-2.00-1.i386.rpm and pic30-binutils-2.00-1.i386.rpm.<br>Convert to deb files.
| int _XBSS(32) xbuf[16];
+
| Stable<br>Now using
 
|-valign="top"
 
|-valign="top"
| _XDATA(N) <sup>[1]</sup>
+
| [http://www.nabble.com/Debian-templates-for-dsPIC-build-toolchain-2.05-td7886279.html v2.05]
| RAM Data in X-memory, aligned at N, with initilization
+
| Reference to example below, but use 2.05 files
| int _XDATA(32) xbuf[] = {1, 2, 3, 4, 5};
+
| Can compile<br>Stable but not heavily tested
 
|-valign="top"
 
|-valign="top"
| _YBSS(N) <sup>[1]</sup>
+
| [http://www.nabble.com/Debian-templates-for-dsPIC-build-toolchain-3.01-tf4308624.html v3.01]
| RAM Data in Y-memory, aligned at N, no initilization
+
| Follow example below
| int _YBSS(32) ybuf[16];
+
| Can compile<br>Unstable (sometime produce segmentation fault)
 
|-valign="top"
 
|-valign="top"
| _YDATA(N) <sup>[1]</sup>
+
| [http://www.nabble.com/Debian-Template-Patches-for-C30-v3.10-i386-td17534084.html v3.10]
| RAM Data in Y-memory, aligned at N, with initilization
+
| Reference to example below, but use 3.10 files
| int _YDATA(32) ybuf[16] = {1, 2, 3, 4, 5};
+
| Cannot compile yet (segmentation fault)
|-valign="top"
 
| __attribute__((space(const)))
 
| Flash ROM data, constant, accessed by normal C statements, but 32K max.
 
| int i __attribute__((space(const))) = 10;
 
|-valign="top"
 
| __attribute__((space(prog)))
 
| Flash ROM data, read/write by program space visibility window (psv)
 
| int i __attribute__((space(prog)));
 
|-valign="top"
 
| __attribute__((space(auto_psv)))
 
| Flash ROM data, read by normal C statements, write by accessing psv
 
| int i __attribute__((space(auto_psv)));
 
|-valign="top"
 
| __attribute__((space(psv)))
 
| Flash ROM data, read/write by (psv)
 
| int i __attribute__((space(psv)));
 
|-valign="top"
 
| _EEDATA(N) <sup>[1]</sup>
 
| ROM Data in EEPROM, aligned at N, read/write with psv
 
| int _EEDATA(2) table[]={0, 1, 1, 2, 3, 5, 8};<br>
 
  void main(){<br>
 
    PSVPAG = __builtin_psvpage(&table);<br>
 
    CORCONbits.PSV = 1;<br>
 
    ...<br>
 
    if(table[2]){<br>
 
        ...<br>
 
    }<br>
 
  }
 
|-valign="top"
 
| _PERSISTENT
 
| RAM Data, data remain after reset
 
| int _PERSISTENT var1, var2;
 
|-valign="top"
 
| _NEAR
 
| RAM Data at near section
 
| int _NEAR var1, var2;
 
|-valign="top"
 
| _ISR
 
| Interrupt service rountine
 
| void _ISR _INT0Interrupt(void);
 
|-valign="top"
 
| _ISRFAST
 
| Fast interrupt service rountine
 
| void _ISRFAST _T0Interrupt(void);
 
 
|-
 
|-
 
|}
 
|}
#N must be a power of two, with a minimum value of 2.
+
====Conversion Example====
 +
*Pre-install these packages: dpkg-dev, debhelper, bison, flex, sysutils, gcc-3.3, fakeroot
 +
**cmd: '''sudo apt-get install dpkg-dev debhelper bison flex sysutils gcc-3.3 fakeroot'''
 +
*Download and unzip template: '''pic30-3.01.tar.bz2'''
 +
*Download assembler: '''mplabalc30v3_01_A.tar.gz'''. Save under /pic30-3.01/pic30-binutils-3.01/upstream/
 +
*Download c-compiler: '''mplabc30v3_01_A.tgz'''. Save under /pic30-3.01/pic30-gcc-3.01/upstream/
 +
*Install MPLAB_C30_v3_01-StudentEdition under Windows
 +
*Copy directories /include, /lib, /support, and /bin/c30_device.info to pic30-3.01/pic30-support-3.01/upstream/
 +
*Pack pic30-binutils into deb file
 +
**goto /pic30-3.01/pic30-binutils-3.01/
 +
**type cmd: '''dpkg-buildpackage -rfakeroot -b'''
 +
*Install pic30-binutils_3.01-1_i386.deb
 +
**type cmd: '''sudo dpkg -i pic30-binutils_3.01-1_i386.deb'''
 +
*Pack pic30-gcc-3.01 into deb file
 +
**goto /pic30-3.01/pic30-gcc-3.01/
 +
**type cmd: '''dpkg-buildpackage -rfakeroot -b'''
 +
*Install pic30-gcc_3.01-1_i386.deb
 +
**type cmd: '''sudo dpkg -i pic30-gcc_3.01-1_i386.deb'''
 +
*Pack support files into deb file
 +
**goto /pic30-3.01/pic30-support-3.01/
 +
**type cmd: '''dpkg-buildpackage -rfakeroot -b'''
 +
*Install pic30-support_3.01-1_all.deb
 +
**type cmd: '''sudo dpkg -i pic30-support_3.01-1_all.deb'''
 +
*After installation, locations of
 +
**C-Header (*.h): /usr/pic30-elf/include
 +
**Libraries (*.a): /usr/pic30-elf/lib
 +
**Assembly header (*.inc): /usr/share/pic30-support/inc
 +
**Linkerscript (*.gld): /usr/share/pic30-support/gld
 +
 
 +
===Burning Program Codes to Target Board===
 +
#Use 'dspicprg and dspicdmp' utilities developed by [http://homerreid.ath.cx/misc/dspicprg/ Homer Reid] to burn hex code (*.hex) to devices. See Reference [http://forum.microchip.com/tm.aspx?m=94243 here]. Through serial port only?
 +
#Use [http://piklab.sourceforge.net/ Piklab IDE]. Details on file format not known.
 +
#Use [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 MPLAB IDE] to burn hex code (*.hex) to devices.
 +
 
 +
===Code Optimization===
 +
*Below is a comparsion between different optimization levels for the project including drivers for 2 projects.
  
===Driver Development===
+
{|border="1" cellspacing="0" cellpadding="5"
{| border="1" cellspacing="0" cellpadding="5"
+
|+ Comparison between differnt optimization levels
|+ Table 5.2 Driver Development
+
! Optimization !! Description !! Project 1<br>Code Size<br>(byte) !! Project 1<br>Data Usage<br>(byte) !! Project 2<br>Code Size<br>(byte) !! Project 2<br>Data Usage<br>(byte)
! Item !! Description !! Start Date !! Completion Date !! Test Date
 
|-valign="top"
 
| DI/DO and 10ms Timer interrupt
 
| Simple switching of LEDs
 
| 07 Nov 2006 || 08 Nov 2006 || 15 Nov 2006
 
 
|-valign="top"
 
|-valign="top"
| UART
+
| O0
| RS232 and RS485
+
| No optimization<br>Fastest Compilation
| 08 Nov 2006 || 10 Nov 2006 || 16 Nov 2006
+
| 6222 (9%) || 178 (4%) || 26,037 (38%) || 710 (17%)
 
|-valign="top"
 
|-valign="top"
| I<sup>2</sup>C
+
| O1
| DAC
+
| Optimize<br> Tries to reduce code size and execution time.
| 13 Nov 2006 || 28 Nov 2006 || 28 Nov 2006
+
| 4473 (6%) || 178 (4%) || 22,290 (32%) || 710 (17%)
 
|-valign="top"
 
|-valign="top"
| Analog I/O
+
| O2
| Sampling analog signal
+
| Optimize even more<br> Performs nearly all supported optimizations <br>that do not involve a space-speed trade-off. <br>Increases both compilation time and the <br>performance of the generated code.
| 29 Nov 2006|| 30 Nov 2006 || 1 Dec 2006
+
| 4422 (6%) || 178 (4%) || 21,993 (32%) || 710 (17%)
 
|-valign="top"
 
|-valign="top"
| Usage of Standard C-libraries
+
| O3
| 1. math.h<br>2. stdlib.h
+
| Optimize yet more. <br>O3 turns on all optimizations specified by O2 <br>and also turns on the inline-functions option.
| 08 Nov 2006 || 08 Nov 2006 || 21 Nov 2006
+
| 4485 (6%) || 178 (4%) || 22,176 (32%) || 710 (17%)
 
|-valign="top"
 
|-valign="top"
| Usage of DSP libraries
+
| Os
| 1. Vector<br>2. Matrix<br> 3. DFT
+
| Optimize for size. <br>Os enables all O2 optimizations that do not <br>typically increase code size. It also performs <br>further optimizations designed to reduce code <br>size.
| || ||
+
| 4356 (6%) || 178 (4%) || 21,885 (32%) || 710 (17%)
|-valign="top"
 
| Usage of Buildin libraries
 
| 1. __builtin_add<br>2. __builtin_divud<br> 3. __builtin_clr
 
| || ||  
 
 
|-
 
|-
 
|}
 
|}
  
===Configuration Bits===
 
*System clock source can be provided by:
 
#Primary oscillator (OSC1, OSC2)
 
#Secondary oscillator (SOSCO and SOSCI) with 32kHz crystal
 
#Internal Fast RC (FRC) oscillator at 7.37MHz
 
#Low-Power RC (LPRC) oscillator (Watchdog Timer) at 512 kHz.
 
*These clock sources can be incorporated with interal Phase-locked-loop (PLL) x4, x8 or x16 to yield the osciallator frequrence F<sub>OSC</sub>
 
*The system clock is divided by 4 to yield the internal instruction cycle clock, F<sub>CY</sub>=F<sub>OSC</sub>/4
 
*FRC with PLLx16 is used to achieve F<sub>CY</sub>=29.48MHz (30MIPS)
 
    _FOSC(CSW_FSCM_OFF & FRC_PLL16);
 
 
===UART===
 
*5011 provides two UART channels UxART, for x=1, 2.
 
*UxMODE, UxSTA, UxBRG are registers used to set the mode, indicate the status, and set the baud rate respectively.
 
*For UART communications compatiable with RS232 standard, an external driver (e.g. MAX3232ESE) is needed.
 
*For UART communications compatiable with RS485 standard, an external driver (e.g. DS3695N) is needed.
 
====Auto baud rate detection====
 
*The PC sends a ASCII character 'U' (0x55) to the target board.
 
*On the first rising edge of the start bit, the target board starts the timer.
 
*At the fifth rising edge, the timer is stopped, let the count number be ''t_count''.
 
**The measured period corresponds to 8 bits transmitted at a baud rate ''uxbrg''.
 
  _  _  _  _  _  _
 
_|S|_|1|_|1|_|1|_|1|_|S|_  (S = Start Bit)
 
  <--------------->
 
    Measured Time
 
*The relationship between ''uxbrg'' and ''TMR'' is
 
Measured Time (in seconds) = t_count/F<sub>cy</sub>
 
uxbrg = 1/(Measured Time/8)
 
      = 8*F<sub>cy</sub>/t_count
 
*Since UxBRG is computed by:
 
UxBRG = (F<sub>cy</sub>/(16*Baudrate)) -1
 
      = (F<sub>cy</sub>/(16*8*F<sub>cy</sub>/t_count)) -1
 
      = t_count/128 -1
 
*The following is the code for auto baud rate detection for U2ART:
 
U2MODEbits.ABAUD = 1; //Enable Autobaud detect from U2RX (from IC2 if 0)
 
U2MODEbits.UARTEN = 1; //U2ART enable
 
//Timer 3 Config==========================================================
 
PR3 = 0xFFFF; // Set counter to maximum
 
_T3IF = 0; // Clear interrupt flag
 
_T3IE = 0; // Disable interrupt
 
T3CONbits.TON = 1; // Start the timer, TMR3 count up
 
//Input Capture Config====================================================
 
IC2CONbits.ICM = 3; //Detect rising
 
_IC2IF = 0; //Clear interrupt flag
 
_IC2IE = 0; //Disable interrupt
 
//Start Auto baud detection===============================================
 
unsigned int i=0;
 
cli(); //Disable Global Interrupt
 
while(!_IC2IF); //1st rising edge detected
 
TMR3 = 0; //Clear TMR3 to start count up
 
_IC2IF = 0; //Clear interrupt flag
 
while(!_IC2IF); //Second to 2nd rising edge detected
 
_IC2IF = 0; //Clear interrupt flag
 
while(!_IC2IF); //Second to 3rd rising edge detected
 
_IC2IF = 0; //Clear interrupt flag
 
while(!_IC2IF); //Second to 4th rising edge detected
 
_IC2IF = 0; //Clear interrupt flag
 
while(!_IC2IF); //Second to 5th rising edge detected
 
_IC2IF = 0; //Clear interrupt flag
 
T3CONbits.TON = 0; // Stop the timer
 
sti(); //Enable Global Interrupt
 
//Compute value for BRG register==========================================
 
unsigned int time;
 
time = ((TMR3+0x40)>>7)-1;    //+0x40 for rounding
 
//========================================================================
 
return time;
 
 
===I<sup>2</sup>C===
 
*Two lines are devoted for the serial communication. SCL for clock, SDA for data.
 
*Standard communication speed includes
 
#Standard speed mode: 100kHz
 
#Fast speed mode: 400kHz
 
#High speed mode: 3.4MHz
 
*dsPIC30f5011 supports standard and fast speed modes. The maximum speed attainable is 1MHz.
 
*Pull-up resistors are required for both SCL and SDA. Minimum pull-up resistance is given by:
 
    Pull-up resistor (min) = (V<sub>dd</sub>-0.4)/0.003  ......  [See section 21.8 in Family reference manual]
 
*2.2Kohm is typical for standard speed mode.
 
*After initiating a start/stop/restart bit, add a small delay (e.g. no operation) before polling the corresponding control bit (hardware controlled). For example:
 
      StartI2C();<br>
 
      Nop(); //A small delay for hardware to respond<br>
 
      while(I2CCONbits.SEN); //Wait till Start sequence is completed
 
*After sending a byte and receiving an acknowledgement from the slave device, ensure to change to idle state. For example:
 
      MasterWriteI2C(0x55);<br>
 
      while(I2CSTATbits.TBF); //Wait for transmit buffer to empty<br>
 
      while(I2CSTATbits.ACKSTAT); //Wait for slave acknowledgement<br>
 
      IdleI2C();
 
 
===ADC===
 
*12-bit ADC: (Max 16 Channels)
 
*Allow 2 sets of analog input multiplexer configurations, MUX A and MUX B.
 
 
===DSP Library===
 
 
===Buildin Library===
 
 
 
==Bootloader==
 
 
===Concepts===
 
*Programming with ICSP is useful when the target board is produced in batch. The producer can download a program even when the chip is on the target board.
 
*However, ICSP requires an external programmer.
 
*To allow the user to change the program after production but without the need of an external programmer, bootloader becomes useful.
 
*Bootloader is a small program installed via ICSP. Everytime the device is reset, the bootloader is run first. The bootloader first detects the default serial channel whether the user wishes to download a new program to the device. If so, the bootloader will pause there, and wait for the user to download the hex file from the PC. The hex file is written to the device via RTSP instructions in the bootloader. If a new download is not necessary, the bootloader redirects to the previously installed user's program.
 
*The disadvantage of bootloaders is that they consume some of the memory of the device.
 
 
 
{| border="1" cellspacing="0" cellpadding="5"
 
|+ Table 6.1 Free bootloaders for dsPIC
 
! Developer
 
! Source
 
! Platform
 
! User Guide
 
! Remarks
 
|- valign="top"
 
| [http://www.ingenia-cat.com/index.php?lang=en ingenia]
 
| [http://www.ingenia-cat.com/download/iBL.s Assembly]
 
| [http://www.ingenia-cat.com/download/ingeniadsPICbootloader1.1.zip Windows]
 
| [http://www.ingenia-cat.com/reference/pdf/iBL.UG.V1.2.pdf pdf]
 
|
 
*Works for all dsPIC supporting RTSP
 
*Auto baudrate detection
 
*Use about 1.15% of the flash memory space (0xAFFF-0xAE00)/(0xAFFF-0x0100)
 
*Development of Linux platform is underway
 
*Modification of code for dsPIC30F5011 is successful
 
|-valign="top"
 
| [http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm Tiny]
 
| [http://www.etc.ugal.ro/cchiculita/software/tinybld191.zip Assembly]
 
| Windows
 
| [http://www.etc.ugal.ro/cchiculita/software/tinybldusage.htm Web]
 
|
 
*By default, only supports 601X, 601X, 401X, 2010
 
*Smaller code size than ingenia, but not as easy to modify
 
|-valign="top"
 
| [http://www.via.si/software/dsPIC_bootloader/ Elektronika]
 
| [http://www.via.si/software/dsPIC_bootloader/data/ Hex]
 
| Windows
 
| [http://www.via.si/software/dsPIC_bootloader/data/README.txt txt]
 
|
 
*Only works for dsPIC30F6014 serial port UART2 at baudrate 57600
 
|-
 
|}
 
 
===ingenia===
 
====Modification====
 
*For 5011, the bootloader is located between 0x00AE00 to 0x00AFFE. Refer to C:\Program Files\Ingenia\ingeniadsPICbootloader\ibl_dspiclist.xml after installing the GUI interface.
 
*Changes made to [http://www.ingenia-cat.com/download/iBL.s assembly code]  includes:
 
1. including p30f5011.gld and p30f5011.inc
 
        .include "p30f5011.inc"
 
2. changing the config code of UART #0x8420 -> #0x8020
 
        ; Uart init
 
        mov '''#0x8020''', W0          ; W0 = 0x8020 -> 1000 0000 0010 0000b
 
        mov W0, U2MODE            ; Enable UART, AutoBaud and 8N1
 
        clr U2STA
 
3. changing the start address 0xAE00 - 0x0100 = 0AD00
 
          .equ CRC, W4
 
          .equ ACK, 0x55
 
          .equ NACK, 0xFF
 
          .equ USER_ADDRESS, 0x0100
 
          .equ START_ADDRESS, '''0xAD00'''                ; Relative to 0x0100
 
4. using Internal FRC and PLL16
 
        config __FOSC, CSW_FSCM_OFF & '''FRC_PLL16''' ;Turn off clock switching and
 
                                          ;fail-safe clock monitoring and
 
                                            ;use the Internal Clock as the
 
                                          ;system clock
 
5. disabling MCLR (optional)
 
        config __FBORPOR, PBOR_ON & BORV_27 & PWRT_16 & '''MCLR_DIS'''
 
                                            ;Set Brown-out Reset voltage and
 
                                            ;and set Power-up Timer to 16msecs
 
6. changing all the related registers of U1ART to U2ART, all U1XXX => U2XXX
 
        '''U2MODE, U2STA, U2BRG, U2RXREG, U2TXREG'''
 
7. changing all the related registers of IC1 to IC2, all IC1XXX => IC2XXX
 
        '''IC2CON, #IC2IF, #IC2IE'''
 
 
====Communication Protocol====
 
* Communication Protocol is reviewed in [http://www.ingenia-cat.com/reference/pdf/iBL.UG.V1.2.pdf user's guide] section 2.1.3. The following summarises the key steps on the PC side (Refer also to section 2.2.2).
 
* Transmission is conducted in 8N1, i.e. 8-bit, no parity, 1 stop-bit
 
* '''Stage 1: User's configuation'''
 
**Select a baudrate
 
**Select a COM port channel
 
* '''Stage 2: Autobaud rate detection and version control'''
 
**Continuously sending a character "U" [0x55] via COM port
 
**Continuously waiting for an acknowledgment character "U", [ACK] = [0x55]
 
**Send command character [0x03]
 
**Receive 3 characters 1) Major Version 2) Minor Version 3) Acknowledgment [0x33]
 
**Prints the version number [Major.Minor] (e.g. 1.1) on screen.
 
* '''Stage 3: Loading and writing the program'''
 
**Load the user hex file, check integrity.
 
**Start loading file using:
 
***Read command character [0x01] + 24-bit address [High][Medium][Low]
 
***Receive 4-byte data [High][Medium][Low][ACK]
 
***Write command character [0x02] + 24-bit address [High][Medium][Low]+ Number of bytes [N] + [data 0] + [data 1] + ... + [data N-1] + [CRC]=(INTEL HEX8 Checksum - Sum modulo 256)
 
***Recieve [ACK] or [NACK] = [0xFF]
 
***Note: Writing is in row mode access (i.e. erase and write a whole row, each row has 32 instructions, or 96 bytes because each instruction has 24 bits)
 
::# Ensure the initial address of writing match an initial row position,
 
::# Send the data corresponding to the whole row.
 
 
===USB/RS232 Interface===
 
*Window Driver for [http://www.prolific.com.tw/eng/downloads.asp?ID=31 PL-2303 USB to Serial Bridge]
 
*[Java library http://www.rxtx.org/]
 
  
 +
==[[freertos_posix Development | Driver Development]]==
 +
*Description on developing drivers with POSIX API
  
==Programming the Device==
 
  
===Requirements===
+
==[[Bootloader Development]]==
*Hardware
+
*Description on concepts and development on bootloader
#PC with COM port (Windows XP Installed)
+
*Description on dsPicProgrammer to download firmware via bootloader
#ICD2 Programmer
 
#Target Board
 
#5V Power Supply
 
  
*Software
 
#[http://ww1.microchip.com/downloads/en/DeviceDoc/MP750.zip MPLAB IDE v7.50 or higher]
 
#[http://www.ingenia-cat.com/download/ingeniadsPICbootloader1.1.zip ingenia dsPIC bootloader GUI v1.1 or higher]
 
  
*Files
+
==[[Programming the Device]]==
#Modified ingenia bootloader ('''ingenia.hex'''). Original assembly code can be downloaded from [http://www.ingenia-cat.com/download/iBL.s here].
+
*Description on how to use dsPicProgrammer to download firmware to dspic
#Application hex file (e.g. '''app.hex''')
 
  
===Procedures===
 
====Loading Bootloader====
 
*Install [http://ww1.microchip.com/downloads/en/DeviceDoc/MP750.zip MPLAB IDE] on PC
 
#Do '''NOT''' connect ICD 2 (via USB) to PC
 
#Execute '''MPLAB vX.XX Install.exe'''
 
*Install USB Driver for ICD 2
 
#Follow the instruction in (C:\Program Files\Microchip\MPLAB IDE\ICD2\Drivers\Ddicd2.htm)
 
*Run MPLAB IDE on PC
 
*Select target chip
 
#Select: Configure>Select Devices...
 
#Choose dsPIC30F5011
 
*Plug-in ICD 2 to PC (USB)
 
#Do '''NOT''' connect target (via 6-pin cable) to ICD 2
 
*Select ICD 2 as the current programmer
 
#Select: Programmer>Select Programmer>MPLAB ICD 2
 
#If this is the first time the ICD 2 is connected to PC, MPLAB IDE will automatically download the required OS to ICD 2, wait until it has finished
 
#You should also see Warnings on invalid device IDs, and/or running self tests. Ignore these warnings since the target board has not been connected yet.
 
*Place Jumper on target board
 
*Connect target board to ICD 2 (via six pin cable)
 
#Beware of the pin assignments. Only pin 1 - 5 should be used.
 
*Power-up the Target
 
*Establish connection with target
 
#On MPLAB IDE, Select Programmer>Connect
 
#See results of self test: Programmer>Settings, Status Tab. Refer to [http://ww1.microchip.com/downloads/en/DeviceDoc/51331B.pdf ICD2 User's Guide] Chapter 7.
 
*Load the bootloader hex file '''ingenia.hex''' on MPLAB IDE
 
#Select: File>Import...
 
*Download the bootloader to target board
 
#Select: Programmer>Program
 
*Power-down the Taget.
 
*Disconnect ICD 2 from PC
 
#Select: Programmer>Select Programmer>None
 
#Unplug USB cable
 
  
====Loading Application====
+
[[category:projects]]
*Install ingenia dsPIC bootloader GUI on PC
 
#Execute '''ingeniadsPICbootloader.exe'''
 
*Connect target board to COM Port
 
*Power-down target board
 
*Run ingenia dsPIC bootloader GUI
 
*Press "OK, my platform is shut down" in Dialog 0
 
*Select COM port and baud rate in Dialog 1
 
*Power-up target board in Dialog 2
 
*Load the '''app.hex''' by pressing Open in Dialog 3
 
*Download the hex file by pressing Write in Dialog 3
 
*Power-down target board and disconnect from COM port
 

Latest revision as of 07:30, 16 October 2012

This project aims to provide the development tools for building a multi-purpose MCU board. Description is based on Microchip dsPic33FJ256GP506 (was dsPic30F5011), but information provided in this wiki may give useful directions for developing similar embedded systems with different platforms.

Introduction

Features of dsPic33FJ256GP506

  • 3.0 to 3.3 V
  • Up to 40 MIPs
  • Maximum current sink/source for I/O pins: 4 mA
  • 16-bit arithmetics
  • DSP Instruction Set
  • Dual programming techniques: ICSP and RTSP
  • Memory
    • 256 KB flash (86K instructions)
    • 16 KB RAM (incl. 2 KB DMA RAM)
    • No EEPROM
  • Communications ports
    • UART
    • I2C: up to 1 Mbit/s
    • SPI
  • ADC
  • 10-bit A/D, 1.1 Msps
  • 12-bit A/D, 500 ksps
  • No DAC (PWMs only)
  • Pin-to-pin compatible with other dsPICs
Comparison between different dsPICs
dsPic *Price
US$
MIPs Flash
(kB)
RAM
(kB)
EEPROM
(kB)
I/O ADC
12-bit
IC OC Motor
Ctrl
Timers QEI UART SPI I2C CAN Codec
33FJ256GP506 6.11 40 256 16 0 53 18 8 8 0 9x16bit
4x32bit
0 2 2 2 1 1
33FJ128GP206 4.62 40 128 8 0 53 18 8 8 0 9x16bit
4x32bit
0 2 2 1 0 1
33FJ128GP306 4.81 40 128 16 0 53 18 8 8 0 9x16bit
4x32bit
0 2 2 2 0 1
33FJ128GP706 5.49 40 128 16 0 53 18 8 8 0 9x16bit
4x32bit
0 2 2 2 2 1
33FJ128MC506 4.97 40 128 8 0 53 16 8 8 8 9x16bit
4x32bit
1 2 2 2 1 0
33FJ128MC706 5.38 40 128 16 0 53 16 8 8 8 9x16bit
4x32bit
1 2 2 2 1 0

*For reference only, subject to change

Forums

  • Microchip: Official forum by Microchip
    • See MPLAB ICD 2, MPLAB IDE, MPLAB C30 Compiler, ASM30, Link30 forum, dsPIC30F Topics, dsPic33 topics
  • HI-TECH Software Forum: Discussion on dsPICC, a C compiler developed by HI-TECH
  • FreeRTOS Real Time Kernel: Open Discussion and Support on FreeRTOS
  • Nabble: MicroControllers - GNUPIC

References

Code Examples

Related Development


Programming Methods

  • There are 2 programming methods: In-Circuit Serial Programming (ICSP) and Run-Time Self-Programming (RTSP)
  • ICSP allows the devices to be programmed after being placed in a circuit board.
  • RTSP allows the devices to be programmed when an embedded program is already in operation.

ICSP: External Programmer (ICD2)

  • Two types of ICSP are available: ICSP and Enhanced ICSP. Both of them require setting MCLR# to VIHH (9V – 13.25V).
  • Standard ICSP
    • Use external programmer (e.g. MPLAB® ICD 2, MPLAB® PM3 or PRO MATE® II) only.
    • Required low-level programming to erase, program and verify the chip.
    • Slower, because codes are serially executed.
  • Enhanced ICSP
    • Use external programmer and Programming Executive (PE).
    • PE is stored in the on-chip memory.
    • PE allows faster programming.
    • PE can be downloaded to the chip by external programmer using the standard ICSP method.
    • PE contains a small command set to erase, program and verify the chip, avoiding the need of low-level programming.

Hardware Interface

Pin Used by ICSP
Pin Label Function Pin Number
MCLR# Programming Enable 7
VDD Power Supply 10, 26, 38, 57
VSS Ground 9, 25, 41, 56
PGC Serial Clock 17
PGD Serial Data 18


Available Programmers in the Market
Product Name Interface with PC Interface with Device *Price (US) Remarks
MPLAB® ICD 2 USB or RS232 6-PIN RJ-12 connector $159.99 -
Clone Microchip ICD2 (Now Using) USB 6-pin flat cables $52.35 Do not work with new MPLAB versions (works for 7.50), communication to MPLAB may sometime hang (see manual)

*For reference only (exclude shipping), subject to change


DIY ICD 2 Programmer Circuit
Source Schematic PIC16F877A Bootloader
Patrick Touzet Yes HEX
Nebadje Yes Zip


Software Interface

  • The program can be written and compiled in an Integrated Development Environment (IDE) using either Assembly or C. The complied codes are then loaded to the device through the external programmer.
Summary of IDE
Product Name Features OS Price (US$)
MPLAB® IDE Assembler Only Windows Free
MPLAB® C30 Assembler and C-Compiler Windows $895.00 (Free student version1)
Piklab Assembler and C-Compiler Linux Free
  1. Full-featured for the first 60 days. After 60 days, some code optimization functions are disabled. The compiler will continue to function after 60 days, but code size may increase.

RTSP: COM Port (Bootloader)

  • RTSP works in normal voltage (MCLR# no need to raise to VIHH).
  • No literature has mentioned the incorporation of Programming Executive (PE). Presumably, since Enhanced ICSP needs to set MCLR# to VIHH, RTSP cannot use PE.
  • Refer to bootloader section.


Development Environment

Windows

PIC setup win.JPG

  • C-Compiler, Assembler and Linker are under GNU license.
    • MPLAB C30 C Compiler (*.c -> *.s)
    • MPLAB ASM30 Assembler (*.s -> *.o)
    • MPLAB LINK30 Linker (*.o -> *.bin)
  • PA optimizer, simulator, runtime libraries, header files, include files, and linker scripts are not covered by GNU. Reference is here.
  • Microchip has integrated ASM30, LINK30, assembly header files, linker scripts in MPLAB IDE, which is free for download.
  • MPLAB C30 costs US$895. A 60-day free student version is also available. After 60-days, the optimizer is automatically disabled, while other tools can still function properly.


C Libraries in MPLAB C30
Library Directory
(\\Microchip\MPLAB C30)
Major functions
DSP Library
(e.g. libdsp-coff.a)
\lib
\src\dsp
\support\h
Vector, Matrix, Filter, etc.
16-Bit Peripheral Libraries \lib
\src\peripheral
\support\h
ADC12, IOPort, UART, I2C, etc.
Standard C Libraries
(e.g. libc-coff.a, libm-coff.a, libpic-coff.a)
\lib
\src\libm
\include
stdio.h, time.h, float.h, math.h,
MPLAB C30 Built-in Functions none _buildin_addab, _buildin_add, _buildinmpy, etc

Linux

PIC setup linux.JPG

  • C Compiler, Assembler and Linker are under GNU license.
    • The code can be downloaded from Microchip at here.
    • Current MPLAB ASM30 Assembler: v2.04
    • Current MPLAB C30 Compiler: v2.04
  • Important Note: Only the compiler is free. The header files and library are owned by Microchip.
Pic30 C-Compiler Toolchain Templates for Conversion to Debian-based systems
Toolchain Source Instruction Remarks
v2.00 Download pic30-gcc-2.00-1.i386.rpm and pic30-binutils-2.00-1.i386.rpm.
Convert to deb files.
Stable
Now using
v2.05 Reference to example below, but use 2.05 files Can compile
Stable but not heavily tested
v3.01 Follow example below Can compile
Unstable (sometime produce segmentation fault)
v3.10 Reference to example below, but use 3.10 files Cannot compile yet (segmentation fault)

Conversion Example

  • Pre-install these packages: dpkg-dev, debhelper, bison, flex, sysutils, gcc-3.3, fakeroot
    • cmd: sudo apt-get install dpkg-dev debhelper bison flex sysutils gcc-3.3 fakeroot
  • Download and unzip template: pic30-3.01.tar.bz2
  • Download assembler: mplabalc30v3_01_A.tar.gz. Save under /pic30-3.01/pic30-binutils-3.01/upstream/
  • Download c-compiler: mplabc30v3_01_A.tgz. Save under /pic30-3.01/pic30-gcc-3.01/upstream/
  • Install MPLAB_C30_v3_01-StudentEdition under Windows
  • Copy directories /include, /lib, /support, and /bin/c30_device.info to pic30-3.01/pic30-support-3.01/upstream/
  • Pack pic30-binutils into deb file
    • goto /pic30-3.01/pic30-binutils-3.01/
    • type cmd: dpkg-buildpackage -rfakeroot -b
  • Install pic30-binutils_3.01-1_i386.deb
    • type cmd: sudo dpkg -i pic30-binutils_3.01-1_i386.deb
  • Pack pic30-gcc-3.01 into deb file
    • goto /pic30-3.01/pic30-gcc-3.01/
    • type cmd: dpkg-buildpackage -rfakeroot -b
  • Install pic30-gcc_3.01-1_i386.deb
    • type cmd: sudo dpkg -i pic30-gcc_3.01-1_i386.deb
  • Pack support files into deb file
    • goto /pic30-3.01/pic30-support-3.01/
    • type cmd: dpkg-buildpackage -rfakeroot -b
  • Install pic30-support_3.01-1_all.deb
    • type cmd: sudo dpkg -i pic30-support_3.01-1_all.deb
  • After installation, locations of
    • C-Header (*.h): /usr/pic30-elf/include
    • Libraries (*.a): /usr/pic30-elf/lib
    • Assembly header (*.inc): /usr/share/pic30-support/inc
    • Linkerscript (*.gld): /usr/share/pic30-support/gld

Burning Program Codes to Target Board

  1. Use 'dspicprg and dspicdmp' utilities developed by Homer Reid to burn hex code (*.hex) to devices. See Reference here. Through serial port only?
  2. Use Piklab IDE. Details on file format not known.
  3. Use MPLAB IDE to burn hex code (*.hex) to devices.

Code Optimization

  • Below is a comparsion between different optimization levels for the project including drivers for 2 projects.
Comparison between differnt optimization levels
Optimization Description Project 1
Code Size
(byte)
Project 1
Data Usage
(byte)
Project 2
Code Size
(byte)
Project 2
Data Usage
(byte)
O0 No optimization
Fastest Compilation
6222 (9%) 178 (4%) 26,037 (38%) 710 (17%)
O1 Optimize
Tries to reduce code size and execution time.
4473 (6%) 178 (4%) 22,290 (32%) 710 (17%)
O2 Optimize even more
Performs nearly all supported optimizations
that do not involve a space-speed trade-off.
Increases both compilation time and the
performance of the generated code.
4422 (6%) 178 (4%) 21,993 (32%) 710 (17%)
O3 Optimize yet more.
O3 turns on all optimizations specified by O2
and also turns on the inline-functions option.
4485 (6%) 178 (4%) 22,176 (32%) 710 (17%)
Os Optimize for size.
Os enables all O2 optimizations that do not
typically increase code size. It also performs
further optimizations designed to reduce code
size.
4356 (6%) 178 (4%) 21,885 (32%) 710 (17%)


Driver Development

  • Description on developing drivers with POSIX API


Bootloader Development

  • Description on concepts and development on bootloader
  • Description on dsPicProgrammer to download firmware via bootloader


Programming the Device

  • Description on how to use dsPicProgrammer to download firmware to dspic