要如何透過PWM的概念去設計LED燈的閃爍

374 views
Skip to first unread message

幽藍心域

unread,
Aug 9, 2012, 4:02:47 AM8/9/12
to msp430lau...@googlegroups.com
版主你好!!
在此論壇中有一章節在討論PWM的概念,剛好符合我們一些裝飾上需求,但是我現在打算外接其它的LED燈,所以想要請問一下:

1.我可以設定不同的接腳作為PWM來控制其它的LED嗎?
2.我有查詢過一些8051的單晶片概念,我可以套用想同的想法嗎?
如:我的LED燈泡是吃12V的電,所以我將板子設定為低電位(也就是0)時後亮、高電位(也就是1)時後暗
所以四顆LED要交錯閃爍就把他設定為10、5、10、5(16進制)這樣閃爍嗎?
或是有其它的設定方式?
3.目前我想要設定4種LED燈閃爍的模式,在PWM的設定上我該怎樣寫呢?
是否可請版主提供我一個概念讓我進行修改呢??

在此先感謝版主的協助。

Wang Taiyuan

unread,
Aug 9, 2012, 4:38:53 AM8/9/12
to msp430lau...@googlegroups.com



2012/8/9 幽藍心域 <line...@gmail.com>

版主你好!!
在此論壇中有一章節在討論PWM的概念,剛好符合我們一些裝飾上需求,但是我現在打算外接其它的LED燈,所以想要請問一下:

1.我可以設定不同的接腳作為PWM來控制其它的LED嗎?

當然OK。 以<<類比輸出 + 使LED明暗變化>>範例中
原始程式碼, LED PWM, Breathing LED effect with the LaunchPad_msp430g2553
要改用其他腳位只須改變定義的BIT6 為P1.6 去改成你想要的腳位。


2.我有查詢過一些8051的單晶片概念,我可以套用想同的想法嗎?
如:我的LED燈泡是吃12V的電,所以我將板子設定為低電位(也就是0)時後亮、高電位(也就是1)時後暗
所以四顆LED要交錯閃爍就把他設定為10、5、10、5(16進制)這樣閃爍嗎?
或是有其它的設定方式?

Launchpad的I/O點只有3.3V,如果你的應用是驅動12V LED燈泡,應該要加relay繼電器電路,單純Launchpad IO無法直接對接,電壓電流都太小,我相信如果你使用8051也是不能這樣做。 
 
3.目前我想要設定4種LED燈閃爍的模式,在PWM的設定上我該怎樣寫呢?
是否可請版主提供我一個概念讓我進行修改呢??

原始碼程式部分,我們的建議是請先依照站上的 <<類比輸出 + 使LED明暗變化>>範例實際作一遍,雖然它簡單但是可以確定你已經能夠控制到"一顆LED的閃爍",如果成功,至於你要調整成"多顆"LED模式或是其他變化,我相信只是多拉一些LED接線與COPY增加一段程式而已。


在此先感謝版主的協助。

--
您收到此郵件,是因為您訂閱了 Google 網上論壇的「[玩USB互動裝置] TI
MSP430 LaunchPad 使用者討論區」群組。
如要在此群組張貼留言,請寄電子郵件至 msp430lau...@googlegroups.com
如要取消訂閱此群組,請寄電子郵件至
msp430launchpad...@googlegroups.com
如需更多選項,請造訪此群
組:http://groups.google.com/group/msp430launchpaddiy?hl=zh-TW?hl=zh-TW

幽藍心域

unread,
Aug 9, 2012, 9:43:06 PM8/9/12
to msp430lau...@googlegroups.com


板主於 2012年8月9日星期四UTC+8下午4時38分53秒寫道:



2012/8/9 幽藍心域 <line...@gmail.com>

2.我有查詢過一些8051的單晶片概念,我可以套用想同的想法嗎?
如:我的LED燈泡是吃12V的電,所以我將板子設定為低電位(也就是0)時後亮、高電位(也就是1)時後暗
所以四顆LED要交錯閃爍就把他設定為10、5、10、5(16進制)這樣閃爍嗎?
或是有其它的設定方式?

Launchpad的I/O點只有3.3V,如果你的應用是驅動12V LED燈泡,應該要加relay繼電器電路,單純Launchpad IO無法直接對接,電壓電流都太小,我相信如果你使用8051也是不能這樣做。 
 

我所提到的燈泡是指製作成T10燈座的燈泡,其實內部也是電阻和二極體的解構,照片如下:

 基本上電流大小當然會影響燈光亮度,但是板子本身無法供應12V,所以我才思考從外部送電,把板子的接口做為地端,當然也擔心燒壞。

