sexta-feira, 27 de maio de 2011

Projeto das portas do microcontrolador

  Retomando nossa discussão do post anterior, tomaremos rumo na definição da função de cada pino do microcontrolador MSP430F2013. Lembrando que temos como periféricos botões, lcd, timer externo e sensor de temperatura. Portanto para os botões, lcd e timer teremos de usar portas I/O e para o sensor uma porta analógica. Analisando a configuração de portas obtemos:

Pino

       Função


1
Vcc



2
I/O
(+ A/D in)


3
I/O
(± A/D in)


4
I/O
(± A/D in)


5
I/O
(- A/D in)


6
I/O
(+ A/D in)


7
I/O
(- A/D in)
Serial

8
I/O
(+ A/D in)
Serial

9
I/O
(- A/D in)
Serial

10
Reset



11
JTAG



12
I/O


CLKout
13
I/O


CLKin
14
GND





Portanto temos 10 portas I/O sendo 8 analógicas e 3 seriais, essa grande quantidade de portas analógicas torna o MSP um micro bem flexível, além de barato, podendo ser empregado em inúmeros projetos com diferentes periféricos a serem controlados, as portas seriais multiplicam mais ainda sua capacidade. Por isso é um microcontrolador largamente usado na indústria eletrônica.


O lcd que usaremos é um modelo padrão de 2x16 com 16 portas.


               








- Retirado de: http://www.lcd-module.de/eng/pdf/doma/dip162-de.pdf
Então os pinos 1 e 5 são aterrados, o 2 vai na alimentação, o 3 é o ajuste de contraste conectando a um potenciômetro, os pinos 4 e de 6 a 10 são dados estes vão no micro. Como você pode perceber estamos trabalhando com a metade dos pinos de dados, apenas 4 bits, ajuste necessário para que o micro comporte todos periféricos.
O timer que iremos trabalhar é um HT1380 com um cristal de 33KHz, este usará 3 portas do MSP, para poupar portas estas serão as seriais.


Uma porta analógica será dedicada a uma entrada do sensor de temperatura LM35. Assim das 10 portas disponíveis do MSP 6 estão ligadas ao lcd, 3 do timer estão em paralelo com 3 do lcd, e 1 está ligada ao sensor, restando-nos 3 portas livres das 10. Essas portas serão conectadas a 3 botões que irão ajustar o relógio.
Enfim todas as portas do micro estão ocupadas com seus respectivos dispositivos, agora devemos pensar como estes serão conectados, mas isso é assunto para um outro post.

sexta-feira, 20 de maio de 2011

Hardware design for the MSP430F2013 microcontroller

This week we'll start talking about hardware, as promised.

To start our electronic design we think about what resources we have available, what we want to do and we can really do. First we analyze the main part of the project, the microcontroller. This line belongs to the low power of Texas Instruments, which is also the cheapest line, a thousand units of the computer cost U$ 1.35, being the economic line the number of these ports and functions are also scarce.

What we have in mind is to make maximum use of all features supported by only 14 micro-door, causing him to communicate with buttons, LCD display and analog signal devices. Based on these components you can use the ports I / O to send and receive data, the ability to use serial communication on the available ports, analog signal reception doors with A / D converter. 

A characteristic that can be noted are the two main roads, instead of one.In these the CPU sends and receives data from the Flash memory and RAM, A / D Converter, Watchdog Timer, SPI interface, I / O ports and the unique JTAG Interface (essential mechanism for the "debug" of embedded systems) due to two-way protocol (Spy-Bi-Wire). It is also an internal clock associated with the CPU, in addition, there is a protection against "brownout" (undervoltage).


So we have the most resources available in project economically cheap to obtain a final product that can be the basis for production to the market. A product of high consumption, low cost and with a fair level of associated electronics would be a watch, it has buttons, LCD display, temperature sensor and external timer, so we have to build a viable device.


 Thus, in the coming weeks we will be studying and designing our watch, bye.

sexta-feira, 13 de maio de 2011

Projeto de hardware para o microcontrolador MSP430F2013

 Olá caros seguidores, nessa semana começaremos a falar de hardware, como prometido.
 Para iniciar o nosso projeto eletrônico devemos pensar no que temos disponível de recursos, o que queremos fazer e o que realmente podemos fazer. Primeiramente analisaremos a peça principal do projeto, o microcontrolador. Este pertence à linha de baixa energia da Texas Instruments, que também é a linha mais barata, mil unidades do micro custam U$1.35, sendo a linha econômica o número de portas e as funções destas também são escassas.
 O que temos em mente é fazer o uso máximo de todos os recursos suportados pelo micro de apenas 14 portas, fazendo-o comunicar com botões, display LCD e dispositivos de sinal analógico. Tendo como base esses componentes é possível usar as portas de I/O para envio e recepção de dados, utilizar o recurso de comunicação serial nas portas disponíveis, a recepção de sinal analógico em portas com conversor A/D.



