mbed/linraries 
SDFileSystemDMA inherited from Official SDFileSystem.
https://developer.mbed.org/users/mimi3/code/SDFileSystemDMA/

FastPWM
https://developer.mbed.org/users/Sissors/code/FastPWM/



[ 1 comment ]   |  [ 0 trackbacks ]   |  permalink
MCU sine with offset in 10bit 

unsigned int const sinetable[512] = {
1023,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1021,
1021,1021,1021,1021,1021,1020,1020,1020,1020,1019,1019,1019,1019,1018,1018,1018,
1018,1017,1017,1017,1016,1016,1016,1015,1015,1014,1014,1014,1013,1013,1012,1012,
1011,1011,1010,1010,1009,1009,1008,1008,1007,1007,1006,1006,1005,1005,1004,1003,
1003,1002,1002,1001,1000,1000,999,998,998,997,996,996,995,994,993,993,
992,991,990,989,989,988,987,986,985,985,984,983,982,981,980,979,
978,977,977,976,975,974,973,972,971,970,969,968,967,966,965,964,
963,962,961,959,958,957,956,955,954,953,952,950,949,948,947,946,
945,943,942,941,940,938,937,936,935,933,932,931,929,928,927,926,
924,923,921,920,919,917,916,915,913,912,910,909,907,906,905,903,
902,900,899,897,896,894,893,891,889,888,886,885,883,882,880,878,
877,875,874,872,870,869,867,865,864,862,860,859,857,855,853,852,
850,848,846,845,843,841,839,838,836,834,832,830,828,827,825,823,
821,819,817,815,813,812,810,808,806,804,802,800,798,796,794,792,
790,788,786,784,782,780,778,776,774,772,770,768,766,764,761,759,
757,755,753,751,749,747,744,742,740,738,736,734,731,729,727,725,
723,720,718,716,714,711,709,707,705,702,700,698,695,693,691,689,
686,684,682,679,677,674,672,670,667,665,663,660,658,655,653,651,
648,646,643,641,638,636,633,631,628,626,624,621,619,616,614,611,
608,606,603,601,598,596,593,591,588,586,583,580,578,575,573,570,
567,565,562,560,557,554,552,549,546,544,541,538,536,533,530,528,
525,522,520,517,514,511,509,506,503,500,498,495,492,490,487,484,
481,478,476,473,470,467,465,462,459,456,453,450,448,445,442,439,
436,433,431,428,425,422,419,416,413,411,408,405,402,399,396,393,
390,387,385,382,379,376,373,370,367,364,361,358,355,352,349,346,
343,341,338,335,332,329,326,323,320,317,314,311,308,305,302,299,
296,293,290,287,284,281,278,275,272,269,266,263,259,256,253,250,
247,244,241,238,235,232,229,226,223,220,217,214,211,208,204,201,
198,195,192,189,186,183,180,177,174,170,167,164,161,158,155,152,
149,146,143,139,136,133,130,127,124,121,118,114,111,108,105,102,
99,96,93,89,86,83,80,77,74,71,68,64,61,58,55,52,
49,46,42,39,36,33,30,27,24,20,17,14,11,8,5,2
};



#include <stdio.h>
#include "sinetable.h"
#include <stdint.h>

int16_t get_sine(uint16_t position) {
// @ inputs: position in wave 0 - 2047
if(position < 1024) {
if(position < 512) {
// Q1
//return(position);
return(sinetable[position]);
} else {
// Q2
position = 511 + (512 - position);
//return(position);
return( -1 * sinetable[position]);
}
} else {
if(position < 1024 + 512) {
// Q3
position = -1 * (1024 - position);
//return(position);
return( -1 * sinetable[position]);
} else {
// Q4
position = 1023 + 1024 - position;
//return(position);
return(sinetable[position]);
}
}
}

uint16_t sine_t_pos = 0; // sinetable position
uint16_t sine_s_ctr = 0; // sine speed counter

uint16_t get_scaled_sine(uint16_t offset, uint16_t speed, uint16_t modulation) {
// @ input offset: 0 - 1023 /10bit/
// @ input speed: 0 - 1023 /10bit/
// @ input modulation: 0 - 1023 /10bit/
// @ function output: 0 - 1023 /10bit/
int32_t sine;

if(sine_s_ctr < speed) {
sine_s_ctr += 1;
} else {
sine_s_ctr = 0;
if(sine_t_pos < 2047) {
sine_t_pos++;
} else {
sine_t_pos = 0;
}
}
sine = get_sine(sine_t_pos);
sine = sine * (1 + modulation);
sine = sine >> 11;
sine = sine + offset;

if(sine < 1024) {
if(sine < 0) {
return((uint16_t) 0);
} else {
return((uint16_t) sine);
}
} else {
return((uint16_t) 1023);
}
}


main(void) {

uint32_t c, d;
uint16_t sine;

for(c=0; c<65535<<4; c++) {
sine = get_scaled_sine(512, 1, 512);
printf("sine: %d\n\r", sine);
}
}