我查詢到8051的概念圖:

畢竟我們希望可以比較亮的LED燈!!

先感謝版主協助回答! 

--
您收到此郵件,是因為您訂閱了 Google 網上論壇的「[玩USB互動裝置] TI
MSP430 LaunchPad 使用者討論區」群組。
如要在此群組張貼留言,請寄電子郵件至 msp430lau...@googlegroups.com
如要取消訂閱此群組,請寄電子郵件至

幽藍心域

unread,
Aug 9, 2012, 10:51:08 PM8/9/12
to msp430lau...@googlegroups.com


板主於 2012年8月9日星期四UTC+8下午4時38分53秒寫道:



2012/8/9 幽藍心域 <line...@gmail.com>
版主你好!!
在此論壇中有一章節在討論PWM的概念,剛好符合我們一些裝飾上需求,但是我現在打算外接其它的LED燈,所以想要請問一下:

1.我可以設定不同的接腳作為PWM來控制其它的LED嗎?

當然OK。 以<<類比輸出 + 使LED明暗變化>>範例中
原始程式碼, LED PWM, Breathing LED effect with the LaunchPad_msp430g2553
要改用其他腳位只須改變定義的BIT6 為P1.6 去改成你想要的腳位。


在此項的設定上我發現一個問題,當我射成其它腳位的時候,輸出的電壓都是固定的,也就是無法創造出閃爍的情況。
真的比較不熟悉腳位的設定和基本概念!!將請版主多協助一下,感謝!!
 


在此先感謝版主的協助。

--
您收到此郵件,是因為您訂閱了 Google 網上論壇的「[玩USB互動裝置] TI
MSP430 LaunchPad 使用者討論區」群組。
如要在此群組張貼留言,請寄電子郵件至 msp430lau...@googlegroups.com
如要取消訂閱此群組,請寄電子郵件至

Wang Taiyuan

unread,
Aug 10, 2012, 12:33:08 AM8/10/12
to msp430lau...@googlegroups.com

2012/8/10 幽藍心域 <line...@gmail.com>



板主於 2012年8月9日星期四UTC+8下午4時38分53秒寫道:



2012/8/9 幽藍心域 <line...@gmail.com>
版主你好!!
在此論壇中有一章節在討論PWM的概念,剛好符合我們一些裝飾上需求,但是我現在打算外接其它的LED燈,所以想要請問一下:

1.我可以設定不同的接腳作為PWM來控制其它的LED嗎?

當然OK。 以<<類比輸出 + 使LED明暗變化>>範例中
原始程式碼, LED PWM, Breathing LED effect with the LaunchPad_msp430g2553
要改用其他腳位只須改變定義的BIT6 為P1.6 去改成你想要的腳位。


在此項的設定上我發現一個問題,當我射成其它腳位的時候,輸出的電壓都是固定的,也就是無法創造出閃爍的情況。
真的比較不熟悉腳位的設定和基本概念!!將請版主多協助一下,感謝!!

先請問,如果完全照著範例作,你可以讓基板上的P1.6閃爍嗎? 請務必在你的環境下操作一次。
如果成功的話,接下來,才開始在試個改變P1.6為其他數值例如P1.0,務必要確認每一個更改的地方 。
如果還是失敗,請POST出來原始碼,大家才有可能知道你的程式哪裡出了錯。

 
 


在此先感謝版主的協助。

--
您收到此郵件,是因為您訂閱了 Google 網上論壇的「[玩USB互動裝置] TI
MSP430 LaunchPad 使用者討論區」群組。
如要在此群組張貼留言,請寄電子郵件至 msp430lau...@googlegroups.com

如要取消訂閱此群組,請寄電子郵件至
msp430launchpaddiy+unsub...@googlegroups.com
如需更多選項,請造訪此群
組:http://groups.google.com/group/msp430launchpaddiy?hl=zh-TW?hl=zh-TW

--
您收到此郵件,是因為您訂閱了 Google 網上論壇的「[玩USB互動裝置] TI
MSP430 LaunchPad 使用者討論區」群組。
如要在此群組張貼留言,請寄電子郵件至 msp430lau...@googlegroups.com
如要取消訂閱此群組,請寄電子郵件至

幽藍心域

unread,
Aug 10, 2012, 2:10:11 AM8/10/12
to msp430lau...@googlegroups.com
抱歉!!我重新提供我所修改的程式碼:
設定:更改為P1.0也就是紅色LED亮(燈光長亮)
延長燈光閃爍的速度(在綠色LED表現正常)
以下是我修改後的程式碼:

#include  "msp430g2553.h"

