07 - Pixel RGB
07 - Pixel RGB
Neste projeto elaboraremos o software necessário para acionar um led RGB. Ele contém 3
emissores de luz: vermelho (red), verde (green) e azul (blue).
A combinação das três cores, em intensidades variadas, permite criar todas as cores do
espectro visível.
Adotaremos a técnica de PWM para variar a intensidade luminosa de cada cor. Para tal
utilizaremos o Timer_A e as 3 saídas dos seus blocos de comparação TA0, TA1 e TA2.
Esta situação nos levará trará limitações na seleção dos de contagem e de saída o Ti‐
mer_A, mas é factível.
Seremos obrigados a utilizar o modo de contagem contínuo (MC=2) e o modo de saída Set
(OUTMOD = 1).
Para padronizar os programas, adotaremos as seguintes conexões de saída dos blocos CCR
e os leds:
RED = TA0 = P1.1
GREEN = TA1 = P1.2
BLUE = TA2 = P1.3
Prog10_a: CLOCK
Etapa inicial na qual vamos geral um programa simples que apenas configura o clock da
CPU para o seu valor máximo.
A verificação do resultado pode ser feita configurando o pino P1.4 como função espe‐
cial e saída. Neste caso e exteriorizará o sinal do SMCLK.
Prog10_b: Timer_A
Tomando por base a versão Prog10_a, vamos adicionar configuração do Timer_A:
‐ Bloco contador: o modo de contagem MC = 2; TAIF gerando interrupção ao final da
contagem.
‐ Para cada um dos blocos CCR0, 1 e 2: o modo de saída sendo OUTMOD = 1.
‐ A RTI gerada pelo TAIFG deve se encarregar de zerar as saídas TAO, 1 e 2. Isto pode
ser feito alterado o modo de saída para OUTMOD = 0 e depois retornando para OUTMOD =
1.
O teste de funcionamento pode ser feito atribuindo valores fixos para TACCR0, 1 e 2.
*/
MSP430F15x, MSP430F16x, MSP430F161x
MIXED SIGNAL MICROCONTROLLER
SLAS368G − OCTOBER 2002 − REVISED MARCH 2011
Terminal Functions
TERMINAL
I/O DESCRIPTION
NAME NO.
AVCC 64 Analog supply voltage, positive terminal. Supplies only the analog portion of ADC12 and DAC12.
AVSS 62 Analog supply voltage, negative terminal. Supplies only the analog portion of ADC12 and DAC12.
DVCC 1 Digital supply voltage, positive terminal. Supplies all digital parts.
DVSS 63 Digital supply voltage, negative terminal. Supplies all digital parts.
P1.0/TACLK 12 I/O General-purpose digital I/O pin/Timer_A, clock signal TACLK input
P1.1/TA0 13 I/O General-purpose digital I/O pin/Timer_A, capture: CCI0A input, compare: Out0 output/BSL transmit
P1.2/TA1 14 I/O General-purpose digital I/O pin/Timer_A, capture: CCI1A input, compare: Out1 output
P1.3/TA2 15 I/O General-purpose digital I/O pin/Timer_A, capture: CCI2A input, compare: Out2 output
P1.4/SMCLK 16 I/O General-purpose digital I/O pin/SMCLK signal output
P1.5/TA0 17 I/O General-purpose digital I/O pin/Timer_A, compare: Out0 output
P1.6/TA1 18 I/O General-purpose digital I/O pin/Timer_A, compare: Out1 output
P1.7/TA2 19 I/O General-purpose digital I/O pin/Timer_A, compare: Out2 output
P2.0/ACLK 20 I/O General-purpose digital I/O pin/ACLK output
P2.1/TAINCLK 21 I/O General-purpose digital I/O pin/Timer_A, clock signal at INCLK
P2.2/CAOUT/TA0 22 I/O General-purpose digital I/O pin/Timer_A, capture: CCI0B input/Comparator_A output/BSL receive
P2.3/CA0/TA1 23 I/O General-purpose digital I/O pin/Timer_A, compare: Out1 output/Comparator_A input
P2.4/CA1/TA2 24 I/O General-purpose digital I/O pin/Timer_A, compare: Out2 output/Comparator_A input
P2.5/Rosc 25 I/O General-purpose digital I/O pin/input for external resistor defining the DCO nominal frequency
P2.6/ADC12CLK/ 26 I/O General-purpose digital I/O pin/conversion clock – 12-bit ADC/DMA channel 0 external trigger
DMAE0
P2.7/TA0 27 I/O General-purpose digital I/O pin/Timer_A, compare: Out0 output
P3.0/STE0 28 I/O General-purpose digital I/O pin/slave transmit enable – USART0/SPI mode
P3.1/SIMO0/SDA 29 I/O General-purpose digital I/O pin/slave in/master out of USART0/SPI mode, I2C data − USART0/I2C mode
P3.2/SOMI0 30 I/O General-purpose digital I/O pin/slave out/master in of USART0/SPI mode
P3.3/UCLK0/SCL 31 I/O General-purpose digital I/O pin/external clock input − USART0/UART or SPI mode, clock output –
USART0/SPI mode, I2C clock − USART0/I2C mode
P3.4/UTXD0 32 I/O General-purpose digital I/O pin/transmit data out – USART0/UART mode
P3.5/URXD0 33 I/O General-purpose digital I/O pin/receive data in – USART0/UART mode
P3.6/UTXD1† 34 I/O General-purpose digital I/O pin/transmit data out – USART1/UART mode
P3.7/URXD1† 35 I/O General-purpose digital I/O pin/receive data in – USART1/UART mode
P4.0/TB0 36 I/O General-purpose digital I/O pin/Timer_B, capture: CCI0A/B input, compare: Out0 output
P4.1/TB1 37 I/O General-purpose digital I/O pin/Timer_B, capture: CCI1A/B input, compare: Out1 output
P4.2/TB2 38 I/O General-purpose digital I/O pin/Timer_B, capture: CCI2A/B input, compare: Out2 output
P4.3/TB3† 39 I/O General-purpose digital I/O pin/Timer_B, capture: CCI3A/B input, compare: Out3 output
P4.4/TB4† 40 I/O General-purpose digital I/O pin/Timer_B, capture: CCI4A/B input, compare: Out4 output
P4.5/TB5† 41 I/O General-purpose digital I/O pin/Timer_B, capture: CCI5A/B input, compare: Out5 output
P4.6/TB6† 42 I/O General-purpose digital I/O pin/Timer_B, capture: CCI6A input, compare: Out6 output
P4.7/TBCLK 43 I/O General-purpose digital I/O pin/Timer_B, clock signal TBCLK input
P5.0/STE1† 44 I/O General-purpose digital I/O pin/slave transmit enable – USART1/SPI mode
P5.1/SIMO1† 45 I/O General-purpose digital I/O pin/slave in/master out of USART1/SPI mode
P5.2/SOMI1† 46 I/O General-purpose digital I/O pin/slave out/master in of USART1/SPI mode
P5.3/UCLK1† 47 I/O General-purpose digital I/O pin/external clock input – USART1/UART or SPI mode, clock output –
USART1/SPI mode
† 16x, 161x devices only
USART0
The MSP430F15x and the MSP430F16x(x) have one hardware universal synchronous/asynchronous receive
transmit (USART0) peripheral module that is used for serial data communication. The USART supports
synchronous SPI (3 or 4 pin), asynchronous UART and I2C communication protocols using double-buffered
transmit and receive channels.
The I2C support is compliant with the Philips I2C specification version 2.1 and supports standard mode (up to
100 kbps) and fast mode (up to 400 kbps). In addition, 7-bit and 10-bit device addressing modes are supported,
as well as master and slave modes. The USART0 also supports 16-bit-wide I2C data transfers and has two
dedicated DMA channels to maximize bus throughput. Extensive interrupt capability is also given in the I2C
mode.
USART1 (MSP430F16x/161x only)
The MSP430F16x(x) devices have a second hardware universal synchronous/asynchronous receive transmit
(USART1) peripheral module that is used for serial data communication. The USART supports synchronous
SPI (3 or 4 pin) and asynchronous UART communication protocols, using double-buffered transmit and receive
channels. With the exception of I2C support, operation of USART1 is identical to USART0.
Timer_A3
Timer_A3 is a 16-bit timer/counter with three capture/compare registers. Timer_A3 can support multiple
capture/compares, PWM outputs, and interval timing. Timer_A3 also has extensive interrupt capabilities.
Interrupts may be generated from the counter on overflow conditions and from each of the capture/compare
registers.
LFXT1CLK Divider
/1/2/4/8
XTS ACLK
OSCOFF
Auxillary Clock
0V
XIN
12pF
LF XT
LFOff XT1Off
12pF
XOUT 0V
SELMx
LFXT1 Oscillator DIVMx
CPUOFF
00
01 Divider
XT2CLK 0
10 /1/2/4/8
1
11 MCLK
XT2OFF
XT2IN Main System Clock
XT
VCC
Modulator
DCOR SCG0 RSELx DCOx
SELS DIVSx
SCG1
off n
0 DC 0 DCOCLK
DCO 0 Divider
1 Generator 1 0
n+1 /1/2/4/8
1
P2.5/Rosc 1
SMCLK
ÎÎÎÎÎÎÎ
1
f DCOCLK
ÎÎÎÎÎÎÎ
Max
f DCO_7
Frequency Variance
Min
f DCO_0
Max
Min
ÎÎÎÎÎÎÎ
ÎÎÎÎÎÎÎ
0 1 2 3 4 5 6 7 DCO
2.2 3 VCC − V
7 6 5 4 3 2 1 0
DCOx MODx
DCOx Bits DCO frequency select. These bits select which of the eight discrete DCO
7-5 frequencies of the RSELx setting is selected.
MODx Bits Modulator selection. These bits define how often the fDCO+1 frequency is
4-0 used within a period of 32 DCOCLK cycles. During the remaining clock
cycles (32−MOD) the fDCO frequency is used. Not useable when DCOx=7.
7 6 5 4 3 2 1 0
XT2OFF Bit 7 XT2 off. This bit turns off the XT2 oscillator
0 XT2 is on
1 XT2 is off if it is not used for MCLK or SMCLK.
XTS Bit 6 LFXT1 mode select.
0 Low frequency mode
1 High frequency mode
DIVAx Bits Divider for ACLK
5-4 00 /1
01 /2
10 /4
11 /8
XT5V Bit 3 Unused. XT5V should always be reset.
RSELx Bits Resistor Select. The internal resistor is selected in eight different steps.
2-0 The value of the resistor defines the nominal frequency. The lowest
nominal frequency is selected by setting RSELx=0.
7 6 5 4 3 2 1 0
SELMx Bits Select MCLK. These bits select the MCLK source.
7-6 00 DCOCLK
01 DCOCLK
10 XT2CLK when XT2 oscillator present on-chip. LFXT1CLK when XT2
oscillator not present on-chip.
11 LFXT1CLK
DIVMx BitS Divider for MCLK
5-4 00 /1
01 /2
10 /4
11 /8
SELS Bit 3 Select SMCLK. This bit selects the SMCLK source.
0 DCOCLK
1 XT2CLK when XT2 oscillator present on-chip. LFXT1CLK when XT2
oscillator not present on-chip.
DIVSx BitS Divider for SMCLK
2-1 00 /1
01 /2
10 /4
11 /8
DCOR Bit 0 DCO resistor select
0 Internal resistor
1 External resistor
7 6 5 4 3 2 1 0
OFIE
rw−0
Bits These bits may be used by other modules. See device-specific datasheet.
7-2
OFIE Bit 1 Oscillator fault interrupt enable. This bit enables the OFIFG interrupt.
Because other bits in IE1 may be used for other modules, it is recommended
to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B
or CLR.B instructions.
0 Interrupt not enabled
1 Interrupt enabled
Bits 0 This bit may be used by other modules. See device-specific datasheet.
7 6 5 4 3 2 1 0
OFIFG
rw−1
Bits These bits may be used by other modules. See device-specific datasheet.
7-2
OFIFG Bit 1 Oscillator fault interrupt flag. Because other bits in IFG1 may be used for other
modules, it is recommended to set or clear this bit using BIS.B or BIC.B
instructions, rather than MOV.B or CLR.B instructions.
0 No interrupt pending
1 Interrupt pending
Bits 0 This bit may be used by other modules. See device-specific datasheet.
Comparator 2
CCI
EQU2
CAP
A
SCCI Y
EN 0
Set TACCR2
1 CCIFG
OUT
Output
Unit2 D Set Q OUT2 Signal
EQU0
Timer Clock
Reset
POR
OUTMODx
Timer_A 11-3
Timer_A Operation
Continuous Mode
In the continuous mode, the timer repeatedly counts up to 0FFFFh and restarts
from zero as shown in Figure 11−4. The capture/compare register TACCR0
works the same way as the other capture/compare registers.
0FFFFh
0h
The TAIFG interrupt flag is set when the timer counts from 0FFFFh to zero.
Figure 11−5 shows the flag set cycle.
Timer Clock
Set TAIFG
Timer_A 11-7
Timer_A Operation
Output Modes
The output modes are defined by the OUTMODx bits and are described in
Table 11−2. The OUTx signal is changed with the rising edge of the timer clock
for all modes except mode 0. Output modes 2, 3, 6, and 7 are not useful for
output unit 0 because EQUx = EQU0.
Timer_A 11-13
Timer_A Operation
The OUTx signal is changed when the timer reaches the TACCRx and
TACCR0 values, depending on the output mode. An example is shown in
Figure 11−13 using TACCR0 and TACCR1.
0FFFFh
TACCR0
Quando o TAR retornar a zero,
TACCR1
uma INT será gerada. Forçar as
saídas TA0, TA1 e TA2 para nível
0h
zero dentro da RTI.
Output Mode 1: Set
Timer_A 11-15