34
DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board 1 от 34 05.3.2007 г. 14:43 DsPIC30F 5011 Development Board From Open Circuits Contents 1 Introduction 1.1 Features of dsPIC30F5011 1.2 Web Page 1.3 Forum 1.4 References 2 Programming Methods 2.1 ICSP: External Programmer (ICD2) 2.1.1 Hardware Interface 2.1.2 Software Interface 2.2 RTSP: COM Port (Bootloader) 3 IC Requirements 4 Development Environment 4.1 Windows 4.2 Linux 4.3 Code Optimization 5 Software Architecture 6 Programming Tips 6.1 Memory Map for 5011 6.2 Data Location 6.3 Configuration Bits 6.4 Timer 6.4.1 Free Time Clock 6.4.2 Time Measurement 6.5 Interrupt 6.6 UART 6.6.1 Auto baud rate detection 6.6.2 Initialize UART 6.6.3 Sending and Receiving Data 6.7 I2C 6.8 ADC 6.8.1 Configuration 6.8.2 Storing ADC Data 6.8.3 Adding and Removing Channels 6.9 EEPROM 6.9.1 Seek 6.9.2 Read 6.9.3 Write 6.10 Simple PWM (Output Compare Module) 6.10.1 open() 6.10.2 ioctl() 6.10.3 write() 6.10.4 Propagration Delay 6.11 DSP Library 6.11.1 Data Types

DsPIC30F 5011 Development Board - Open Circuits

Embed Size (px)

Citation preview

Page 1: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

1 от 34 05.3.2007 г. 14:43

DsPIC30F 5011 Development BoardFrom Open Circuits

Contents

1 Introduction1.1 Features of dsPIC30F50111.2 Web Page1.3 Forum1.4 References

2 Programming Methods2.1 ICSP: External Programmer (ICD2)

2.1.1 Hardware Interface2.1.2 Software Interface

2.2 RTSP: COM Port (Bootloader)3 IC Requirements4 Development Environment

4.1 Windows4.2 Linux4.3 Code Optimization

5 Software Architecture6 Programming Tips

6.1 Memory Map for 50116.2 Data Location6.3 Configuration Bits6.4 Timer

6.4.1 Free Time Clock6.4.2 Time Measurement

6.5 Interrupt6.6 UART

6.6.1 Auto baud rate detection6.6.2 Initialize UART6.6.3 Sending and Receiving Data

6.7 I2C6.8 ADC

6.8.1 Configuration6.8.2 Storing ADC Data6.8.3 Adding and Removing Channels

6.9 EEPROM6.9.1 Seek6.9.2 Read6.9.3 Write

6.10 Simple PWM (Output Compare Module)6.10.1 open()6.10.2 ioctl()6.10.3 write()6.10.4 Propagration Delay

6.11 DSP Library6.11.1 Data Types

Page 2: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

2 от 34 05.3.2007 г. 14:43

6.11.2 Overflow and Saturation Traps6.12 Build-in Library

7 Bootloader Development7.1 Concepts7.2 dsPicBootloader7.3 dsPicProgrammer (Java-based Multi-Platformed)7.4 Special Consideration7.5 Downloads7.6 Communication Protocol

8 USB-RS232 Bridge8.1 FDTI Chipset

9 Programming the Device9.1 Requirements9.2 Loading Bootloader (Once only)9.3 Loading Application

10 Remote Access10.1 Requirements10.2 API Reference for VxWorks

11 Conversion to dsPIC33F Devices (Not Tested)11.1 Hardware11.2 Software

11.2.1 Configuration Bits11.2.2 UART11.2.3 I2C11.2.4 ADC11.2.5 EEPROM11.2.6 Simple PWM

11.3 Memory Map for dsPIC33FJ128GP30611.4 dsPicBootloader11.5 dsPicProgrammer

12 To Do List

Introduction

Features of dsPIC30F5011

2.5 to 5VUp to 30MIPsHigh current/sink source I/O pins: 25mADSP Instruction SetDual programming techniques: ICSP and RTSPUART: up to 2 modulesI2C: up to 1Mbps10-bit A/D, 1.1 Msps12-bit A/D, 200 ksps44K flash (66Kb), 4Kb RAM, 1Kb EEPROMNo DACPin-to-pin compatible with other dsPICs

Table 1.1 Comparison with Compatible dsPICs

dsPic PriceUS$ MIPs Flash

(kB)RAM(kB)

EEPROM(kB) I/O ADC

12-bit IC OC MotorCtrl Timers QEI UART

Page 3: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

3 от 34 05.3.2007 г. 14:43

30F5011 5.91 30 66 4 1 52 16 8 8 0 5x16bit2x32bit 0 2

30F6011A 7.73 30 132 6 2 52 16 8 8 0 5x16bit2x32bit 0 2

30F6012A 7.85 30 144 8 4 52 16 8 8 0 5x16bit2x32bit 0 2

33FJ128GP206 4.62 40 128 8 0 53 18 8 8 0 9x16bit4x32bit 0 2

33FJ128GP306 4.81 40 128 16 0 53 18 8 8 0 9x16bit4x32bit 0 2

33FJ128GP706 5.49 40 128 16 0 53 18 8 8 0 9x16bit4x32bit 0 2

33FJ128MC506 4.97 40 128 8 0 53 16 8 8 8 9x16bit4x32bit 1 2

33FJ128MC706 5.38 40 128 16 0 53 16 8 8 8 9x16bit4x32bit 1 2

33FJ256GP506 6.11 40 256 16 0 53 18 8 8 0 9x16bit4x32bit 0 2

Web Page