int index = 0;   // 指數的PWM的佔空比(亮度)
int i=0;
const unsigned char curve[] = {
1,     1,     1,     1,     1,     1,     1,     1,
   1,     1,     1,     1,     1,     1,     1,     1,
   1,     1,     1,     2,     2,     2,     2,     2,
   2,     2,     3,     3,     3,     3,     3,     3,
   4,     4,     4,     4,     4,     5,     5,     5,
   5,     6,     6,     6,     6,     7,     7,     7,
   8,     8,     8,     8,     9,     9,     9,    10,
  10,    10,    11,    11,    11,    12,    12,    13,
  13,    13,    14,    14,    15,    15,    15,    16,
  16,    17,    17,    18,    18,    18,    19,    19,
  20,    20,    21,    21,    22,    22,    23,    23,
  24,    24,    25,    25,    26,    26,    27,    27,
  28,    29,    29,    30,    30,    31,    31,    32,
  33,    33,    34,    34,    35,    36,    36,    37,
  38,    38,    39,    39,    40,    41,    41,    42,
  43,    43,    44,    45,    46,    46,    47,    48,
  48,    49,    50,    50,    51,    52,    53,    53,
  54,    55,    56,    56,    57,    58,    59,    59,
  60,    61,    62,    62,    63,    64,    65,    66,
  66,    67,    68,    69,    70,    70,    71,    72,
  73,    74,    75,    75,    76,    77,    78,    79,
  80,    80,    81,    82,    83,    84,    85,    86,
  87,    87,    88,    89,    90,    91,    92,    93,
  94,    95,    95,    96,    97,    98,    99,   100,
 101,   102,   103,   104,   105,   106,   106,   107,
 108,   109,   110,   111,   112,   113,   114,   115,
 116,   117,   118,   119,   120,   121,   122,   122,
 123,   124,   125,   126,   127,   128,   129,   130,
 131,   132,   133,   134,   135,   136,   137,   138,
 139,   140,   141,   142,   143,   144,   145,   146,
 147,   148,   149,   150,   151,   152,   153,   154,
 155,   156

};

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

  // Set clock to 1 MHz
  DCOCTL= 0;
  BCSCTL1= CALBC1_1MHZ;
  DCOCTL= CALDCO_1MHZ;

  // SMCLK = 1 MHz / 8 = 125 KHz (SLAU144E p.5-15)
  BCSCTL2 |= DIVS_3;

  // Make P1.6 (green led) an output. SLAU144E p.8-3
  P1DIR |= BIT0;

  // P1.6 = TA0.1 (定時器A的輸出). SLAS694C p.41
  P1SEL |= BIT0;

  // PWM 週期 = 125 KHz / 625 = 200 Hz(可改變閃爍速度)
  TACCR0 = 1250;

  // Source Timer A from SMCLK (TASSEL_2), up mode (MC_1).
  // Up mode counts up to TACCR0. SLAU144E p.12-20
  //源定時器A SMCLK(TASSEL_2)啟動模式(MC_1)。
  // Up模式計數TACCR0。 SLAU144E P.12-20
  TACTL = TASSEL_2 | MC_1;

  // OUTMOD_7 = Reset/set output when the timer counts to TACCR1/TACCR0
  // CCIE = Interrupt when timer counts to TACCR1
//OUTMOD_7=復位/套輸出時,定時器計數到TACCR1/TACCR0
// CCIE的=中斷時,定時器計數到TACCR1


  TACCTL1 = OUTMOD_7 | CCIE;

  // Initial CCR1 (= brightness)
  //初始CCR1(亮度)
  TACCR1 = 0;

  // LPM0 (shut down the CPU) with interrupts enabled
  //LPM0(下降的CPU)啟用中斷
  __bis_SR_register(CPUOFF | GIE);

}

// This will be called when timer counts to TACCR1.
//這將被稱為當定時器數以TACCR1的。
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
  int new_ccr1 = 1;

  // Clear interrupt flag
 //清除中斷標誌
  TACCTL1 &= ~CCIFG;

  if (index < 500) {
    new_ccr1 = curve[index++ >> 1];
  } else if (index < 1000) {
    new_ccr1 = curve[(999 - index++) >> 1];
  } else {
    index = 0;
  }
  // Wait to set the new TACCR1 until TAR has gone past it, so that we
  // don't get interrupted again in this period.
  //等待,直到的TAR已經過去了設置新的TACCR1,所以我們
  //不被打斷再次在此期間。
  while (TAR <= new_ccr1);
  TACCR1 = new_ccr1;

楊曄群

