Editing Programming Tips
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 85: | Line 85: | ||
− | === | + | ===<asm/types.h>=== |
*The following maps the basic data types: | *The following maps the basic data types: | ||
typedef unsigned char __u8; | typedef unsigned char __u8; | ||
Line 110: | Line 110: | ||
− | === | + | ===Custom Linker Script to Maximize Space for Constant Data=== |
*Constant data declared using keyword '''const''' will be stored in the .const section in the flash memory. | *Constant data declared using keyword '''const''' will be stored in the .const section in the flash memory. | ||
*Normally, during compilation, the linker will assign these data after the program code (.text section). | *Normally, during compilation, the linker will assign these data after the program code (.text section). | ||
Line 160: | Line 160: | ||
− | === | + | ===System Clock=== |
*Each timer is 16-bit (i.e. counting from 0 to 65535). | *Each timer is 16-bit (i.e. counting from 0 to 65535). | ||
*Prescale is the ratio between timer counts and system clock counts. Prescales of 1:1, 1:8, 1:64 and 1:256 are available. | *Prescale is the ratio between timer counts and system clock counts. Prescales of 1:1, 1:8, 1:64 and 1:256 are available. | ||
Line 192: | Line 192: | ||
− | === | + | ===<asm/system.h>=== |
*Registers are involved in Interrupts includes: | *Registers are involved in Interrupts includes: | ||
#Interrupt Flag Status (IFS0-IFS2) registers | #Interrupt Flag Status (IFS0-IFS2) registers | ||
Line 209: | Line 209: | ||
==POSIX System Call and Drivers== | ==POSIX System Call and Drivers== | ||
− | * | + | *POSIX System calls (open(), close(), read(), write(), lseek()) are used to access hardware devices related to data stream. |
*The file descriptor return by open() for these devices are statically assigned at compile time. | *The file descriptor return by open() for these devices are statically assigned at compile time. | ||
− | === | + | ===UART=== |
*Serves as the default communication channel for STDIN, STDOUT and STDERR. | *Serves as the default communication channel for STDIN, STDOUT and STDERR. | ||
*Implementation of this driver allows transparent operation of printf() in standard C library. | *Implementation of this driver allows transparent operation of printf() in standard C library. | ||
− | === | + | ===I<sup>2</sup>C=== |
*A number of I2C devices can be added using this driver (e.g. I2C DAC, I2C EEPROM, etc) | *A number of I2C devices can be added using this driver (e.g. I2C DAC, I2C EEPROM, etc) | ||
*Two lines are devoted for the serial communication. SCL for clock, SDA for data. | *Two lines are devoted for the serial communication. SCL for clock, SDA for data. | ||
Line 232: | Line 232: | ||
− | === | + | ===ADC=== |
*12-bit ADC: (Max 18 Channels) | *12-bit ADC: (Max 18 Channels) | ||
*ADC uses DMA to buffer the adc data. | *ADC uses DMA to buffer the adc data. | ||
Line 238: | Line 238: | ||
− | === | + | ===Simple PWM (Output Compare Module)=== |
*The PWM module consists of 8 channels using the output compare module of dsPic. | *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. | *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. | ||
Line 283: | Line 283: | ||
− | === | + | ===Flash-emulated EEPROM=== |
− | |||
− | |||
− | |||
− | |||
− | |||
*Using built-in functions __builtin_tblpage(), __builtin_tbloffset() to set special-purpose registers to access flash memory | *Using built-in functions __builtin_tblpage(), __builtin_tbloffset() to set special-purpose registers to access flash memory | ||
− | *Using | + | *Using assembly code to read and write flash memory. |
− | |||
− | |||
− | |||
− | |||
==DSP Library== | ==DSP Library== | ||
Line 306: | Line 297: | ||
#Transform | #Transform | ||
#Control | #Control | ||
− | |||
===Data Types=== | ===Data Types=== | ||
Line 323: | Line 313: | ||
**Floating point values can be converted to Fractional values using: '''fr = Float2Fract(fo);''' or '''fr = Q15(fo);''' for fo = [-1, 1-2<sup>-15</sup>] | **Floating point values can be converted to Fractional values using: '''fr = Float2Fract(fo);''' or '''fr = Q15(fo);''' for fo = [-1, 1-2<sup>-15</sup>] | ||
**Float2Fract() is same as Q15(), except having saturation control. When +ve >= 1, answer = 2<sup>15</sup>-1 = 32767 (0x7FFF). When -ve < -1, answer = -2<sup>15</sup> = -32767 (0x8000) | **Float2Fract() is same as Q15(), except having saturation control. When +ve >= 1, answer = 2<sup>15</sup>-1 = 32767 (0x7FFF). When -ve < -1, answer = -2<sup>15</sup> = -32767 (0x8000) | ||
− | |||
− | |||
− | |||
− |