[ 7 comments ]   |  [ 0 trackbacks ]   |  permalink
Rotary Encoder Interfacing With MSP430 LaunchPad  
http://www.circuitvalley.com/2013/09/ro ... chpad.html


[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |  related link
MSP430 i2c code 4 DCO 

/*
* This file is automatically generated and does not require a license
*
* ==== WARNING: CHANGES TO THIS GENERATED FILE WILL BE OVERWRITTEN ====
*
* To make changes to the generated code, use the space between existing
* "USER CODE START (section: <name>)"
* and
* "USER CODE END (section: <name>)"
* comments, where <name> is a single word identifying the section.
* Only these sections will be preserved.
*
* Do not move these sections within this file or change the START and
* END comments in any way.
* ==== ALL OTHER CHANGES WILL BE OVERWRITTEN WHEN IT IS REGENERATED ====
*
* This file was generated from
* C:/ti/grace_3_00_01_48_eng/packages/ti/mcu/msp430/csl/interrupt_vectors/InterruptVectors_init.xdt
*/
#include <msp430.h>

/* USER CODE START (section: InterruptVectors_init_c_prologue) */
#include <stdint.h>

extern unsigned char calibrate_flag;

struct Voice {

uint8_t osc_divider;
uint8_t osc_counter_lsb;
uint8_t osc_counter_msb;
uint8_t osc_dac_lsb;
uint8_t osc_dac_msb;

} voice;

unsigned int i2c_cntr = 0;
unsigned int virtual_TA0CCR0;
unsigned int virtual_TA0CTL;
unsigned char play_midi_note_toggle_bit;
/* USER CODE END (section: InterruptVectors_init_c_prologue) */

/*
* ======== InterruptVectors_graceInit ========
*/
void InterruptVectors_graceInit(void)
{
}


/* Interrupt Function Prototypes */



/*
* ======== USCI A0/B0 TX Interrupt Handler Generation ========
*
* Here are several important notes on using USCI_A0/B0 TX interrupt Handler:
* 1. User could use the following code as a template to service the interrupt
* handler. Just simply copy and paste it into your user definable code
* section.
* For UART and SPI configuration:

if (IFG2 & UCA0TXIFG) {

}
else if (IFG2 & UCB0TXIFG) {

}

* For I2C configuration:
if (IFG2 & UCA0/B0TXIFG) {

}
else if (IFG2 & UCA0/B0RXIFG) {

}


* 2. User could also exit from low power mode and continue with main
* program execution by using the following instruction before exiting
* this interrupt handler.
*
* __bic_SR_register_on_exit(LPMx_bits);
*/
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR_HOOK(void)
{
/* USER CODE START (section: USCI0TX_ISR_HOOK) */
if (IFG2 & UCB0TXIFG) { // callback to transmit bytes

UCB0TXBUF = 0xff;

} else if (IFG2 & UCB0RXIFG) { // callback for bytes received

switch(i2c_cntr) {

case 0:
voice.osc_divider = UCB0RXBUF;
i2c_cntr++;
break;

case 1:
voice.osc_counter_msb = UCB0RXBUF;
i2c_cntr++;
break;

case 2:
voice.osc_counter_lsb = UCB0RXBUF;
i2c_cntr++;
break;

case 3:
voice.osc_dac_msb = UCB0RXBUF;
i2c_cntr++;
break;

case 4:
voice.osc_dac_lsb = UCB0RXBUF;
i2c_cntr++;

virtual_TA0CCR0 = voice.osc_counter_msb; // (2) CCR0 - set CCR0 (compare register value)
virtual_TA0CCR0 = virtual_TA0CCR0 << 8;
virtual_TA0CCR0 |= voice.osc_counter_lsb;

if(voice.osc_divider == 1) {
// (4) TA0CTL - clock src & divider & mode
// start TIMER0_A0
// TASSEL_2 == Timer A clock source select: 2 - SMCLK
// ID_0 == Timer A input divider: none
virtual_TA0CTL = TASSEL_2 | ID_0 | MC_1; // MC_1 == Timer A mode control: 1 - Up to CCR0

} else if(voice.osc_divider == 2) {
// (4) TA0CTL - clock src & divider & mode
// TASSEL_2 -- SMCLK
// ID_1 -- Timer A input divider: 1 - /2 *
virtual_TA0CTL = TASSEL_2 | ID_1 | MC_1; // MC_1 -- Timer A mode control: 1 - Up to CCR0

} else if(voice.osc_divider == 4) {
// (4) TA0CTL - clock src & divider & mode
// TASSEL_2 -- SMCLK
// ID_2 -- Timer A input divider: 2 - /4 *
virtual_TA0CTL = TASSEL_2 | ID_2 | MC_1; // MC_2 -- Timer A mode control: 1 - Up to CCR0

} else if(voice.osc_divider == 8) {
// (4) TA0CTL - clock src & divider & mode
// TASSEL_2 -- SMCLK
// ID_2 -- Timer A input divider: 3 - /8
virtual_TA0CTL = TASSEL_2 | ID_3 | MC_1; // MC_2 -- Timer A mode control: 1 - Up to CCR0

} else if(voice.osc_divider == 16) {
// (4) TA0CTL - clock src & divider & mode
// TASSEL_2 -- SMCLK
// ID_2 -- Timer A input divider: 3 - /8
virtual_TA0CTL = TASSEL_2 | ID_3 | MC_3; // MC_3 -- Timer A mode control: 3 - Up/Down

} else if(voice.osc_divider == 0xff) { // calibration request (0xff)

calibrate_flag = 1; // set calibration flag
P1OUT |= BIT2; // ON LED; BIT0(P1) is MCU pin 2

}

}

if(!calibrate_flag) {

//
// TOGGLE play_midi_note_toggle_bit & SET
//

play_midi_note_toggle_bit ^= BIT7; // toggle play_midi_note_toggle_bit

if(play_midi_note_toggle_bit != 0) {

P1OUT |= BIT3; // BIT3(P1) is MCU pin 5

} else {

P1OUT &= ~(BIT3); // BIT3(P1) is MCU pin 5

};

//
// set voltages on R2R
//
if(voice.osc_dac_msb != 0) { // prevent ower-current when MSB state changes
// ie. 10 11111000 <-> 11 10000000
P3OUT = 0;

}

voice.osc_dac_msb |= 0xfc;
P2OUT &= voice.osc_dac_msb;

voice.osc_dac_msb &= 0x03;
P2OUT |= voice.osc_dac_msb;

P3OUT = voice.osc_dac_lsb;

}

}

/* USER CODE END (section: USCI0TX_ISR_HOOK) */
}

/*
* ======== USCI A0/B0 RX Interrupt Handler Generation ========
*
* Here are several important notes on using USCI_A0/B0 RX interrupt Handler:
* 1. User could use the following code as a template to service the interrupt
* handler. Just simply copy and paste it into your user definable code
* section.
* For UART and SPI configuration:

if (IFG2 & UCA0RXIFG) {

}
else if (IFG2 & UCB0RXIFG) {

}

* For I2C configuration:
if (UCB0STAT & UCSTTIFG) {

}
else if (UCB0STAT & UCSTPIFG) {

}
else if (UCB0STAT & UCNACKIFG) {

}
else if (UCB0STAT & UCALIFG) {

}

* 2. User could also exit from low power mode and continue with main
* program execution by using the following instruction before exiting
* this interrupt handler.
*
* __bic_SR_register_on_exit(LPMx_bits);
*/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR_HOOK(void)
{
/* USER CODE START (section: USCI0RX_ISR_HOOK) */
if (UCB0STAT & UCSTTIFG) { // start condition interrupt (1 is pending)

i2c_cntr = 0; // transmission begins
UCB0STAT &= ~UCSTTIFG; // clear start condition int flag

} else if (UCB0STAT & UCSTPIFG) { // stop condition interrupt (1 is pending)

UCB0STAT &= ~UCSTPIFG; // clear stop condition int flag

} else if (UCB0STAT & UCNACKIFG) { // slave not acknowledge received data (if master)

UCB0STAT &= ~UCNACKIFG;

} else if (UCB0STAT & UCALIFG) { // two or more masters start trans. simultaneously

// master code

}
/* USER CODE END (section: USCI0RX_ISR_HOOK) */
}

/*
* ======== Timer0_A3 Interrupt Service Routine ========
*/
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR_HOOK(void)
{
/* USER CODE START (section: TIMER0_A0_ISR_HOOK) */

TA0CTL = virtual_TA0CTL;
TA0CCR0 = virtual_TA0CCR0;

/* USER CODE END (section: TIMER0_A0_ISR_HOOK) */
}




[ 7 comments ]   |  [ 0 trackbacks ]   |  permalink
Writing and then Reading from Flash Memory on msp430g2553 
Writing and then Reading from Flash Memory on msp430g2553

http://e2e.ti.com/support/microcontroll ... 91331.aspx

[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |  related link
msp430-frequencyCounter 
msp430-frequencyCounter

[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |  related link
Faster switch(case) with intrinsic _even_in_range() 

switch(__even_in_range(TD0IV,30))
{
case 0:
...



default:
_never_executed();



[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |  related link
Mecrimus-B 
Mecrimus-B is a bit-bang implementation of low-speed USB 1.1 for MSP430 microcontrollers.

This is experimental code, and it is under active development. Currently, it runs on a MSP430G2452 with a digital external clock source of 15 MHz or 18 MHz. With Mecrimus-B 0.4 support for MSP430F2012 with 32768 Hz crystal clocking is added and it implements an USB HID mouse.

[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |  related link
SPI on MSP430 
a good writting on MSP430 SPI (bitbang) and USI usage: http://dbindner.freeshell.org/msp430/lcd_spi.html

[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |  related link
MSP430G2553 clocks 
TACLK - from an external pin, just for TA(x)CLK
ACLK - from an external crystal
SMCLK - sub-main clock (SMCLK) is derived from any of the four oscillators, and it drives peripherals
INCLK - internal DCO

[ 205 comments ] ( 78 views )   |  [ 0 trackbacks ]   |  permalink

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>