unread,
Aug 12, 2012, 5:18:01 AM8/12/12
to msp430lau...@googlegroups.com
�z�n 
�ڦb��� launchpad  PWM ���ɭ�,  �]�J��L�o�Ӱ��D....
���D�bDATA Sheet ���i�঳�ѵ�  (�ڬO�� �j�~�� ^_^  !)
SLAS694C p.33  p1.0 �� Pin Functions �?��
P1.0  / TA0CLK /ACLK   
��� P1.0  �ȥi�@�� TA0CLK(��J?)  , �L�k�N TA0.1 ��X�ɦV�� P1.0
�p�]�w�n�N P1.0 �@�� PWM ��X, �N�o�� digital I/O ���覡����
�o�ӧ@�k�|�۷��� cpu ���u�@�ɶ�(?)

�ڥ� energia  (Arduino Like �� Lanuchpad �}�o����)���g�F�@��
green�M red Led ���| �ѷt��G�ѫG��t�� PWM  ���� example
��O���@�Ӧa��M arduino reference ������P, 
analogWrite () ����X��Ť�M reference ���ۤ�, �̫�˹L��count �~�@
�X�ӧڭn���ĪG


energia �{���p�U: 
P1.0 �i�� digitalWrite()��XPWM,  �����analogWrite()��X
P1.6 �i��analogWrite()��XPWM,  �]�i��digitalWrite() ��X

/*
 Fade
 
 This example shows how to fade an LED on pin P1.0 and P1.6
 using the analogWrite() function and digitalWrite() .
 
 This example code is in the public domain.
 
 */
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int interval;    // PWM duty cycle step
int cycle=50;    // Duty Cycle*interval  DO NOT SET Bigger THAN 1/20 sec for POV effect

void setup()  {
  // declare pin P1.0 P1.6  as output:
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
 
}

void loop()  {
digitalWrite(GREEN_LED,HIGH);
digitalWrite(RED_LED,LOW);
for (interval=0; interval<=255; interval+=5)
  {
    digitalWrite(RED_LED,HIGH);
    delayMicroseconds(cycle*interval+1);
    digitalWrite(RED_LED,LOW);
    delayMicroseconds(12750-cycle*interval+1);
    analogWrite(GREEN_LED,255-interval);  //?? reverse the interval from 255 to 0 will force the
                                          // Green LED  dimming from darkest to brightest ??
                                          //But it is different from Reference, HOW COME?
    delay(10);
  }
 for (interval=255; interval>=0; interval-=5)  // interval=256 will cause LED Blink ilregularly
                                              // According to reference the max value is 255 for
                                              // alalogWrite.
  {
    digitalWrite(RED_LED,HIGH);
    delayMicroseconds(cycle*interval+1);
    digitalWrite(RED_LED,LOW);
    delayMicroseconds(12750-cycle*interval+1);
    analogWrite(GREEN_LED,255-interval);
    delay(10);
  }
}

