使用 CCS v10、并且当前在定制 SBC 上运行 MSP430F5638。 使用 TB0创建用于 LED 调光的 PWM。 TB0工作正常、在示波器上获得所需的频率和占空比。 但我有很多问题。 我包含了与完整版相同的简化版部分。 完整程序会将大量数据发送到所连接的 LCD 以进行测试和开发-为清晰起见、删除了该代码。
void main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer // setup functions // setup_430_ports(); setup_430_clocks(); // use XT2 @ 20 MHz // setup testing for LED PWM Dimmer set_LED_TB0_dim(); // no code accessible after LED function runs // LCD_put_string_4_cc(170, 20, "AFTER LED TB0 CALL", red, white); }
void set_LED_TB0_dim(void) { float xt2 = 20e6, frequency, dutycycle; WDTCTL = WDTPW+WDTHOLD; // Stop WDT P4SEL |= BIT6; // P4.6 peripheral option select P4DIR |= BIT6; // P4.6 output // left most 0 not required since only 1 TB TBCCR0 = 100; // set CCR0 cycle period register TBCCTL6 = OUTMOD_7; // set CCR6 Output mode, reset/set TBCCR6 = 50; // set CCR6 PWM duty cycle TBEX0 = 0; // has no effect, 0 = '/1' by default // enable CCR6 interrupt - required for ISR to run // but disables TB0, no PWM out //TBCCTL6 = CCIE; // ID_0 = /1 by default // add enable interrupt - not necessary (+ TBIE), removed TBCTL = TBSSEL_2 + MC_1 + ID_0 + TBCLR; // SMCLK, up mode to CCR0, /1, TB clear // compute frequency & duty cycle for LCD diagnostics frequency = xt2/TBCCR0; // not accurate for > 50% and < 100%, need to cast int as float dutycycle = (float)TBCCR0/TBCCR6; // no timer output without this? __bis_SR_register(LPM0_bits + GIE); // enter LPM0 with interrupts enabled, CPU off, runs in regular routines //__bis_SR_register(GIE); // interrupts enabled, runs in regular routines //__bic_SR_register_on_exit(LPM0_bits); // exit LPM0 - can only run from ISR's } // ISR from msp430f66xx_tb_03.c and modified // Timer_B0 CCR6 Interrupt Vector (TBIV) handler // changed from B1 to B0 - BOTH MUST BE B1 TO WORK???? #pragma vector=TIMERB1_VECTOR __interrupt void TIMERB1_ISR(void) { switch( __even_in_range(TBIV,14) ) { case 0: break; // No interrupt case 2: break; // CCR1 not used case 4: break; // CCR2 not used case 6: break; // CCR3 not used case 8: break; // CCR4 not used case 10: break; // CCR5 not used case 12: // CCR6 overflow { __bic_SR_register_on_exit(LPM0_bits); // exit LPM0, can only run from ISR LCD_put_string_4_cc(170, 40, "IN TB0 ISR CASE 12", red, white); break; } case 14: break; // CCR7 not used default: { LCD_put_string_4_cc(190, 0, "IN TB0 ISR DEFAULT CASE", white, red); break; // no default } } }
main()问题
1.在调用 SET_LED_TB0_DIM ()后,为什么 main()中的任何代码都不运行?
Set_LED_TB0_DIM ()问题
- MSP430F5638只有一 TB、因此看起来0后缀是多余的 TBCCR0、TB0CCR0都起作用
- TBCCTL6 = ISR 运行需要 CCIE、但禁用 TB0、无 PWM 输出
- 为什么 SET_LED_TB0_DIM ()进入 LPM 模式? 没有它就无法运行。
- 为什么需要 CCIE、但不需要 TBIE?
- __bis_SR_register (LPM0_bits + GIE)可与 LPM0_bits 配合使用或不与 LPM0_bits 配合使用(我不是实时检查功耗–但看起来是相同的142ma)
我真的不希望 TB0将 CPU 放入 LPM 中、但没有它、代码就无法运行。
ISR 问题
为什么 ISR 名称在矢量和函数名称中要求 B1、而不要求 B0? 这是 TB0、但不适用于 B0。