Jump to content
43oh

[ ENDED ] April 2011 - 43oh Project of the Month Contest


The April 2011 - 43oh Project of the Month Contest  

28 members have voted

You do not have permission to vote in this poll, or see the poll results. Please sign in or register to vote in this poll.

Recommended Posts

Voting closed.

 

Congratulations to NatureTM on his "Polyphonic MIDI Dynth" project. He wins this April 2011 Project of the Month Contest.

Runner up is the "Serial to 7 segment LED display driver v1" by Rob.

 

A big thank you to PhirePhly, GeoNomad and SugarAddict for participating. Wish you all luck in the upcoming contests.

Link to post
Share on other sites
  • 2 weeks later...

Got my prize in the mail today!

I wish I could start using it right away, but I decided to not keep up with my calculus class for the past month. My exam is the day after tomorrow. I did 3 weeks worth of units today, and I get to do another two weeks worth tomorrow.

 

"Dave, my mind is going. I can feel it. I can feel it. My mind is going. There is no question about it."

Link to post
Share on other sites
  • 9 months later...
SugarAddict's submission:

viewtopic.php?f=8&t=732&hilit=tlc5940#p4986

 

Ok... here's something much nicer... still horribly commented code with some stuff that could be cleaned up or improved...

 

[attachment=0]MSP430_LED_Control_tlc5940.png[/attachment]

 

 

// I know that my commenting sucks ass... I'm not exactly working on a team project here :-P

#define SetLow(port, pin) (port &= ~pin)
#define SetHigh(port, pin) (port |= pin)
#define Pulse(port, pin) do{SetHigh(port, pin);SetLow(port, pin);} while(0)

#define DELTA_1MHZ    244                   // 244 x 4096Hz = 999.4Hz
#define DELTA_8MHZ    1953                  // 1953 x 4096Hz = 7.99MHz
#define DELTA_12MHZ   2930                  // 2930 x 4096Hz = 12.00MHz
#define DELTA_16MHZ   3906                  // 3906 x 4096Hz = 15.99MHz
#define DELTA_18MHZ   4395                  // 4395 x 4096Hz = 18.00MHz
#define DELTA_20MHZ   4883                  // 4883 x 4096Hz = 20.00MHz
#define DELTA_24MHZ   5859                  // 5859 x 4096Hz = 23.99MHz

#include "msp430g2252.h"

void Rotate(void);
void Bounce(void);
void Set_DCO(unsigned int Delta);            // Set DCO to selected frequency
void SendDotCorrectionData(void);
void SendGreyScaleData(void);

int dcdata[] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};

int gsdata[] = {	0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
				0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x0000, 0x0000, 0x0000,
				0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
				0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};


char CntrA = 0, CntrB = 0, dcsent = 0, rotator = 0, bounce = 12, bouncedir = 0;
int Counter = 0, data = 0, data2 = 0;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;						// Stop WDT

//	BCSCTL1 = CALBC1_16MHZ;                      // Set range  
//	DCOCTL = CALDCO_16MHZ;                       // Set DCO step + modulation
Set_DCO(4639); // 19 MHz


// 1.6 DCPRG, 1.7 GSCLK
// 2.0 VPRG, 2.1/2.2 SIN, 2.3 XLAT. 2.4 SCLK, 2.5 BLANK
P1DIR |= (BIT6|BIT7);
P2DIR |= (BIT0|BIT1|BIT2|BIT3|BIT4|BIT5);
P1OUT &= ~(BIT7);
P1OUT |= (BIT6);
P2OUT &= ~(BIT1|BIT2|BIT3|BIT4);
P2OUT |= (BIT0|BIT5);

CCTL0 = CCIE;									// CCR0 interrupt enabled
CCR0 = 56;
TACTL = TASSEL_2 + MC_1 + ID_0; // SMCLK, Up 

TACTL |= MC_0; // Stop 
SendDotCorrectionData();
SendGreyScaleData();

TACTL &= ~MC_0; // Start 

_bis_SR_register(LPM0_bits + GIE);           // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
Counter++;

if(Counter>4095)
{
	TACTL |= MC_0; // Stop 
	Counter = 0;
	CntrA = 0;
	CntrB = 0;
	SetHigh(P2OUT,BIT5);
	Pulse(P2OUT,BIT3);
	rotator++;
	if(rotator>3)
	{
		//Rotate();
		Bounce();
		rotator = 0;
	}
	SendGreyScaleData();
	TACTL &= ~MC_0; // Start 
}

Pulse(P1OUT, BIT7);
}

void Rotate(void)
{
data = gsdata[31];
for(CntrA = 31;CntrA > 0;CntrA--)
{
	gsdata[CntrA] = gsdata[CntrA-1];
}
gsdata[0] = data;
data = 0; CntrA = 0;
}