�� 2012/8/10 �U�� 02:10, ���Ť߰� ����:
��p!!�ڭ��s���ѧکҭק諸�{���X:
�]�w:��אּP1.0�]�N�O����LED�G(�O���G)
����O��{�{���t��(�b���LED��{���`)
�H�U�O�ڭק�᪺�{���X:

#include  "msp430g2553.h"

int index = 0;   // ��ƪ�PWM����Ť�]�G�ס^
  // P1.6 = TA0.1 (�w�ɾ�A����X). SLAS694C p.41
  P1SEL |= BIT0;

  // PWM �g�� = 125 KHz / 625 = 200 Hz(�i���ܰ{�{�t��)
  TACCR0 = 1250;

  // Source Timer A from SMCLK (TASSEL_2), up mode (MC_1).
  // Up mode counts up to TACCR0. SLAU144E p.12-20
  //���w�ɾ�A SMCLK�]TASSEL_2�^�ҰʼҦ��]MC_1�^�C
  // Up�Ҧ��p��TACCR0�C SLAU144E P.12-20
  TACTL = TASSEL_2 | MC_1;

  // OUTMOD_7 = Reset/set output when the timer counts to TACCR1/TACCR0
  // CCIE = Interrupt when timer counts to TACCR1
//OUTMOD_7=�_��/�M��X�ɡA�w�ɾ��p�ƨ�TACCR1/TACCR0
// CCIE��=���_�ɡA�w�ɾ��p�ƨ�TACCR1


  TACCTL1 = OUTMOD_7 | CCIE;

  // Initial CCR1 (= brightness)
  //��lCCR1�]�G�ס^
  TACCR1 = 0;

  // LPM0 (shut down the CPU) with interrupts enabled
  //LPM0�]�U����CPU�^�ҥΤ��_
  __bis_SR_register(CPUOFF | GIE);

}

// This will be called when timer counts to TACCR1.
//�o�N�Q�٬���w�ɾ��ƥHTACCR1���C
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
  int new_ccr1 = 1;

  // Clear interrupt flag
 //�M�����_�лx
  TACCTL1 &= ~CCIFG;

  if (index < 500) {
    new_ccr1 = curve[index++ >> 1];
  } else if (index < 1000) {
    new_ccr1 = curve[(999 - index++) >> 1];
  } else {
    index = 0;
  }
  // Wait to set the new TACCR1 until TAR has gone past it, so that we
  // don't get interrupted again in this period.
  //���ݡA���쪺TAR�w�g�L�h�F�]�m�s��TACCR1�A�ҥH�ڭ�
  //���Q���_�A���b�������C
  while (TAR <= new_ccr1);
  TACCR1 = new_ccr1;
--
�z���즹�l��A�O�]���z�q�\�F Google ���W�׾ª��u[��USB���ʸ˸m] TI
MSP430 LaunchPad �ϥΪ̰Q�װϡv�s�աC
�p�n�b���s�ձi�K�d���A�бH�q�l�l��� msp430lau...@googlegroups.com
�p�n���q�\���s�աA�бH�q�l�l���
msp430launchpad...@googlegroups.com
�p�ݧ�h�ﶵ�A�гy�X���s
�աGhttp://groups.google.com/group/msp430launchpaddiy?hl=zh-TW?hl=zh-TW �C


-- 
�ѻ���  ����s  
Docent  Alan Yang  
�O�_���ߤѤ��DZШ|�] 
Taipei Astronomical Museum
TEL:886-2-28314551ext 305
SKYPE:iamalanyang
alan...@tam.gov.tw

幽藍心域

unread,
Aug 12, 2012, 9:23:18 PM8/12/12
to msp430lau...@googlegroups.com
版主!!不好意思!!
很多文字發現都是亂碼的說,那些文子只是符號呢?還是包含你說明與解釋?
我會先去了解你所提供的程式碼!!

Alan Yang於 2012年8月12日星期日UTC+8下午5時18分01秒寫道:
嚙緲嚙緯 
嚙誹在嚙踝蕭嚙�launchpad  PWM 嚙踝蕭嚙褕哨蕭,  嚙稽嚙皚嚙踝蕭L嚙緻嚙諉堆蕭嚙瘩....
嚙踝蕭嚙瘩嚙箭DATA Sheet 嚙踝蕭嚙箠嚙賞有嚙諸蛛蕭  (嚙誹是嚙踝蕭 嚙篌嚙羯嚙踝蕭 ^_^  !)
SLAS694C p.33  p1.0 嚙踝蕭 Pin Functions 嚙�嚙踝蕭
P1.0  / TA0CLK /ACLK   
嚙踝蕭嚙�P1.0  嚙褓可嚙瑾嚙踝蕭 TA0CLK(嚙踝蕭J?)  , 嚙盤嚙糊嚙瞇 TA0.1 嚙踝蕭X嚙褕向嚙踝蕭 P1.0
嚙緘嚙稽嚙緩嚙緯嚙瞇 P1.0 嚙瑾嚙踝蕭 PWM 嚙踝蕭X, 嚙瞇嚙緻嚙踝蕭 digital I/O 嚙踝蕭嚙質式嚙踝蕭嚙踝蕭
嚙緻嚙諉作嚙糊嚙罵嚙諛瘀蕭嚙踝蕭 cpu 嚙踝蕭嚙線嚙瑾嚙褕塚蕭(?)

嚙誹伐蕭 energia  (Arduino Like 嚙踝蕭 Lanuchpad 嚙罷嚙緻嚙踝蕭嚙踝蕭)嚙踝蕭嚙篇嚙瘤嚙瑾嚙踝蕭
green嚙瞎 red Led 嚙踝蕭嚙罵 嚙諸暗嚙踝蕭G嚙諸亮嚙踝蕭t嚙踝蕭 PWM  嚙踝蕭嚙踝蕭 example
嚙踝蕭O嚙踝蕭嚙瑾嚙諉地嚙踝蕭M arduino reference 嚙踝蕭嚙踝蕭嚙踝蕭P, 
analogWrite () 嚙踝蕭嚙踝蕭X嚙踝蕭聾嚙瞎 reference 嚙踝蕭嚙諛歹蕭, 嚙諒恬蕭佴L嚙踝蕭count 嚙羯嚙瑾
嚙碼嚙諉我要嚙踝蕭嚙衝果


energia 嚙緹嚙踝蕭嚙緘嚙磊: 
P1.0 嚙箠嚙踝蕭 digitalWrite()嚙踝蕭XPWM,  嚙踝蕭嚙踝蕭嚙窮nalogWrite()嚙踝蕭X
P1.6 嚙箠嚙踝蕭analogWrite()嚙踝蕭XPWM,  嚙稽嚙箠嚙踝蕭digitalWrite() 嚙踝蕭X
嚙踝蕭 2012/8/10 嚙磊嚙踝蕭 02:10, 嚙踝蕭嚙褐心堆蕭 嚙踝蕭嚙踝蕭:
嚙踝蕭p!!嚙誹哨蕭嚙編嚙踝蕭嚙諸我所修改的嚙緹嚙踝蕭嚙碼:
嚙稽嚙緩:嚙踝蕭麍訐1.0嚙稽嚙瞇嚙瞌嚙踝蕭嚙踝蕭LED嚙瘦(嚙瞌嚙踝蕭嚙瘦)
嚙踝蕭嚙踝蕭O嚙踝蕭{嚙緹嚙踝蕭嚙緣嚙踝蕭(嚙箭嚙踝蕭嚙盤ED嚙踝蕭{嚙踝蕭嚙窯)
嚙瘡嚙磊嚙瞌嚙誹修改蕭嶊綽蕭{嚙踝蕭嚙碼:

#include  "msp430g2553.h"

int index = 0;   // 嚙踝蕭う嚙瞑WM嚙踝蕭嚙踝蕭聾嚙稽嚙瘦嚙論)
  // P1.6 = TA0.1 (嚙緩嚙褕橘蕭A嚙踝蕭嚙踝蕭X). SLAS694C p.41
  P1SEL |= BIT0;

  // PWM 嚙篇嚙踝蕭 = 125 KHz / 625 = 200 Hz(嚙箠嚙踝蕭嚙豌閃嚙緹嚙緣嚙踝蕭)
  TACCR0 = 1250;

  // Source Timer A from SMCLK (TASSEL_2), up mode (MC_1).
  // Up mode counts up to TACCR0. SLAU144E p.12-20
  //嚙踝蕭嚙緩嚙褕橘蕭A SMCLK嚙稽TASSEL_2嚙稷嚙課動模佗蕭嚙稽MC_1嚙稷嚙瘠
  // Up嚙課佗蕭嚙緘嚙踝蕭TACCR0嚙瘠 SLAU144E P.12-20
  TACTL = TASSEL_2 | MC_1;

  // OUTMOD_7 = Reset/set output when the timer counts to TACCR1/TACCR0
  // CCIE = Interrupt when timer counts to TACCR1
//OUTMOD_7=嚙稻嚙踝蕭/嚙瞎嚙踝蕭X嚙褕,嚙緩嚙褕橘蕭嚙緘嚙複剁蕭TACCR1/TACCR0
// CCIE嚙踝蕭=嚙踝蕭嚙稻嚙褕,嚙緩嚙褕橘蕭嚙緘嚙複剁蕭TACCR1


  TACCTL1 = OUTMOD_7 | CCIE;

  // Initial CCR1 (= brightness)
  //嚙踝蕭lCCR1嚙稽嚙瘦嚙論)
  TACCR1 = 0;

  // LPM0 (shut down the CPU) with interrupts enabled
  //LPM0嚙稽嚙磊嚙踝蕭嚙踝蕭CPU嚙稷嚙課用歹蕭嚙稻
  __bis_SR_register(CPUOFF | GIE);

}

// This will be called when timer counts to TACCR1.
//嚙緻嚙瞇嚙瞋嚙誶穿蕭嚙踝蕭w嚙褕橘蕭嚙複以TACCR1嚙踝蕭嚙瘠
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
  int new_ccr1 = 1;

  // Clear interrupt flag
 //嚙瞎嚙踝蕭嚙踝蕭嚙稻嚙請誌
  TACCTL1 &= ~CCIFG;

  if (index < 500) {
    new_ccr1 = curve[index++ >> 1];
  } else if (index < 1000) {
    new_ccr1 = curve[(999 - index++) >> 1];
  } else {
    index = 0;
  }
  // Wait to set the new TACCR1 until TAR has gone past it, so that we
  // don't get interrupted again in this period.
  //嚙踝蕭嚙豎,嚙踝蕭嚙趣的TAR嚙緩嚙篇嚙盤嚙篁嚙瘤嚙稽嚙練嚙編嚙踝蕭TACCR1嚙璀嚙課以嚙誹哨蕭
  //嚙踝蕭嚙瞋嚙踝蕭嚙稻嚙璀嚙踝蕭嚙箭嚙踝蕭嚙踝蕭嚙踝蕭嚙瘠
  while (TAR <= new_ccr1);
  TACCR1 = new_ccr1;
--
嚙緲嚙踝蕭嚙趣此嚙締嚙踝蕭A嚙瞌嚙稽嚙踝蕭嚙緲嚙緬嚙穀嚙瘤 Google 嚙踝蕭嚙磕嚙論壇迎蕭嚙線[嚙踝蕭USB嚙踝蕭嚙褊裝置] TI
MSP430 LaunchPad 嚙誕用者討嚙論區」嚙編嚙調。
嚙緘嚙緯嚙箭嚙踝蕭嚙編嚙調張嚙皺嚙範嚙踝蕭嚙璀嚙請寄嚙緬嚙締嚙締嚙踝蕭嚙�msp430lau...@googlegroups.com
嚙緘嚙緯嚙踝蕭嚙緬嚙穀嚙踝蕭嚙編嚙調,嚙請寄嚙緬嚙締嚙締嚙踝蕭嚙�br> msp430launchpaddiy+unsub...@googlegroups.com
嚙緘嚙豎改蕭h嚙踝項嚙璀嚙請造嚙碼嚙踝蕭嚙編
嚙調:http://groups.google.com/group/msp430launchpaddiy?hl=zh-TW?hl=zh-TW 嚙瘠


-- 
嚙諸鳴蕭嚙踝蕭  嚙踝蕭嚙踝蕭s  
Docent  Alan Yang  
嚙瞌嚙稻嚙踝蕭嚙賠天歹蕭嚙褒教育嚙稽 
Taipei Astronomical Museum
TEL:886-2-28314551ext 305
SKYPE:iamalanyang
alan...@tam.gov.tw

幽藍心域

unread,
Aug 12, 2012, 9:52:50 PM8/12/12
to msp430lau...@googlegroups.com

圖片為我所看到回覆畫面,主要擔心版主你所看的跟我看到不一樣!!

另外透過程式的執行發現下面版主所提供的程式出現GREEN_LED和RED_LED未定義,但是我並不清楚如何去宣告他,回推我的使用目的的話,我會選用其它腳位作為輸出,所以這種定義似乎不太適合。

目前我透過「視覺暫留POV LED」這各實驗中確定了在P.1的腳位上我可以利用0xXX的型態去決定我要亮哪一些LED燈,但是小弟只有兩個問題尚未解決,分別為:

1.如何透過PWM或其它的方式設定各種執行的迴圈或較方便的設定方式。
2.小弟所用的LED燈工作電壓為12V,透過MSP430無法驅動,不知到是否可以設定為低腳位做為地端來開關LED燈。

請版主多協助外,我也會查詢一些實際案例的。

楊曄群

unread,
Aug 12, 2012, 10:17:32 PM8/12/12
to msp430lau...@googlegroups.com
Sorry for the miscoded font.   I sent this mail via BIG5 encoded.  
There must be some error when transferring the latest mail. 
I am purely an another amateur registered in this mail group.    
AND most impotant is : I am not the groupmail manager , Mr. Wang Taiyuan  ^_^! 

The point is " IF P1.0 can be TA0 output".  
According the SLAS694C P33 , P1.0 could be  P1.0 /TA0CLK/ACLK  only.
It seems like that P1.0 do not  act  as TA0.x  output. 

I have implemented some example code in ENERGIA (Arduino Like Development
environment) to achive the PWM function with RED led.   It consumes more CPU resource
with digital I/O output.   But I think it work.  

Please  compile the code below  in ENERGIA.    And your will see  Green and Red LED
breathing .  The PWM control works on RED LED as well.

------------------------------------------------------------------------

/*
 Fade
 
 This example shows how to fade an LED on pin P1.0 and P1.6
 using the analogWrite() function and digitalWrite() .

P1.0 can be controled by digitalWrite() but not analogWrite().
P1.6 can be controled by digitlaWrite() ,  analogWrite() as well.
 
 This example code is in the public domain.
 
 */
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int interval;    // PWM duty cycle step
int cycle=50;    // Duty Cycle*interval  DO NOT SET Bigger THAN 1/20 sec for POV effect

void setup()  {
  // declare pin P1.0 P1.6  as output:
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
 
}

void loop()  {
digitalWrite(GREEN_LED,HIGH);
digitalWrite(RED_LED,LOW);
for (interval=0; interval<=255; interval+=5)
  {
    digitalWrite(RED_LED,HIGH);                        // Light up the RED Led  cycle*interval+1 microseconds
    delayMicroseconds(cycle*interval+1);
    digitalWrite(RED_LED,LOW);                        // Turn off the RED led  in  the other time cycle

    delayMicroseconds(12750-cycle*interval+1);
    analogWrite(GREEN_LED,255-interval);  //?? reverse the interval from 255 to 0 will force the
                                          // Green LED  dimming from darkest to brightest ??
                                          //But it is different from Reference, HOW COME?  I still get nothing about the fact.
    delay(10);
  }
 for (interval=255; interval>=0; interval-=5)  // interval=256 will cause LED Blink ilregularly
                                              // According to reference the max value is 255 for
                                              // alalogWrite.
  {
    digitalWrite(RED_LED,HIGH);
    delayMicroseconds(cycle*interval+1);
    digitalWrite(RED_LED,LOW);
    delayMicroseconds(12750-cycle*interval+1);
    analogWrite(GREEN_LED,255-interval);
    delay(10);
  }
}


於 2012/8/13 上午 09:23, 幽藍心域 提到:
--
您收到此郵件,是因為您訂閱了 Google 網上論壇的「[玩USB互動裝置] TI
MSP430 LaunchPad 使用者討論區」群組。
如要在此群組張貼留言,請寄電子郵件至 msp430lau...@googlegroups.com
如要取消訂閱此群組,請寄電子郵件至
msp430launchpad...@googlegroups.com
如需更多選項,請造訪此群
組:http://groups.google.com/group/msp430launchpaddiy?hl=zh-TW?hl=zh-TW


-- 
解說員  楊曄群  
Docent  Alan Yang  
臺北市立天文科學教育館 
Taipei Astronomical Museum
TEL:886-2-28314551ext 305
SKYPE:iamalanyang
alan...@tam.gov.tw

幽藍心域

unread,
Aug 13, 2012, 2:01:57 AM8/13/12
to msp430lau...@googlegroups.com
感謝你的回覆,在你所提供的程式中是可以大略了解程式的架構,但是部分字元似乎跟我們所用的CCS編輯器無法配對,固定出現的為:


#20 identifier "GREEN_LED" is undefined.
保括RED_LED、HIGH、LOW等表示狀態的設定都是未定義~

但是我會參考內部的PWM的迴圈設計概念

Alan Yang於 2012年8月13日星期一UTC+8上午10時17分32秒寫道:

如需更多選項,請造訪此群
組:http://groups.google.com/group/msp430launchpaddiy?hl=zh-TW?hl=zh-TW

Wang Taiyuan

unread,
Aug 13, 2012, 3:02:35 AM8/13/12
to msp430lau...@googlegroups.com
轉貼一次iamalanyang大大的文章 ....(已轉成圖檔顯示應該OK了)
 
Inline image 1

 

 

 
2012/8/13 楊曄群 <iamal...@gmail.com>
code.jpg

楊曄群

unread,
Aug 13, 2012, 3:35:24 AM8/13/12
to msp430lau...@googlegroups.com
The undefined  constant problem happened because I used to code launchpad in energia.
It is different from CCS.   It looks like ARDUINO  developement tool.
You can get more information from the blog bleow.

http://www.mcuapps.com/blog/2012/04/26/arduino-ide-for-msp430-launchpad/ 


於 2012/8/13 下午 02:01, 幽藍心域 提到:

幽藍心域

unread,
Aug 13, 2012, 3:51:11 AM8/13/12
to msp430lau...@googlegroups.com
我了解 Alan Yang 大所利用的是Arduino進行程式的編輯,所以小弟也試著要利用相同的概念進行規劃,但是沒有基礎的小弟時在不容易。

其實小弟最大的需求是:

1.安裝四顆LED燈,並透過PWM的開關概念輪流閃爍不同燈光。
例如:
第一段:LED-1、LED-2長亮3分鐘關閉
第二段:LED-1、2、3、4輪流閃爍3分鐘
第三段:LED-1、3和LED2、4輪流點亮和關閉

例如這種方式可以規劃我自己想要的LED燈節目
2.小弟所用的LED燈是12V的T10規格燈,所以不能透過MSP430 LaunchPad來點亮,所以在設計上可能要將LaunchPad設定為低電位來點亮LED,如:

P1.0=0==>LED燈亮
P1.1=1==>LED燈暗 

單純的推斷因該不是很難,只是小弟並無MSP430的開發經驗,已經在蒐集各種相關資料,但是並無法解答小弟的疑問,目前已透過此網站的資源了解LED燈的PWM開關和複數LED燈我該怎樣定義腳位,但是更加關鍵的就是無法將兩個概念組合,所以希望各位大大可以多點醒我一些觀念!!

感謝!!

Alan Yang於 2012年8月13日星期一UTC+8下午3時35分24秒寫道:
Reply all
Reply to author
Forward
0 new messages