Microchip Official Website(http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2529&param=en024856

Forum

Microchip (http://direct.forum.microchip.com/default.aspx) : Official forum by MicrochipMPLAB ICD 2 (http://direct.forum.microchip.com/tt.aspx?forumid=49) : Subforum on ICD 2 programmerMPLAB IDE (http://direct.forum.microchip.com/tt.aspx?forumid=57) : Subforum on IDEMPLAB C30 Compiler, ASM30, Link30 forum(http://direct.forum.microchip.com/tt.aspx?forumid=101) : Subforum on C compiler. Refer to MPLAB C30 C Compiler User's Guide(http://ww1.microchip.com/downloads/en/DeviceDoc/C30_Users_Guide_51284e.pdf) Chapter 3dsPIC30F Topics (http://direct.forum.microchip.com/tt.aspx?forumid=153) : Subformum ondsPIC30F

GNUPIC (http://www.gnupic.org/) : Discussion on PIC in Linux SystemsDebian (http://www.linuxhacker.org/cgi-bin/ezmlm-cgi?1:dds:5443#b)

HI-TECH Software Forum (http://www.htsoft.com/forum/all/ubbthreads.php/Cat/0/C/6) : Discussion on dsPICC, a C compiler developed by HI-TECHPICList (http://piclist.com/techref/piclist/index.htm) : Discussion on older PIC systems (not dsPIC)PicKit (http://groups.google.com/group/pickit-devel) : Discussion on PICkit/PICkit 2 programmersFreeRTOS Real Time Kernel (http://sourceforge.net/forum/forum.php?forum_id=382005) : Open Discussion and Support on FreeRTOS

References

dsPIC30FFamily Overview (http://ww1.microchip.com/downloads/en/DeviceDoc/70043F.pdf) Family Reference Manual (http://ww1.microchip.com/downloads/en/DeviceDoc/70046E.pdf) :

Page 4: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

4 от 34 05.3.2007 г. 14:43

Contains detailed descriptions on dsPIC30F register definitions and example codes5011 Data Sheet (http://ww1.microchip.com/downloads/en/DeviceDoc/70116F.pdf) Flash Programming Specification (http://ww1.microchip.com/downloads/en/DeviceDoc/70102G.pdf) Programmer Reference Manual (http://ww1.microchip.com/downloads/en/DeviceDoc/70157B.pdf)

dsPIC33FProduct Overview (http://ww1.microchip.com/downloads/en/DeviceDoc/70155c.pdf) Family Data Sheet (http://ww1.microchip.com/downloads/en/DeviceDoc/70165E.pdf) Flash Programming Specification (http://ww1.microchip.com/downloads/en/DeviceDoc/70152C.pdf) dsPIC30F to dsPIC33F Conversion Guidelines(http://ww1.microchip.com/downloads/en/DeviceDoc/70172A.pdf)

ICD2 ProgrammerICD2 User's Guide (http://ww1.microchip.com/downloads/en/DeviceDoc/51331B.pdf)

MPLABMPLAB IDE User's Guide (http://ww1.microchip.com/downloads/en/DeviceDoc/51519B.pdf)

C30 CompilerMPLAB C30 C Compiler User's Guide(http://ww1.microchip.com/downloads/en/DeviceDoc/C30_Users_Guide_51284e.pdf) : Contains commands for using pic30-elf-gcc16-bit Language Tools Libraries(http://ww1.microchip.com/downloads/en/DeviceDoc/16bit_Language_Tool_Libraries_51456c.pdf) : Contains summaries and examples of using DSP libraries, standard C libraries and device librariesMPLAB ASM30, MPLAB LINK30 and Utilities User's Guide(http://ww1.microchip.com/downloads/en/DeviceDoc/Asm30_Link_Util_51317e.pdf) dsPIC30F Language Tools Quick Reference Card(http://ww1.microchip.com/downloads/en/DeviceDoc/51322d.pdf)

Programming Methods

There are 2 programming methods: In-Circuit Serial Programming (ICSP) and Run-TimeSelf-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.Program memory can be erased using Normal-Voltage (4.5 – 5.5V) or Low-Voltage (2.5V – 4.5V).

Enhanced ICSPUse 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

Page 5: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

5 от 34 05.3.2007 г. 14:43

Table 2.1 Pin Used by ICSPPin 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

Product Name

MPLAB® ICD 2(http://direct.www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046&part=DV164005

Full Speed USB Microchip ICD2Debugger and Programmer (http://www.etekronics.com/product_info.php?cPath=24&products_id=48)

Mini Microchip Compatible ICD2Debugger and Programmer (http://www.etekronics.com/product_info.php?cPath=24&products_id=47)

ICDX30 (http://www.inexglobal.com/microcontroller.php)

Clone Microchip ICD2 (http://www.sure-electronics.net/englishsite/icd2/icd2.htm)

Table 2.3 DIY ICD 2 Programmer CircuitSource Schematic

Patrick Touzet(http://membres.lycos.fr/silicium31/Electronique/PIC/FreeIcdEnglish.htm)

Yes(http://membres.lycos.fr/silicium31/Electronique/PIC/ICD2%20V1.3.pdf

Nebadje (http://www.nebadje.org/doku.php?id=neblab:icd2clone) Yes (http://people.ee.ethz.ch/~jbiveron/nebadje/ICD2_DOC.pdf

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.

Page 6: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

6 от 34 05.3.2007 г. 14:43

Table 2.4 Summary of IDE

Product Name

MPLAB® IDE(http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002

MPLAB® C30(http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010065&part=SW006012

Piklab 0.12.0 (http://linux.softpedia.com/get/Science-and-Engineering/Electronic-Design-Automation-EDA-/Piklab-8099.shtml

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.

1.

The current version supports external programmer ICD 2, but not yet tested.2.

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.

IC Requirements

Table 3.1 IC Requirements

Part No. Description Min Temp

Max Temp

dsPIC30F5011-30I/PT(http://ww1.microchip.com/downloads/en/DeviceDoc/70116F.pdf)

uP -40oC 85o

MAX3232ESE (http://datasheets.maxim-ic.com/en/ds/MAX3222-MAX3241.pdf) RS232 driver -40oC 85o

DS3695N (http://www.national.com/ds.cgi/DS/DS3695.pdf) RS485 driver -40oC 85o

DAC6574DGS (http://focus.ti.com/lit/ds/symlink/dac6574.pdf) 10-bit Quad-DAC I2C

-40oC 105

74HC14D(http://www.semiconductors.philips.com/acrobat/datasheets/74HC_HCT14_3.pdf)

Quad-Schmitt Trigger -40oC 125

Overall -40oC 85o

dsPIC33FJ128GP306(http://ww1.microchip.com/downloads/en/DeviceDoc/70165E.pdf) uP -40oC 85o

ADM3485EARZ(http://www.analog.com/UploadedFiles/Data_Sheets/ADM3485E.pdf) RS485 driver -40oC 85o

Page 7: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

7 от 34 05.3.2007 г. 14:43

Minimum voltage measured is 3.3V (with 2 LEDs blinking) running at 30MHz.1.Measured current at 5V is 180mA (with 2 LEDs blinking only)2.

Development Environment

Windows

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 (http://direct.forum.microchip.com/tm.aspx?m=107208) .

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.

C-libraries contained in C30 includes (Refer to 16-Bit Language Tools Libraries(http://ww1.microchip.com/downloads/en/DeviceDoc/16bit_Language_Tool_Libraries_51456c.pdf) from Microchip).

Table 4.1 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 (e.g. libp30F5011-coff.a)

\lib \src\peripheral \support\h

ADC12, IOPort, UART, I2C, etc.

Page 8: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

8 от 34 05.3.2007 г. 14:43

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

C Compiler, Assembler and Linker are under GNU license.The code can be downloaded from Microchip at here(http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023073.Current MPLAB ASM30 Assembler: v2.04Current MPLAB C30 Compiler: v2.04

John Steele Scott (http://gcc.gnu.org/ml/gcc/2005-02/msg01144.html) 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.

Download pic30-1.32-debian.tar.bz2 for Template v1.32. (For v2.01, please goto pic30-debian-2.01.tar.bz2(http://thread.gmane.org/gmane.comp.hardware.microcontrollers.gnupic/3768/focus=3768) ).Download pic30-binutils_1.32-1_i386.deb for the assember.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 here(http://www.baycom.org/~tom/dspic/) .Instructions for filling the upstream direction is available here(http://forum.microchip.com/printable.aspx?m=139360) .Alteratively, Stephan Walter (https://gna.org/projects/pic30-libc/) 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 Homer Reid (http://homerreid.ath.cx/misc/dspicprg/) to burn hex code (*.hex) to devices. See Reference here (http://forum.microchip.com/tm.aspx?m=94243) . Through serial port only?

1.

Page 9: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

9 от 34 05.3.2007 г. 14:43

Use Piklab IDE (http://piklab.sourceforge.net/) . Details on file format not known.2.Use MPLAB IDE(http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002to burn hex code (*.hex) to devices.

3.

Code Optimization

Code Optimization under GNU license supports O0 and O1 only.MPLAB C-Compiler supports O0, O1, O2, Os and O3. The Student version will disable O2, Os, and O3after 60 days.Below is a comparsion between different optimization levels for the project including drivers for 2projects.

Table 4.2 Comparison between differnt optimization levels

Optimization Description

Project 1Code Size

(byte)

Project 1Data

Usage(byte)

Project 2Code Size

(byte)

Project 2Data

Usage(byte)

O0 No optimizationFastest Compilation

6222 (9%)

178 (4%) 26,037 (38%)

710 (17%)

O1 OptimizeTries to reduce code size and execution time.

4473 (6%)

178 (4%) 22,290 (32%)

710 (17%)

O2 Optimize even morePerforms 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%)

Software Architecture

Page 10: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

10 от 34 05.3.2007 г. 14:43

Currently, operating system is based on linlike8(http://www.psocdeveloper.com/forums/viewtopic.php?p=973&sid=717d6b7e86472a5036f7cfbbcb0c05aa. The possibility of using other OS (e.g. FreeRTOS (http://www.freertos.org/) ) will be explored later.Software Drivers are to be developed to allow users at Application Level to use the hardware (e.g. ADC, DAC, UART, EEPROM) through the OS.The interface between the drivers and the OS should be compliant with POSIX standard(http://www.die.net/doc/linux/man/man2/) for Linux (e.g. open(), write(), read(), ioctl() etc).

Programming Tips

Memory Map for 5011

Table 6.1 Memory LocationType Start Address End Address Size

Flash 0x000000 0x00AFFF 44K[1]

+--Flash: Reset Vector 0x000000 0x000003 4

+--Flash: Interrupt Vector Table 0x000004 0x00007F 124

+--Flash: Alternate Vector Table 0x000084 0x0000FF 124

+--Flash: User Program 0x000100 0x00AFFF 43.7K

EEPROM 0x7FFC00 0x7FFFFF 1K[2]

Programming Executive 0x800000 0x8005BF 1472

Unit ID 0x8005C0 0x8005FF 64

Config Registers 0xF80000 0xF8000F 16

Device ID 0xFF0000 0xFF0003 4

[1] Each address is 16-bit wide. Every two addresses correspond to a 24-bit instruction. Each even address contains 2 valid bytes; each odd address contains 1 valid byte plus 1 phathom byte.[2] Each address is 8-bit wide.

Data Location

+----------+-----------+---------+---------+ | local | remote | | | +----------+-----------+ host | UI | | data access | channel | | | (DI,DO,AI,AO) | | | +----------------------+---------+---------+ | Application | | | +------------------------------------------+ | Applications Model | | +--------------+-----------+ | | | GUI | CLib | | | | +------+-----------+-------+ | | | Operating System | +-------+-------+--------------------------+ | Drivers | +------------------------------------------+ | Hardware | +------------------------------------------+

Page 11: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

11 от 34 05.3.2007 г. 14:43

Table 6.2 Data LocationType Description Example

_XBSS(N) [1] RAM Data in X-memory, aligned at N, no initilization

int _XBSS(32) xbuf[16];

_XDATA(N) [1] RAM Data in X-memory, aligned at N, with initilization

int _XDATA(32) xbuf[] = {1, 2, 3, 4, 5};

_YBSS(N) [1] RAM Data in Y-memory, aligned at N, no initilization

int _YBSS(32) ybuf[16];

_YDATA(N) [1] RAM Data in Y-memory, aligned at N, with initilization

int _YDATA(32) ybuf[16] = {1, 2, 3, 4, 5};

__attribute__((space(const))) Flash ROM data, constant, accessed by normal Cstatements, but 32K max.

int i __attribute__((space(const))) = 10;

__attribute__((space(prog))) Flash ROM data, read/write by program space visibilitywindow (psv)

int i __attribute__((space(prog)));

__attribute__((space(auto_psv))) Flash ROM data, read by normal C statements, writeby accessing psv

int i __attribute__((space(auto_psv)));

__attribute__((space(psv))) Flash ROM data, read/write by (psv)

int i __attribute__((space(psv)));

_EEDATA(N) [1] ROM Data in EEPROM, aligned at N, read/write with psv

int _EEDATA(2) table[]={0, 1, 2, 3, 5, 8};

_PERSISTENT RAM Data, data remain after reset

int _PERSISTENT var1, var2;

_NEAR RAM Data at near section int _NEAR var1, var2;

_ISR Interrupt service rountine void _ISR _INT0Interrupt(void);

_ISRFAST Fast interrupt service rountine void _ISRFAST _T0Interrupt(void);

N must be a power of two, with a minimum value of 2.1.

Configuration Bits

System clock source can be provided by:

Primary oscillator (OSC1, OSC2)1.Secondary oscillator (SOSCO and SOSCI) with 32kHz crystal2.Internal Fast RC (FRC) oscillator at 7.37MHz (7372800Hz)3.Low-Power RC (LPRC) oscillator (Watchdog Timer) at 512 kHz.4.

These clock sources can be incorporated with interal Phase-locked-loop (PLL) x4, x8 or x16 to yield the osciallator frequrence FOSCThe system clock is divided by 4 to yield the internal instruction cycle clock, FCY=FOSC/4FRC with PLLx16 is used to achieve FCY=29.49MHz (29491200Hz or 30MIPS)

Page 12: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

12 от 34 05.3.2007 г. 14:43

Timer

Each timer is 16-bit (i.e. counting from 0 to 65535).Timer 2 and 3 can be incorporated together to form a 32-bit timer.Prescale is the ratio between timer counts and system clock counts. Prescales of 1:1, 1:8, 1:64 and 1:256 are available.Timers may be used to implement free time clock or mesaure time.

Free Time Clock

Let required time for ticking be PERIOD.Number of instruction cycles during PERIOD = PERIOD*FCY cyclesUsing a prescale of 1:x, the timer period count register = # of cycles/xe.g. PERIOD = 10ms; # of cycles = 10ms*30MHz = 300000 cylces; Using 1:64 Prescale, register setting = 300000/64 = 4688

Time Measurement

To measure the time taken for action(), use the code below:

Interrupt

Registers are involved in Interrupts includes:

//The code (MACRO) below is to be placed at the top of program (before main) _FOSC(CSW_FSCM_OFF & FRC_PLL16); _FWDT(WDT_OFF); //Turn off Watchdog Timer _FBORPOR(PBOR_ON & BORV_27 & MCLR_DIS & PWRT_16); _FGS(CODE_PROT_OFF); //Disable Code Protection

void time_init(void){ TMR1 = 0; // Clear register PR1 = 4688; // Set period //============================================================ _T1IF = 0; // Clear interrupt flag _T1IE = 1; // Enable interrupts //============================================================ T1CONbits.TCS = 0; // Use internal clock source T1CONbits.TCKPS = 2; // Prescale Select 1:64 T1CONbits.TON = 1; // Start the timer } //******************************************************************** void _ISRFAST _T1Interrupt(void){ _T1IF = 0; // Clear interrupt flag //Place user code here }

unsigned int measure_time(void){ PR3 = 0xFFFF; // Set counter to maximum _T3IF = 0; // Clear interrupt flag _T3IE = 0; // Disable interrupt T3CONbits.TON = 1; // Start the timer, TMR3 count up TMR3 = 0; //Clear TMR3 to start count up //==================================================== //Add code here to wait for something to happen action(); //==================================================== T3CONbits.TON = 0; //Stop the timer //==================================================== return (unsigned int) TMR3/FCY; //TMR/FCY yields the actual time }

Page 13: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

13 от 34 05.3.2007 г. 14:43

Interrupt Flag Status (IFS0-IFS2) registers1.Interrupt Enable Control (IEC0-IEC2) registers2.Interrupt Priority Control (IPC0-IPC10) registers3.Interrupt Priority Level (IPL) register4.Global Interrupt Control (INTCON1, INTCON2) registers5.Interrupt vector (INTTREG) register6.

User may assign priority level 0-7 to a specific interrupt using IPC. Setting priority to 0 disable a specific interrupt. Level 7 interrupt has the highest priority.Current priority level is stored in IPL. Setting IPL to 7 disables all interrupts (except traps). The followingMACROs are defined in <p30f5011.h>:

SET_CPU_IPL(ipl): Set IPL to ipl1.SET_AND_SAVE_CPU_IPL(save_to, ipl): Store the current IPL to save_to and then set to ipl2.RESTORE_CPU_IPL(saved_to): Restore the previously saved ipl3.

sti() and cli() are defined to enable and disable global interrupts for time critical functions:

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) isneeded.For UART communications compatiable with RS485 standard, an external driver (e.g. DS3695N) isneeded.

Auto baud rate detection

The method is provided by ingenia bootloader(http://www.opencircuits.com/DsPIC30F_5011_Development_Board) .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.

The relationship between uxbrg and TMR is

extern int SAVE_IPL; #define sti() RESTORE_CPU_IPL(SAVE_IPL) #define cli() SET_AND_SAVE_CPU_IPL(SAVE_IPL, 7) //============================================================ char adc_ioctl(unsigned char request, unsigned char* argp){ //... cli(); //Disable global interrupt for(;ch<=argp[0];ch++) adc_add_ch(argp[ch]); //Add adc channels sti(); //Enable global interrupt //... return 0; }

_ _ _ _ _ _ _|S|_|1|_|1|_|1|_|1|_|S|_ (S = Start Bit) <---------------> Measured Time

Page 14: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

14 от 34 05.3.2007 г. 14:43

Since UxBRG is computed by:

The following is the code for auto baud rate detection for U2ART:

For 30MIP, tested speeds of transmission include 9600bps, 19200bps, 28800bps, 38400bps and57600bps.

Initialize UART

Measured Time (in seconds) = t_count/Fcy uxbrg = 1/(Measured Time/8) = 8*Fcy/t_count

UxBRG = (Fcy/(16*Baudrate)) -1 = (Fcy/(16*8*Fcy/t_count)) -1 = t_count/128 -1

unsigned int uart2_autobaud(void){ 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); //2nd rising edge detected _IC2IF = 0; //Clear interrupt flag while(!_IC2IF); //3rd rising edge detected _IC2IF = 0; //Clear interrupt flag while(!_IC2IF); //4th rising edge detected _IC2IF = 0; //Clear interrupt flag while(!_IC2IF); //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; }

Page 15: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

15 от 34 05.3.2007 г. 14:43

Sending and Receiving Data

I2C

Two lines are devoted for the serial communication. SCL for clock, SDA for data.Standard communication speed includes

Standard speed mode: 100kHz1.Fast speed mode: 400kHz2.High speed mode: 3.4MHz3.

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:

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:

void uart2_init(void){ //================================================================= // Configure Baud rate // +-- Default Baud rate = 19.2 kbps // +-- U2BRG = 30e6 / (16 * 19200) - 1 = 97 unsigned int u2brg = 97; #if(AUTO_BAUD_DECT>0) u2brg = uart2_autobaud(); #endif U2BRG = u2brg; //================================================================= // Disable U2ART U2MODEbits.UARTEN = 0; //Disable U2ART module //================================================================= // Configure Interrupt Priority _U2RXIF = 0; //Clear Rx interrupt flags _U2TXIF = 0; //Clear Tx interrupt flags _U2RXIE = 1; //Receive interrupt: 0 disable, 1 enable _U2TXIE = 1; //Transmit interrupt: 0 disable, 1 enable //================================================================= // Configure Mode // +--Default: 8N1, no loopback, no wake in sleep mode, continue in idle mode // +--Diable autobaud detect // +--Enable U2ART module U2MODEbits.ABAUD = 0; //Disable Autobaud detect from U2RX U2MODEbits.UARTEN = 1; //U2ART enable //================================================================= // Configure Status // +--Default: TxInt when a char is transmitted, no break char // +--Default: RxInt when a char is received, no address detect, clear overflow // +--Enable Transmit U2STAbits.UTXEN = 1; //Tx enable }

void _ISR _U2TXInterrupt(void){ _U2TXIF = 0; //Clear Interrupt Flag if(tx_data_ready()) U2TXREG = tx_buf[POS]; //send next byte... } void _ISR _U2RXInterrupt(void){ _U2RXIF = 0; //Clear the flag if ( U2STAbits.URXDA ){ rx_buf[POS] = (unsigned char) U2RXREG; //Read the data from buffer } }

Pull-up resistor (min) = (Vdd-0.4)/0.003 ...... [See section 21.8 in Family reference manual]

Page 16: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

16 от 34 05.3.2007 г. 14:43

After sending a byte and receiving an acknowledgement from the slave device, ensure to change to idle state. For example:

ADC

12-bit ADC: (Max 16 Channels)Allow a maximum of 2 sets of analog input multiplexer configurations, MUX A and MUX B (Normallyuse one only).A maximum of 200kps of sampling rate when using auto sampling mode.

Configuration

Interrupt: Clear ADC interrupt flag and enable ADC interrupt. The ADC module will be set to interrupt when the specified channels are updated.

I/O: Set the corresponding TRISBX bits (digit i/o config) to input (i.e. = 1), and set corresponding bits in ADPCFG (analog config) to zero.

Scanning Mode: Scan mode is used. In this mode, the Sample and Hold (S/H) is switched between the channels specified by ADCSSL (Scan select register).

Reference Voltage for S/H: Only MUX A is used. By default, the negative reference voltage of the S/H is connected to VREF-.

Sampling Rate: TAD refers to the time unit for the ADC clock. To configure the ADC module at 200kbps,the minimum sampling time of 1TAD = 334ns is required. ADCS<5:0> in ADCON3 register is used to setthe time, which is given by:

StartI2C(); Nop(); //A small delay for hardware to respond

while(I2CCONbits.SEN); //Wait till Start sequence is completed

MasterWriteI2C(0x55);

while(I2CSTATbits.TBF); //Wait for transmit buffer to empty

while(I2CSTATbits.ACKSTAT); //Wait for slave acknowledgement

IdleI2C();

_ADIF = 0; //clear ADC interrupt flag _ADIE = 1; //enable adc interrupt

_TRISB2 = 1; //Set AN2 [Case Temp] as analog input _TRISB8 = 1; //Set AN8 [Power detect 0] as analog input _TRISB9 = 1; //Set AN9 [Power detect 1] as analog input _TRISB10 = 1; //Set AN10 [Current detect 0] as analog input _TRISB11 = 1; //Set AN11 [Temp detect 0] as analog input ADPCFG = 0xF0FB; //0 => Analog, 1 => Digital

ADCSSL = 0x0F04; //0 => Skip, 1 => Scan

ADCHSbits.CH0NA = 0;

Page 17: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

17 от 34 05.3.2007 г. 14:43

Settings for ADC Operation: For 200kbps operation, the voltage references for the ADC voltage are connected to VREF+ and VREF-. Scan input is enabled, and the module will generate an interrupt when all selected channels have been scanned.

More Settings for ADC Operation: Turn on the module, select the data output format as unsigned integer, and allow auto setting of SAMP bit (auto sampling).

Storing ADC Data

16 registers (ADCBUF0 -ADCBUF15) are dedicated to store the ADC data between interrupts. However,the data in ADCBUFx does not necessarily correspond to the data taken for channel x. Since the lowest register will always be filled first, when some of the channels are not scanned (i.e. skipped), care must be taken. The following code checks the ADCSSL register for the current scanning channels and moves the data to the corresponding position in *adc_buf.

Adding and Removing Channels

Channels may be added or removed by changing _TRISBX, ADPCFG, ADCSSL andADCON2bits.SMPI.

ADCS<5:0> = 2(TAD/TCY)-1 = 2(334e-9/33.34e-9)-1 = 19

ADCON3bits.SAMC = 1; //1TAD for sampling time ADCON3bits.ADRC = 1; //Use internal ADC clock ADCON3bits.ADCS = 19; //Set TAD = 334ns

ADCON2bits.VCFG = 3; //External Vref+, Vref- ADCON2bits.CSCNA = 1; //Scan input ADCON2bits.SMPI = 4; //take 5 samples (one sample per channel) per interrupt

ADCON1bits.ADON = 1; //Turn on module ADCON1bits.FORM = 0; //[2 fractional]; [3 siged fractional] ADCON1bits.SSRC = 7; //auto covert, using internal clock source ADCON1bits.ASAM = 1; //auto setting of SAMP bit

void _ISR _ADCInterrupt(void){ _ADIF = 0; //Clear adc interrupt //========================================================== unsigned char channel = 0; unsigned char buffer = 0; for (; channel<ADC_MAX_CH; channel++){ if(adc_ch_updated(channel)){ //Check if channel has updated adc_buf[channel] = ADC16Ptr[buffer]; //Copy data to adc_buf buffer++; } } } unsigned char adc_ch_updated(unsigned char ch){ unsigned int mask; mask = 0x0001 << ch; if(ADCSSL & mask) return 1; return 0; }

Page 18: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

18 от 34 05.3.2007 г. 14:43

EEPROM

5011 has 1024 bytes of EEPROM, readable and writable under normal voltage (5V).To use, declare:

Seek

This function moves the pointer to the desired position before a reading/writing operation is performed.

Read

This function read count bytes from the eeprom.

void adc_add_ch(unsigned char ch){ //Enable i/o pin as input=========================================== switch(ch){ case 0: _TRISB0 = 1; break; case 1: _TRISB1 = 1; break; case 2: _TRISB2 = 1; break; case 3: _TRISB3 = 1; break; case 4: _TRISB4 = 1; break; case 5: _TRISB5 = 1; break; case 6: _TRISB6 = 1; break; case 7: _TRISB7 = 1; break; case 8: _TRISB8 = 1; break; case 9: _TRISB9 = 1; break; case 10: _TRISB10 = 1; break; case 11: _TRISB11 = 1; break; case 12: _TRISB12 = 1; break; case 13: _TRISB13 = 1; break; case 14: _TRISB14 = 1; break; default: _TRISB15 = 1; } unsigned int mask; mask = 0x0001 << ch; ADCSSL = ADCSSL | mask; ADPCFG = ~ADCSSL; ADCON2bits.SMPI++; //take one more sample per interrupt } void adc_rm_ch(unsigned char ch){ unsigned int mask; mask = 0x0001 << ch; ADPCFG = ADPCFG | mask; ADCSSL = ~ADPCFG; ADCON2bits.SMPI--; //take one less sample per interrupt }

unsigned char _EEDATA(2) eeData[1024]={ 0x00, 0x00, 0x00, 0x00, .... } unsigned int byte_pointer = 0;

int eeprom_lseek(int offset, unsigned char whence){ byte_pointer = offset; return byte_pointer; }

int eeprom_read(unsigned char* buf, int count){ int i=0; for(; i<count && byte_pointer < 1024; i++){ readEEByte( __builtin_tblpage(eeData), __builtin_tbloffset(eeData) + byte_pointer, &buf[i]); byte_pointer++; //Update global pointer } return i; //read i bytes successful }

Page 19: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

19 от 34 05.3.2007 г. 14:43

readEEByte() is implemented in assembly code as follows:

Write

This function write count bytes to eeprom.

eraseEEWord and writeEEWord are implemented in assembly.

.global _readEEByte _readEEByte: push TBLPAG ;w0 = base of eeData mov w0, TBLPAG ;w1 = offset for eeData in byte tblrdl.b [w1], [w2] ;w2 = pointer to user buffer pop TBLPAG return

int eeprom_write(unsigned char* buf, int count){ char isOddAddr = byte_pointer%2; //current address is odd char isOddByte = count%2; //number of bytes to write is odd //================================================================= unsigned int word_offset = byte_pointer>>1; //div by 2 and round down int max_write; max_write = (isOddAddr == 0 && isOddByte == 0) ? (count>>1) : (count>>1)+1; //================================================================= unsigned int word_data; //Store word to be written int byte_wr = 0; //number of bytes written, i.e buffer pointer int i = 0; //================================================================= for(; i<max_write && word_offset<512; i++, word_offset++){ if(i==0 && isOddAddr){ //First byte not used //============================================save first byte readEEByte( __builtin_tblpage(eeData), __builtin_tbloffset(eeData) + byte_pointer - 1, &word_data); //=========================================================== word_data = ((unsigned int)buf[0] << 8) + (0xFF & word_data); byte_wr++; //Update buffer pointer byte_pointer++; //Update global pointer } else if(i==max_write-1 && ((isOddAddr && sOddByte==0)||(isOddAddr==0 && isOddByte))){ //Last byte not used //=============================================save last byte readEEByte( __builtin_tblpage(eeData), __builtin_tbloffset(eeData) + byte_pointer + 1, &word_data); //============================================================ word_data = (word_data << 8) + buf[byte_wr]; byte_wr++; //Update buffer pointer byte_pointer++; //Update global pointer } else{ //Both bytes valid word_data = ((unsigned int)buf[byte_wr+1] << 8) + buf[byte_wr]; byte_wr+=2; //Update buffer pointer byte_pointer+=2; //Update global pointer } //================================================================== eraseEEWord( __builtin_tblpage(eeData), __builtin_tbloffset(eeData) + 2*word_offset); writeEEWord( __builtin_tblpage(eeData), __builtin_tbloffset(eeData) + 2*word_offset, &word_data); //================================================================== } return byte_wr; //No. of byte written }

Page 20: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

20 от 34 05.3.2007 г. 14:43

Simple PWM (Output Compare Module)

The PWM module consists of 8 channels using the output compare module of dsPic.These channels are locate at pin 46 (OC1), 49 (OC2), 50 (OC3), 51 (OC4), 52 (OC5), 53 (OC6), 54 (OC7), 55 (OC8). These pins are shared with port D.The range of PWM freqeuencies obtainable is 2Hz to 15MHz (See Figure 6.3). Suggested range of operation is 2Hz to 120kHz. The relationship between resolution r and PWM frequency fPWM is given by:

Table 6.3 Relationship of Resolution and PWM FrequencyResolution (bit) Prescale=1 Prescale=8 Prescale=64 Prescale=256

1 15,000,000 1,875,000 234,375 58,594

2 7,500,000 937,500 117,188 29,297

3 3,750,000 468,750 58,594 14,648

4 1,875,000 234,375 29,297 7,324

.global _eraseEEWord _eraseEEWord: push TBLPAG mov w0, NVMADRU ;w0 = base of eeData mov w1, NVMADR ;w1 = offset for eeData in word mov #0x4044, w0 mov w0, NVMCON ;Set to erase operation push SR ;Disable global interrupts mov #0x00E0, w0 ior SR mov #0x55, w0 ;Write the KEY sequence mov w0, NVMKEY mov #0xAA, w0 mov w0, NVMKEY bset NVMCON, #15 ;Start the erase cycle, bit 15 = WR nop nop L1: btsc NVMCON, #15 ;while(NVMCONbits.WR) bra L1 clr w0 pop SR ;Enable global interrupts pop TBLPAG return

.global _writeEEWord _writeEEWord: push TBLPAG ;w0 = base of eeData mov w0, TBLPAG ;w1 = offset for eeData in byte tblwtl [w2], [w1] ;w2 = pointer to user buffer mov #0x4004, w0 ;Set to write operation MOV w0, NVMCON push SR ;Disable global interrupts mov #0x00E0, w0 ior SR mov #0x55, w0 ;Write the KEY sequence mov w0, NVMKEY mov #0xAA, w0 mov w0, NVMKEY bset NVMCON, #15 ;Start the erase cycle, bit 15 = WR nop nop L2: btsc NVMCON, #15 ;while(NVMCONbits.WR) bra L2 clr w0 pop SR ;Enable global interrupts pop TBLPAG return

fPWM = fCY/(Prescale*10rlog(2))

Page 21: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

21 от 34 05.3.2007 г. 14:43

5 937,500 117,188 14,648 3,662

6 468,750 58,594 7,324 1,831

7 234,375 29,297 3,662 916

8 117,188 14,648 1,831 458

9 58,594 7,324 916 229

10 29,297 3,662 458 114

11 14,648 1,831 229 57

12 7,324 916 114 29

13 3,662 458 57 14

14 1,831 229 29 7

15 916 114 14 4

16 458 57 7 2

open()

A timer (either Timer 2 or 3) is needed to determine the pwm period. The following code uses timer 2 for all 8 channels.

ioctl()

User should select the channel and set the pwm period using the functions below before issuing the dutycycle:

void pwm_open(void){ OC1CON = 0; OC2CON = 0; //Disable all output compare modules OC3CON = 0; OC4CON = 0; OC5CON = 0; OC6CON = 0; OC7CON = 0; OC8CON = 0; //============================================================ TMR2 = 0; // Clear register PR2 = 0xFFFF; // Set to Maximum //============================================================ _T2IP = 7; // Set priority level to 7 (7 Highest) _T2IF = 0; // Clear interrupt flag _T2IE = 1; // Enable interrupts //============================================================ T2CONbits.TCS = 0; // Use internal clock source T2CONbits.TCKPS = 0; // Prescale Select 1:1 //============================================================ T2CONbits.TON = 1; // Start the timer } void _ISR _T2Interrupt(void){ _T2IF = 0; // Clear interrupt flag }

Page 22: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

22 от 34 05.3.2007 г. 14:43

write()

User can change the duty cycle using teh following functions

Propagration Delay

PWM channels sharing the same timer will have their PWM signals synchronised (i.e. the HIGH state of

char pwm_ioctl(unsigned char request, unsigned long* argp){ unsigned int value; unsigned char mask; switch(request){ case PWM_SET_PERIOD: return setPeriodNPrescale(argp[0]); case PWM_SELECT_CH: pwm_channel = argp[0]; mask = 0x01 << pwm_channel; pwm_status = pwm_status | mask; return 0; default: return -1; } } char setPeriodNPrescale(unsigned long value_ns){ unsigned long ans; unsigned long long numerator = (unsigned long long)value_ns*SYSTEM_FREQ_MHZ; unsigned char index= -1; unsigned long denominator; //------------------------------------------------- do{ denominator = (unsigned long)1000*pwm_prescale[++index]; ans = (unsigned long)(((long double)numerator/denominator) + 0.5) - 1; //rounding to nearest integer } while(ans > 0x0000FFFF && index < 3); //------------------------------------------------- if(ans > 0x0000FFFF) return -1; //------------------------------------------------- T2CONbits.TON = 0; // Turn off the timer T2CONbits.TCKPS = index; // Change prescale factor PR2 = (unsigned int) ans; // Set to Maximum T2CONbits.TON = 1; // Turn on the timer //------------------------------------------------- return 0; }

int pwm_write(unsigned long* buf){ if((pwm_status & (0x01 << pwm_channel)) == 0){ return -1; //Channel has not been enabled } switch(pwm_channel){ case 0: OC1RS = calcDCycle(buf[0]); OC1R = OC1RS; OC1CONbits.OCM = 6; //Simple PWM, Fault pin disabled break; case 1: OC2RS = calcDCycle(buf[0]); OC2R = OC2RS; OC2CONbits.OCM = 6; //Simple PWM, Fault pin disabled break; ... case 7: OC8RS = calcDCycle(buf[0]); OC8R = OC8RS; OC8CONbits.OCM = 6; //Simple PWM, Fault pin disabled break; default: return -1; } return 4;} unsigned int calcDCycle(unsigned long value_ns){ unsigned long long numerator = (unsigned long long)value_ns*SYSTEM_FREQ_MHZ; unsigned int index = T2CONbits.TCKPS; unsigned long denominator = (unsigned long)1000*pwm_prescale[index]; return (unsigned int)(((long double)numerator/denominator) + 0.5) - 1; //rounding to nearest integer }

Page 23: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

23 от 34 05.3.2007 г. 14:43

the duty cycle are all triggered together).To introduced delay to the PWM signals, the signal from selected channels may be made to pass through aseries of inverters (e.g. 74HC14D). This adds propagation delay to the signal.However, as propagration delay of logic gates depends on applied voltage, temperature and load capacitance, the accuracy is low and performance is poor. For accurate delay, delay lines may be used, but they are expensive.

Table 6.4 Propagation Delay of Philips 74HC14D(http://www.nxp.com/acrobat_download/datasheets/74HC_HCT14_3.pdf) [1], [2]

3.3V 5.0V

Number of Gates A B C A B C

2 21ns (10.5) 23ns (11.5) 22ns (11.0) 15ns (7.5) 14ns (7.0) 14ns (7.0)

4 45ns (11.3) 46ns (11.5) 46ns (11.5) 30ns (7.5) 30ns (7.5) 30ns (7.5)

6 69ns (11.5) 70ns (11.7) 72ns (12.0) 45ns (7.5) 46ns (7.7) 47ns (7.8)

[1] Data in specification for 4.5V: Typical 15ns, Maximum 25ns[2] Data in specification for 6.0V: Typical 12ns, Maximum 21ns

DSP Library

Library functions in <dsp.h> include the following categories:

Vector1.Window2.Matrix3.Filtering4.Transform5.Control6.

Data Types

Signed Fractional Value (1.15 data format)Inputs and outputs of the dsp functions adopt 1.15 data format, which consumes 16 bits to represent values between -1 to 1-2-15 inclusive.Bit<15> is a signed bit, positive = 0, negative = 1.Bit<14:0> are the exponent bits e.Positive value = 1 - 2-15*(32768 - e)Negative value = 0 - 2-15*(32768 - e)

40-bit Accumulator operations (9.31 data format)The dsp functions use the 40 bits accumalators during arithmatic calculations.Bit<39:31> are signed bits, positive = 0x000, negative = 0x1FF.Bit<30:0> are exponent bits.

IEEE Floating Point ValuesFractional values can be converted to Floating point values using: fo = Fract2Float(fr); for fr = [-1, 1-2-15]Floating point values can be converted to Fractional values using: fr = Float2Fract(fo); or fr = Q15(fo); for fo = [-1, 1-2-15]Float2Fract() is same as Q15(), except having saturation control. When +ve >= 1, answer = 215-1 = 32767 (0x7FFF). When -ve < -1, answer = -215 = -32767 (0x8000)

Page 24: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

24 от 34 05.3.2007 г. 14:43

Overflow and Saturation Traps

To be added.

Build-in Library

Some assembler operators can only be accessed by inline assembly code, for example,

Manuipulation of accumulators A and B (add, sub, mul, divide, shift, clear, square)1.Bit toggling2.Access to psv (program space visiblity) page and offset3.Access to table instruction page and offset4.

Built-in functions are written as C-like function calls to utilize these assembler operators.

Bootloader Development

Concepts

Programming with ICSP is useful when the target board is produced in batch. The producer can downloada 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.

Page 25: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

25 от 34 05.3.2007 г. 14:43

Developer Source

ingenia (http://www.ingenia-cat.com/index.php?lang=en) Assembly (http://www.ingenia-cat.com/download/iBL.s

Tiny(http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm)

Assembly(http://www.etc.ugal.ro/cchiculita/software/tinybld191.zip

Elektronika (http://www.via.si/software/dsPIC_bootloader/) Hex (http://www.via.si/software/dsPIC_bootloader/data/

dsPicBootloader

The bootloader developed by ingenia is open source and it has been modified (see below) to suit our development using dsPic30f5011.The bootloader (hereafter called dsPicBootloader) employs the following settings:

Use U2ART channel1.Use FRC, PLL162.For 5011, the bootloader is located between 0x00AE00 to 0x00AFFE (512bytes). Refer to C:\Program Files\Ingenia\ingeniadsPICbootloader\ibl_dspiclist.xml after installing the GUI interface.

3.

Changes made to assembly code (http://www.ingenia-cat.com/download/iBL.s) includes:

1. including p30f5011.gld and p30f5011.inc

2. changing the config code of UART #0x8420 -> #0x8020

3. changing the start address 0xAE00 - 0x0100 = 0AD00

.include "p30f5011.inc"

; Uart init mov #0x8020, W0 ; W0 = 0x8020 -> 1000 0000 0010 0000b mov W0, U2MODE ; Enable UART, AutoBaud and 8N1 clr U2STA

Page 26: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

26 от 34 05.3.2007 г. 14:43

4. using Internal FRC and PLL16

5. disabling MCLR (optional)

6. changing all the related registers of U1ART to U2ART, all U1XXX => U2XXX

7. changing all the related registers of IC1 to IC2, all IC1XXX => IC2XXX

dsPicProgrammer (Java-based Multi-Platformed)

Ingenia developed a programmer (PC-side) that works only in Windows environment. The project for Linux environment is currently suspended.A simple programmer (hereafter called dsPicProgrammer) written in Java based on the library developed by RXTX (http://www.rxtx.org/) has been developed here. The programmer supports both Linux and Windows environments, and may be used as a substitution for the official programmer developed byingenia.The programmer has the following specification and limitations:

Use baud rate of 57600bps (Not selectable).1.Only program dsPic30f5011 devices (Developers may change the source code for your devices).2.Protection against overwriting bootloader codes on devices.3.Dectection if application program does not have its reset() at address 0x100.4.

Special Consideration

The bootloader assumes that the user program starts at address 0x100. This is usually the case, but there are always exceptions.To ensure that the user program always starts at address 0x100, you can create a customized linker script and customized reset() function as follows:

Copy and modify the file named "crt0.s" from the directory "C:\Program Files\Microchip\MPLAB C30\src\pic30" to the project directory and include it.

.equ CRC, W4 .equ ACK, 0x55 .equ NACK, 0xFF .equ USER_ADDRESS, 0x0100 .equ START_ADDRESS, 0xAD00 ; Relative to 0x0100

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

config __FBORPOR, PBOR_ON & BORV_27 & PWRT_16 & MCLR_DIS ;Set Brown-out Reset voltage and ;and set Power-up Timer to 16msecs

U2MODE, U2STA, U2BRG, U2RXREG, U2TXREG

IC2CON, #IC2IF, #IC2IE

.section .reset, code //previously .section .libc, code

Page 27: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

27 от 34 05.3.2007 г. 14:43

Copy and modify the linkerscript for the device (e.g. p30f5011.gld) to the project directory and include it.

Downloads

Table 7.2 dsPicBootloader and dsPicProgrammer for dsPIC30f5011Program Site 1 Site 2

dsPicBootloader click(http://chungyan5.no-ip.org/websvn/listing.php)

click(http://www.opencircuits.com/images/e/ed/DsPicBootloader.zip

dsPicProgrammer click(http://chungyan5.no-ip.org/websvn/listing.php)

click(http://www.opencircuits.com/images/1/13/DsPicProgrammer.zip

Communication Protocol

Communication Protocol is reviewed in ingenia bootloader user's guide(http://www.ingenia-cat.com/reference/pdf/iBL.UG.V1.2.pdf) section 2.1.3. The following summarises thekey 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-bitStage 1: User's configuation

Select a baudrateSelect a COM port channel

Stage 2: Autobaud rate detection and version controlContinuously sending a character "U" [0x55] via COM portContinuously waiting for an acknowledgment character "U", [ACK] = [0x55]Send command character [0x03]Receive 3 characters 1) Major Version 2) Minor Version 3) Acknowledgment [0x55]Prints the version number [Major.Minor] (e.g. 1.1) on screen.

Stage 3: Loading and writing the program

.text __CODE_BASE : { *(.reset); //<-insert this line here *(.handle); *(.libc) *(.libm) *(.libdsp); /* keep together in this order */ *(.lib*); *(.text); } >program

Page 28: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

28 от 34 05.3.2007 г. 14:43

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 modulo256)Receive [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,1.Send the data corresponding to the whole row.2.

USB-RS232 Bridge

As USB ports are becoming more and more common, COM ports and Parallel ports may be redundant in the next few years. This section explore the possibilities of programming the target board through a USBport.There are two options:

Use an external USB/RS232 adaptor, the driver will emulate a virtual COM port, such as Prolific(http://www.prolific.com.tw/eng/downloads.asp?ID=31) and FDTI(http://www.ftdichip.com/Drivers/VCP.htm) . Ingenia has tested its bootloader with some USB-232 manufacturers (silabs, FTDI, etc..). However, the programming failed with our Prolific adapter. Application program may use JavaComm API (http://java.sun.com/products/javacomm/) (javax.comm) and/or RXTX (http://www.rxtx.org/) to drive the COM port.

1.

Modified the bootloader program on PC to support USB communication. e.g. using jUSB(http://jusb.sourceforge.net/) and JSR-80 (http://javax-usb.org/) (javax.usb). External circuits such as PIC18F4550 and MAX232 are required.

2.

Currently, when RXTX is incorporated with JavaComm API, operating systems supported include Linux, Windows, Mac OS, Solaris and other operating systems. On the other hand, jUSB and JSR-80 only worksfor linux.

FDTI Chipset

FT232RL communicates with PC via USB to provide 1 UART channel.Datasheet can be downloaded here (http://www.ftdichip.com/Documents/DataSheets/DS_FT232R.pdf) .

Refer to Fig. 11 (Page 19) for Bus Powered Configuration.Refer to Fig. 16 (Page 24) for for UART TTL-level Receive [RXD -> 1], Transmit [TXD -> 4], Transmit Enable [CBUS2/TXDEN -> 3]. Omit Receive Enable [CBUS3/PWREN#] and use[CBUS2/TXDEN -> 2]Refer to Fig. 15 (Page 23) for LED Configuration: [CBUS0/TXLED#] and [CBUS1/RXLED#]

|--User's App.--|-------Device Manager------|-------USB-RS232 Interface------|---dsPIC---| Option 1: +-------------+ +----------+ +----------+ +---+ +------------+ +-----+ +--------+ | Application |--| JavaComm |--| Virtual |==|USB|--| FDTI |--|RS232|==| Target | | Program | | RXTX | | COM Port | +---+ | Circuitary | +-----+ | Board | +-------------+ +----------+ +----------+ +------------+ +--------+ Option 2: +-------------+ +--------+ +---+ +------------+ +-----+ +--------+ | Application |----------| JSR-80 |==========|USB|--| PIC18F4550 |--|RS232|==| Target | | Program | | jUSB | +---+ | MAX232 | +-----+ | Board | +-------------+ +--------+ +------------+ +--------+

Page 29: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

29 от 34 05.3.2007 г. 14:43

Virtual COM Port Drivers can be downloaded here (http://www.ftdichip.com/Drivers/VCP.htm) .

Programming the Device

Requirements

Hardware

PC with COM port (Windows XP Installed for MPLAB)1.ICD2 Programmer2.Target Board3.5V Power Supply4.

Software

MPLAB IDE v7.50 or higher (http://ww1.microchip.com/downloads/en/DeviceDoc/MP750.zip) 1.dsPicProgrammer (http://chungyan5.no-ip.org/websvn/listing.php) (dsPicProgrammer.jar)2.RXTX driver (http://users.frii.com/jarvi/rxtx/download.html) 3.

Files

dsPicBootloader (http://chungyan5.no-ip.org/websvn/listing.php) (ingenia.hex). Original assembly code by ingenia can be downloaded from here (http://www.ingenia-cat.com/download/iBL.s) .

1.

Application hex file (e.g. app.hex)2.

Loading Bootloader (Once only)

Page 30: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

30 от 34 05.3.2007 г. 14:43

Table 9.1 Loading BootloaderStep Remarks

Install MPLAB IDE(http://ww1.microchip.com/downloads/en/DeviceDoc/MP750.zip) Do NOT connect ICD 2 (via USB) to PC

Execute MPLAB vX.XX Install.exe

Install USB Driver Follow the instruction in (C:\Program Files\Microchip\MPLAB IDE\ICD2\Drivers\Ddicd2.htm)

Select Target Chip Run MPLAB IDE on PCSelect: Configure>Select Devices...Choose dsPIC30F5011

Target <-> ICD 2Use six pin cable. Beware of the pin assignments. Only pin 1 - 5 should be used.Place Jumper on target board (if any). The Jumper connects target Vcc to ICD 2.Do NOT power-up the target.

ICD 2 <-> PC Plug-in ICD 2 to PC via USB cablePower-up the target.Select: Programmer>Select Programmer>MPLAB ICD 2If 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 finishedIf you have not connected and powered up the target, you might see Warnings on invalid device IDs, and/or running self tests.See results of self test if necessary: Programmer>Settings, Status Tab. Refer to ICD2 User's Guide(http://ww1.microchip.com/downloads/en/DeviceDoc/51331B.pdfChapter 7.

Load Bootloader Select: File>Import...Select ingenia.hex

Start Programming Select: Programmer>Program

Finishing Power-down the TagetSelect: Programmer>Select Programmer>NoneUnplug USB cable

Loading Application

Page 31: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

31 от 34 05.3.2007 г. 14:43

Table 9.2 Loading Application FileStep Remarks

Install RXTX For Windows User:

copy RXTXcomm.jar to \jre\lib\ext (under java)copy rxtxSerial.dll to \jre\bin

For Linux User:copy RXTXcomm.jar to /jre/lib/ext (under java)copy librxtxSerial.so to /jre/lib/[machine type] (i386 for instance)

Connect target board For Windows User:

connect to COM1 (or other useable port)For Linux User:

connect to ttyS0 (or other useable port)

Open a console window In Windows, Start>Run, and type cmd.

Start Programming Change to the directory containing dsPicProgrammer.jarExecute dsPicProgrammer.jar

For Windows User: java -jar dsPicProgrammer.jar COMi Y:\foo2\app.hexFor Linux User: java -jar dsPicProgrammer.jar /dev/ttySi Y:/foo2/app.hex

Power-up target board

Finishing Power-down target boardDisconnect from COM port

Remote Access

At the moment, local devices (e.g. EEPROM, ADC, DAC, etc.) can only be accessed locally through POSIX functions such as open(), read(), write(), ioctl().However, a client may need to access these devices on a remote server. This section reviews the background and gives some ideas on its possible implementation.

Requirements

A remote file access protocol, to transfer "files" (i.e. device's data) such as:

File Transfer Protocol (http://en.wikipedia.org/wiki/FTP) (FTP): Required files are copied from sever to client for manipulation

1.

Remote Shell (http://en.wikipedia.org/wiki/Remote_Shell) (RSH): Required files are copied from sever to client for manipulation

2.

Network File System (http://en.wikipedia.org/wiki/Network_File_System_%28Sun%29) (NFS): Required files are manipulated on sever

3.

Page 32: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

32 от 34 05.3.2007 г. 14:43

An API to access files using a selected protocol, such as:

lam_rfposix (http://www.die.net/doc/linux/man/man2/lam_rfposix.2.html) : A POSIX-like remote file service for Local Area Multicomputer

1.

API employed by VxWorks: VxWorks (http://en.wikipedia.org/wiki/VxWorks) is a Unix-like real-time operating system, commonly used for embedded systems.

2.

API Reference for VxWorks

Reference:VxWorks Official Website (http://www.windriver.com/vxworks/) OS Libraries API Reference (http://www-cdfonline.fnal.gov/daq/commercial/)

Related LibraiesnetDrv (netDrv.h): an API using FTP or RSHnfsDrv (nfsDrv.h): an API using NFS

Conversion to dsPIC33F Devices (Not Tested)

This section discusses the conversion required from dsPIC30F5011 to dsPIC33FJ128GP306.Refer to official document dsPIC30F to dsPIC33F Conversion Guidelines(http://ww1.microchip.com/downloads/en/DeviceDoc/70172A.pdf) (DS70172A).Note that this section does not intend to introduce the new functionalities of dsPIC33F devices. It only serves the purpose to summarise the major (if not minimum) changes required to port the setup of dsPIC30 to dsPIC33 devices.

Hardware

dsPIC33 operates at voltage of 3.3V. A voltage regulator, such as LM3940(http://www.national.com/ds.cgi/LM/LM3940.pdf) can be used to convert 5V supply to 3.3V.A 1uF capacitor has to be placed at pin 56 (previously VSS, now VDDCORE).

Software

Configuration Bits

dsPIC33 can operate at 40MIPs at maximum. To configure the device using internal FRC, replace the configuration bits setting as follows:

Configure on-chip PLL at runtime as follows (at start of main function):

_FOSCSEL(FNOSC_FRCPLL); // FRC Oscillator with PLL _FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_NONE); // Clock Switching and Fail Safe Clock Monitor is disabled // OSC2 Pin Function: OSC2 is Clock Output // Primary Oscillator Mode: Disabled _FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software

Page 33: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

33 от 34 05.3.2007 г. 14:43

UART

No change is required.

I2C

dsPIC33 supports upto 2 I2C devices. As a result, replace all I2C related registers with xxI2Cyy to xxI2C1yy. For examples:

ADC

There are upto 2 configurations of the ADC module. Replace all ADC-related registers ADxxx to AD1xxx. For examples:

Set ADC to use 12-bit modes:

dsPIC33 have upto 32 ADC channels. The configurations for each channel is therefore splited into 2 registers (High controls channels 16-31; Low controls channels 0-15).

_PLLDIV = 38; // M=40: PLL Feedback Divisor bits _PLLPOST1 = 0; _PLLPOST0 = 0; // N1=2: PLL VCO Output Divider Select bits _PLLPRE4 = 0; _PLLPRE3 = 0; // N2=2: PLL Phase Detector Input Divider bits _PLLPRE2 = 0; _PLLPRE1 = 0; _PLLPRE0 = 0; OSCTUN = 0; // Tune FRC oscillator, if FRC is used; // 0: Center frequency (7.37 MHz nominal) // 22: +8.25% (7.98 MHz) RCONbits.SWDTEN = 0; // Disable Watch Dog Timer while(OSCCONbits.LOCK != 1); // Wait for PLL to lock

_SI2C1IF = 0; //Clear Slave interrupt _MI2C1IF = 0; //Clear Master interrupt _SI2C1IE = 0; //Disable Slave interrupt _MI2C1IE = 0; //Disable Master interrupt I2C1BRG = I2C_BRG; // Configure Baud rate I2C1CONbits.I2CEN = 1; ... etc.

volatile unsigned int* ADC16Ptr = &ADC1BUF0; AD1CHS0bits.CH0NA = 0; AD1CON3bits.SAMC = 1; //1TAD for sampling time AD1CON2bits.VCFG = 3; //External Vref+, Vref- AD1CON1bits.ADON = 1; //Turn on module ... etc.

AD1CON1bits.AD12B = 1; //12-bit, 1-channel ADC operation

//=========================================================================== // Configure analog i/o _TRISB0 = 1; _TRISB1 = 1; AD1PCFGL = 0xFFFC; //AN0-AN15: Enable AN0 (Vref+) and AN1 (Vref-) AD1PCFGH = 0xFFFF; //AN16-AN31: Disabled //=========================================================================== // Configure scan input channels AD1CSSL = 0x0003; //AN0-AN15: 0 => Skip, 1 => Scan AD1CSSH = 0x0000; //Skipping AN16-AN31

Page 34: DsPIC30F 5011 Development Board - Open Circuits

DsPIC30F 5011 Development Board - Open Circuits http://www.opencircuits.com/DsPIC30F_5011_Development_Board

34 от 34 05.3.2007 г. 14:43

EEPROM

There is no EEPROM in dsPIC33 devices. Please consider to use an external EEPROM using I2C communication.

Simple PWM

No change is required.

Memory Map for dsPIC33FJ128GP306

Table 11.1 Memory LocationType Start Address End Address Size

Flash 0x000000 0x0157FF 86K[1]

+--Flash: Reset Vector 0x000000 0x000003 4

+--Flash: Interrupt Vector Table 0x000004 0x0000FF 252

+--Flash: Alternate Vector Table 0x000104 0x0001FF 252

+--Flash: User Program 0x000200 0x0157FF 85.5K

Programming Executive 0x800000 0x800FFF 4K[1]

Config Registers 0xF80000 0xF80017 24

Device ID (0xCF) 0xFF0000 0xFF0003 4

[1] Each address is 16-bit wide. Every two addresses correspond to a 24-bit instruction. Each even address contains 2 valid bytes; each odd address contains 1 valid byte plus 1 phathom byte.

dsPicBootloader

dsPicProgrammer

To Do List

Construct examples codes for using DSP library1.Construct examples codes for using Build-in library2.GUI Interface for Benchtop boards3.

Retrieved from "http://www.opencircuits.com/DsPIC30F_5011_Development_Board"

This page was last modified 03:55, 5 March 2007.Content is available under Attribution-ShareAlike 2.5.