void Bounce(void)
{
char i = 0;
if(bounce == 31) bouncedir = 1;
if(bounce == 0) bouncedir = 0;

if(bouncedir == 0) // Up
{
	for(i=0;i<32;i++)
	{
		gsdata[i] >>= 1;
	}
	bounce++;
	gsdata[bounce] = 0x1000;
}
else // down
{
	for(i=0;i<32;i++)
	{
		gsdata[i] >>= 1;
	}
	bounce--;
	gsdata[bounce] = 0x1000;
}
}

void Set_DCO(unsigned int Delta)            // Set DCO to selected frequency
{
 unsigned int Compare, Oldcapture = 0;

 BCSCTL1 |= DIVA_3;                        // ACLK = LFXT1CLK/8
 TACCTL0 = CM_1 + CCIS_1 + CAP;            // CAP, ACLK
 TACTL = TASSEL_2 + MC_2 + TACLR;          // SMCLK, cont-mode, clear

 while (1)
 {
   while (!(CCIFG & TACCTL0));             // Wait until capture occured
   TACCTL0 &= ~CCIFG;                      // Capture occured, clear flag
   Compare = TACCR0;                       // Get current captured SMCLK
   Compare = Compare - Oldcapture;         // SMCLK difference
   Oldcapture = TACCR0;                    // Save current captured SMCLK

   if (Delta == Compare)
     break;                                // If equal, leave "while(1)"
   else if (Delta < Compare)
   {
     DCOCTL--;                             // DCO is too fast, slow it down
     if (DCOCTL == 0xFF)                   // Did DCO roll under?
       if (BCSCTL1 & 0x0f)
         BCSCTL1--;                        // Select lower RSEL
   }
   else
   {
     DCOCTL++;                             // DCO is too slow, speed it up
     if (DCOCTL == 0x00)                   // Did DCO roll over?
       if ((BCSCTL1 & 0x0f) != 0x0f)
         BCSCTL1++;                        // Sel higher RSEL
   }
 }
 TACCTL0 = 0;                              // Stop TACCR0
 TACTL = 0;                                // Stop Timer_A
 BCSCTL1 &= ~DIVA_3;                       // ACLK = LFXT1CLK
}


void SendDotCorrectionData(void)
{
CntrA = 0;
CntrB = 0;
data = dcdata[CntrA];
while(CntrA<6)
{
	if(CntrB<16)
	{
		if(data & 0x8000)
		{
			SetHigh(P2OUT,BIT1);
			SetHigh(P2OUT,BIT2);
		}
		else
		{
			SetLow(P2OUT,BIT1);
			SetLow(P2OUT,BIT2);
		}
		data <<= 1;
		CntrB++;
		Pulse(P2OUT,BIT4);
	}
	else
	{
		CntrA++;
		if(CntrA<6)
		{
			CntrB = 1;
			data = dcdata[CntrA];
			if(data & 0x8000)
			{
				SetHigh(P2OUT,BIT1);
				SetHigh(P2OUT,BIT2);
			}
			else
			{
				SetLow(P2OUT,BIT1);
				SetLow(P2OUT,BIT2);
			}
			data <<= 1;
			Pulse(P2OUT,BIT4);
		}
	}
}

Pulse(P2OUT,BIT3);
CntrA = 0;
CntrB = 0;
dcsent = 1;
SetLow(P2OUT,BIT0);
}

void SendGreyScaleData(void)
{
CntrA = 0;
CntrB = 0;
data = gsdata[CntrA];
data2 = gsdata[(CntrA+16)];
while(CntrA<16)
{
	if(CntrB<12)
	{
		if(data & 0x1000)
			SetHigh(P2OUT,BIT1);
		else
			SetLow(P2OUT,BIT1);

		if(data2 & 0x1000)
			SetHigh(P2OUT,BIT2);
		else
			SetLow(P2OUT,BIT2);
		data <<= 1;
		data2 <<= 1;
		CntrB++;
		Pulse(P2OUT,BIT4);
	}
	else
	{
		CntrA++;
		if(CntrA<16)
		{
			CntrB = 1;
			data = gsdata[CntrA];
			data2 = gsdata[(CntrA+16)];
			if(data & 0x1000)
				SetHigh(P2OUT,BIT1);
			else
				SetLow(P2OUT,BIT1);

			if(data2 & 0x1000)
				SetHigh(P2OUT,BIT2);
			else
				SetLow(P2OUT,BIT2);
			data <<= 1;
			data2 <<= 1;
			Pulse(P2OUT,BIT4);
		}
	}
}

Pulse(P2OUT,BIT3);
SetLow(P2OUT,BIT5);
if(dcsent == 1)
{
	Pulse(P2OUT,BIT4);
	dcsent = 2;
}
}

 

 

 

Can someone help me with this, I'm playing around with this project and I keep getting "identifier "TIMER0_A0_VECTOR" is undefined" and I can't figure out why, it looks defined to me? I'm using the G2231 and I have changed it accordingly in the code, but is there something else i need to change to make this work with the G2231?? Thanks!

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...