Uma particularidade que é possível notar-se é as duas vias principais, ao invés de uma. Nestas a CPU envia e recebe dados da memória Flash e RAM, Conversor A/D, Watchdog, Timer, Interface SPI, portas I/O e a exclusiva Interface JTAG (mecanismo essencial para o “debug” de sistemas embarcados) de duas vias devido ao protocolo (Spy-Bi-Wire). Encontra-se também um Clock interno associado à CPU, além disso, há uma proteção contra “Brownout” (subtensão).



 Portanto teremos o máximo de recursos disponíveis em projeto economicamente barato, visando obter um produto final que possa ser base para a produção ao mercado. Um produto de alto consumo, baixo custo, e com um nível razoável de componentes eletrônicos associados seria um relógio, este possui botões, visor LCD, sensor de temperatura e timer externo, com isso temos um engenho viável para construir.
 Assim, nas próximas semanas estaremos estudando e projetando o nosso relógio, até lá.

sexta-feira, 6 de maio de 2011

Creating a Workspace and debugging your program

In the last post we teach how to create a library to run Morse code in the LED, in this one we will show how to use the workbench to create a desktop and debug the program.
Libraries "CodigoMorse.c" and "CodigoMorse.h" already for download.
 
Create a folder to put the files in any location of "Users", as it is created (C: \ programfiles) the Workbech will always need to be run  as administrator for Windows Vista and 7.
Add this to the libraries folder "inc" found in (C: \ Program Files (x86) \ IAR Systems \ Embedded Workbench 6.0 Kickstart \ 430), and create another folder named "projects".
Put the two libraries ready in the "inc."

Now open the Workbench and go to (File New → File).
Enter your code "main", which can also be found for download:

#include "msp430.h"
#include "CodigoMorse.h"

int main(void)
{
      unsigned char i;
      WDTCTL = WDTPW + WDTHOLD;    // Interrompe o watchdog
      P1DIR |= 0x01;                            // Seta P1 como saida
      for (;;)                                         // Inicia loop infinito
      {
           CodigoMorse('S');
           CodigoMorse('O');
           CodigoMorse('S');
           P1OUT = 0x00;     //Termina a mensagem e aguarda antes de reiniciar
          for(i=0;i<10;i++)
         {
              TempoEntreLetras();
         }
      }
}

Save this file in the "inc" named "MainMorce.c."
After all processes completed, the includes tree looks like this:

The principal libraries of the MSP430 are basic to the main program and all of our libraries that we create, so do not forget to include them.
Now you have everything you need to create a worspace and download the program for the microcontroller.

Let's start by creating and configuring the desktop:
Go (File → New → Workspace), and then (Project → Create New Project).
In the window that opens select "Empty Project" and press "OK".
A new window will open, save with the name "CodigoMorse.ewp" in the "projects".
Go (Project → Options → Options → General Device), select (→ Family MSP430x2xx MSP430F2013)
Finally in (Project → Options → Debugger → Driver), make sure it is selected "FET Debugger" and not "Simulator"

Now your workspace is ready to receive the files:
Click the right mouse button in the left window with the name "Workspace" and then (Add → Add Files).
Add the two ".c" previously created (CodigoMorse.ce MainMorse.c).
Go (File → Save Workspace), and save your desktop with the name "CodigoMorse.eww", not forgetting to be saved in the "projects".

Before running the download you must make sure that no files have errors:
Go (Project → Rebuild All). You should see the following window:


As the Workspace has no errors, the project will be compiling to the microprocessor.
Note also that the entire  includes tree was automatically included.


Go (Project → Download and Debug).
If your computer can not communicate with the microprocessor, probably the board is not been recognized, see the post about installation.
If the communication does not fail the project will be downloaded and Workspace will change.
 
Now you will learn how to use the buttons that control the microprocessor, and can even help you "debug" the program.
From left to right:

1.       
    
1. Reset: resets the project is running.
2. Break: stop the  project, will be inoperable unless the project is being executed.
3. Step Over: Executes the current line of code, and goes to the next.
4. Step Into: Executes the next step of the code. For example, in a for (i = 0; i <5; i + +): if i = 3  is the next step increment i, but without leaving the for.
5. Step Out: ends the steps of the current line. In the previous case is going to be finished directly.
6. Next Statement: Go to the next command line the main program.
7. Run to Cursor: run the program to the line indicated by the cursor. The indicated line will not run.
8. Go: get to run the project.
9. Stop Debugging: Stops the debugging and back to the desktop before.

But, the buttons only work that way if there are functions, if the code does not provide functions, then the button 6 will function the same as 4.
 
It is also useful to use the window "watch", go to (View → Watch).
Now you can select any variable of the code and drag it to that window so you can follow their changing values ​​and thus better understand what is happening.
Now that you know how to use the buttons you can see the SOS step by step, or all at once,  
enjoy!
 
Finally, after two weeks you finally saw the long awaited SOS, but now with all the information you already have and the complete library, you can write whatever you want, you can modify the routines of time, to create functions to perform phrases, etc.

Well, I guess for now is that, send us your questions through the comments, we will try to fix them up, if they need help with workbench, look in your datasheet.

Thanks and until next week when we start talking about the hardware!