Découvrez notre Chaîne YouTube "Ingénierie et Projets"
Découvrez notre Chaîne Secondaire "Information Neuronale et l'Ingénierie du Cerveau"

Source de tension numérique (DAC) avec PIC16F887

Objectifs

  • Savoir l’utilité d’un convertisseur Numérique Analogique (DAC)
  • Connaitre les caractéristiques du DAC0808
  • Savoir réaliser une source de tension numérique
  • Savoir utiliser un LCD avec MikroC
  • Connaitre les caractéristiques du LCD LM016L 16×2
  • Savoir utiliser quelques fonctions de conversions de types
  • Comprendre le fonctionnement d’un amplificateur de transimpédance
  • Et autres astuces pratiques

Applications

  • Source de tension précise
  • Générateur des signaux
  • Asservissement des moteurs

Fonctionnement  partie matérielle

Principe

L’objectif du projet est de concevoir une source de tension numérique précise dont la tension peut varier entre 0 et une valeur maximale. Nous disposons de deux boutons poussoirs permettant d’incrémenter ou décrémenter la tension de sortie d’un pas ajustable dans le programme. Le convertisseur numérique-analogique est l’élément essentiel dans notre montage. Il sert à convertir une valeur numérique sur 8 bits à une grandeur analogique (courant ou tension). La valeur de la tension de sortie sera ensuite affichée dans l’afficheur LCD en format flottant.

Convertisseur N/A DAC

Le DAC0808 est un convertisseur numérique analogique (DAC) monolithique de 8 bits offrant un temps de stabilisation du courant de sortie à pleine échelle de 150 ns en ne dissipant que 33 mW avec des alimentations de ± 5V. Aucun ajustement du courant de référence (IREF) n’est requis pour la plupart des applications puisque le courant de sortie à pleine échelle est typiquement ± 1LSB de 255= IREF / 256. La précision est de l’ordre de ± 0,19% assurent une bonne linéarité sur 8 bits pour IREF≥2 mA. Le courant d’alimentation du Le DAC0808 est indépendant du mot binaire, il présente des caractéristiques essentiellement constantes sur toute la plage de tension. De plus, le DAC0808 s’interface directement avec les protocoles TTL, DTL ou Niveaux logiques CMOS et remplace directement le MC1508 / MC1408 pour les applications à plus grande vitesse. Ci-dessous les caractéristiques essentielles du DAC :

  • Résolution binaire : 8 bits
  • Erreur de linéarité maximale de ± 0,19%
  • Correspondance du courant en pleine échelle: ± 1 type LSB
  • Temps de réponse : 150 ns typique (6.66 MHz)
  • Compatible avec les entrées numériques: TTL et CMOS
  • Vitesse de balayage d’entrée multiplicatrice à grande vitesse (Slew Rate): 8 mA / µs
  • Gamme de tension d’alimentation: ± 4,5V à ± 18V
  • Faible consommation d’énergie: 33 mW @ ± 5V
  • Plus de détails: Datasheet DAC0808

Comment calculer le courant de sortie du DAC ?

comment calculer le courant de sortie

On considère le montage ci-dessous (voir la page 8 du datasheet) utilisé par le constructeur pour faire ses tests. Le courant de sortie I0 d’après l’équation dépend de la tension de référence Vref fixée par l’utilisateur et la résistance R14 et l’état des bits d’entrées A1 (poids fort) à A8 (poids faible). Par conséquent la valeur LSB (la valeur la plus que peut prendre le courant I0) est égale au courant I0 lorsque le bit A8 est égal à « 1 ». On considère une tension Vref=10V, R14=5k. Alors le courant I0_LSB=(10/5000)*(1/256)= 7.8125E-6A=7.8125µA. Cette valeur nous sera intégrer dans le programme afin de calculer le courant I0 quelque soit l’état des bits A1-A8.

La résistance liée à la broche 15 permets de compenser en température le courant de polarisation, elle n’est pas nécessaire pour la plupart des applications.

Amplificateur de trans-impédance

Un amplificateur de trans-impédance est un convertisseur courant (I)/ tension (Vout). Il est constitué d’un amplificateur AOP et une résistance R (voir le montage ci-dessous). Le courant parcouru par la résistance R est égal au courant à l’entrée I. On a :

V(-)=Vout+R*I, V(+)=V(-)=0 ==> Vout=-RI

Amplificateur de trans-impédance

Le courant de sortie du convertisseur DAC I0=I14 (voir le datasheet) a un sens opposé à celui de l’amplificateur à transimpédance. Alors Vout=-(-RI)=RI. Par conséquent, la tension de sortie Vout est positive ou nulle en fonction de l’état des bits A1-A8.

Comment valider le fonctionnement du DAC ?

Il est important de faire correspondre les résultats théoriques et ceux de la simulation. En effet, on a besoin de vérifier si le courant LSB correspond parfaitement à la valeur obtenue par le calcul théorique I0_LSB=.7.8125µA. La méthode consiste à positionner le bit A8 à « 1 », et à 0 les autres bits : A1-A7= « 0000000 » puis utiliser la résistance R5 d’une valeur égale à 1 Ohm (Vout=R5*I0=I0). Ci-dessous le résultat de simulation :

Simulation calculer le courant de sortie

Le  résultat de simulation correspond parfaitement à la valeur calculée du courant I0_LSB (A8=1)

Alors: Vout=R5*I0

Valeur maximale: MSB

MSB Source de tension

 

Afficheur LCD 12×2 LM016L (Caractéristiques)

Les écrans à cristaux liquides à base de caractères ils sont couramment utilisés. Ils sont basés sur le contrôleur HD44780 d’Hitachi ou autres, compatibles avec le HD44580. Nous abordons dans la suite les différents pins de l’afficheur, de son interface avec le microcontrôleur PIC18F887 en utilisant la commande 4 bits par l’intermédiaire d’un ensemble des fonctions MikroC. Le LM016L est constitué de deux lignes (1) et (2), chaque ligne est peut contenir 16 caractères (numérotation : 1-16). Lire la suite Datasheet LM016L.

LCD LM016L 1

Pin No. Name Description
Pin no. 1 VSS Masse alimentation (GND)
Pin no. 2 VCC Alimentation (+5V)
Pin no. 3 VEE Ajustement de la contraste
RS 0 = Entrée instruction
1 = Entrée données
Pin no. 5 R/W 0 = Ecrire sur LCD
1 = Lire l’afficheur LCD
Pin no. 6 EN Signal d’activation
Pin no. 7 D0 Donnée ligne  0 (LSB)
Pin no. 8 D1 Donnée ligne 1
Pin no. 9 D2 Donnée ligne 2
Pin no. 10 D3 Donnée ligne 3
Pin no. 11 D4 Donnée ligne 4
Pin no. 12 D5 Donnée ligne 5
Pin no. 13 D6 Donnée ligne 6
Pin no. 14 D7 Donnée ligne 7 (MSB)

La tension VEE permet d’ajuster le contraste du LCD. On peut utiliser un potentiomètre branché avec une alimentation 5V afin de régler l’éclairage de l’afficheur. Pour des raisons de simplification, nous avons branché le pin VEE avec une alimentation 5V fixe.

Afficheur LCD 12×2 LM016L (Fonctions de contrôle)

Le mikroC PRO for PIC fournit une bibliothèque pour la communication avec les écrans à cristaux liquides via l’interface 4 bits (D4-D7. Un exemple de connexions LCD est donné dans le schéma de principe illustré au début du projet. Le logiciel MikroC dispose de six fonctions et un ensemble de variables internes pour la manipulation de ‘afficheur LCD.

Lcd_Init()

Initialisation de l’écran LCD. La fonction ne dispose pas des variables d’entrées ou des sorties. Elle nécessite la déclaration des variables des données et des directions avant son utilisation.

// Exemple:

// Lcd pinout
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
...

Lcd_Init();

Lcd_Out()

Syntaxe: void Lcd_Out(char row, char column, char *text);
  • row: Numéro de ligne (1 ou 2 dans notre cas, la valeur peut être importante lorsqu’on utilise un LCD 4×16, …)
  • column: Numéro de la colonne dont on souhaite commencer. La valeur peut varier entre 1 et 16.
  • *text: Pointeur du tableau des caractères.
// Déclaration 
char txt1[] = "Bonjour";
char txt2[] = "Electronique";

// Affichage
Lcd_Out(1, 1, txt1); // Première ligne, première colonne
Lcd_Out(2, 1, txt2); // Deuxième ligne, première colonne
Lcd_Out(1, 3, "Hello"; ); // Première ligne, troisième colonne

Lcd_Out_Cp()

Afficher le texte dans la position actuelle du curseur.

Syntaxe : void Lcd_Out_Cp(char *text);

Exemple: Lcd_Out_Cp("Here!");

Lcd_Chr()

Affichage d’un seul caractère dans une position (ligne, colonne) dans l’afficheur LCD.

Syntaxe : void Lcd_Chr(char row, char column, char out_char);

// Exemple:
Lcd_Chr(2, 3, 'A');
  • Row: Ligne
  • Column: Colonne
  • out_char: Caractère unique (pas une chaîne de caractères! )

Lcd_Chr_Cp()

Afficher un caractère das la position actuelle du curseur.

Syntaxe: void Lcd_Chr_Cp(char out_char);
Exemple : Lcd_Chr_Cp('e');

Lcd_Cmd()

Envoyer une commande prédéfinie à l’afficheur LCD. Ci-dessous une liste exhaustive des commandes (voir MikroC LCD pour plus de détails)

Syntaxe: void Lcd_Cmd(char out_char);
Lcd Command Purpose
_LCD_FIRST_ROW Move cursor to the 1st row
_LCD_SECOND_ROW Move cursor to the 2nd row
_LCD_THIRD_ROW Move cursor to the 3rd row
_LCD_FOURTH_ROW Move cursor to the 4th row
_LCD_CLEAR Clear display
_LCD_RETURN_HOME Return cursor to home position, returns a shifted display to its original position. Display data RAM is unaffected.
_LCD_CURSOR_OFF Turn off cursor
_LCD_UNDERLINE_ON Underline cursor on
_LCD_BLINK_CURSOR_ON Blink cursor on
_LCD_MOVE_CURSOR_LEFT Move cursor left without changing display data RAM
_LCD_MOVE_CURSOR_RIGHT Move cursor right without changing display data RAM
_LCD_TURN_ON Turn Lcd display on
_LCD_TURN_OFF Turn Lcd display off
_LCD_SHIFT_LEFT Shift display left without changing display data RAM
_LCD_SHIFT_RIGHT Shift display right without changing display data RAM

Comment convertir un entier en chaîne de caractères ?

Syntaxe : unsigned char FloatToStr(float fnum, unsigned char *str);

 

Paramètres de l’entrée: La fonction a besoin de deux paramètres

  • Fnum: La valeur flottante
  • Str: Chaîne de caractères (str doit être déclaré comme tableau ou pointeur)

Paramètre de sortie: La fonction renvoie une valeur en format unsigned char qui peut prendre l’un des quatre valeurs suivantes :

  • 3 si l’entrée est NaN
  • 2 if si l’entrée est -INF
  • 1 si l’entrée est +INF
  • 0 if Conversion réussie
// Exemple

float Volt=4.50 ;

unsigned char VoltStr[10] ;



FloatToStr(Volt, VoltStr);

Comment calculer la tension en fonction des états des entrées A1-A8 ?

Le programme à besoin de trois paramètres pour effectuer le calcul de la tension de sortie : La valeur de la résistance R5 en Ohm, la valeur courant LSB  I0_LSB en ampère calculée d’avance (voir le début du projet) et la valeur du DAC. Ci-dessous les lignes de code qui le permet :

// Paramètres de la Tension de sortie

const float Res_5=5000;

const float Courant_LSB=7.8125E-6;

float Tension=0.0;


// Valeur du DAC

unsigned short  DAC_val=1;



// Conversion Int ==> Float

DAC_fval=(float)DAC_val;


// Calcul de la Tension de sortie

Tension=DAC_fval*Res_5*Courant_LSB;

Note : La valeur du DAC est initialisée à « 1 ». Elle sera mise à jour lorsqu’on appuie sur l’un des boutons poussoirs (V+ : Incrémentation de la valeur, V- : Décrémentation). .

Programme MikroC

#include <built_in.h>

unsigned short DAC_val=1;
unsigned short DAC_step=1;
float DAC_fval=0.0;

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

char txt1[] = "Tension (V): ";
char txt2[16];

// Tension de sortie
const float Res_5=5000;
const float Courant_LSB=7.8125E-6;
float Tension=0.0;

void main()
{
// Configure AN pins as digital
ANSEL = 0;
ANSELH = 0;

// Port A en entrée
TRISA=0xFF;

// Configuration en sortie des ports
TRISB=0;
TRISC=0;
TRISD=0;
TRISE=0;

// Initialisation LCD
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row


// Lecture et affichage de la donnée ADC
while(1)
{
// Lecture des entrées & Mise à jour DAC
if (Button(&PORTA, 0, 1, 1))
{
// Mise à jour de valeur du DAC
DAC_val=DAC_val+DAC_step;

// Affectation de la valeur
PORTD=DAC_val;

// Effacer LCD
Lcd_Cmd(_LCD_CLEAR);

// Tempo
Delay_ms(200);
}
if (Button(&PORTA, 1, 1, 1))
{
DAC_val=DAC_val-DAC_step;
PORTD=DAC_val;
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(200);
}

// Conversion Int ==> Float
DAC_fval=(float)DAC_val;

// Calcul de la Tension de sortie
Tension=DAC_fval*Res_5*Courant_LSB;

// Conversion Float ==> String
FloatToStr(Tension,txt2);

// Affichage
Lcd_Out(1,2,txt1);
Lcd_Out(2,2,txt2);
}
}

Téléchargment

Retour à l’accueil MikroC

Le blog contient des publicités, elles permettent de financer l'hébergement et maintenir le blog en fonctionnement. Vous pouvez utiliser adblock pour une lecture sans publicités.
We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
Cookies settings
Accept
Decline
Privacy & Cookie policy
Privacy & Cookies policy
Cookie name Active

Privacy Policy

What information do we collect?

We collect information from you when you register on our site or place an order. When ordering or registering on our site, as appropriate, you may be asked to enter your: name, e-mail address or mailing address.

What do we use your information for?

Any of the information we collect from you may be used in one of the following ways: To personalize your experience (your information helps us to better respond to your individual needs) To improve our website (we continually strive to improve our website offerings based on the information and feedback we receive from you) To improve customer service (your information helps us to more effectively respond to your customer service requests and support needs) To process transactions Your information, whether public or private, will not be sold, exchanged, transferred, or given to any other company for any reason whatsoever, without your consent, other than for the express purpose of delivering the purchased product or service requested. To administer a contest, promotion, survey or other site feature To send periodic emails The email address you provide for order processing, will only be used to send you information and updates pertaining to your order.

How do we protect your information?

We implement a variety of security measures to maintain the safety of your personal information when you place an order or enter, submit, or access your personal information. We offer the use of a secure server. All supplied sensitive/credit information is transmitted via Secure Socket Layer (SSL) technology and then encrypted into our Payment gateway providers database only to be accessible by those authorized with special access rights to such systems, and are required to?keep the information confidential. After a transaction, your private information (credit cards, social security numbers, financials, etc.) will not be kept on file for more than 60 days.

Do we use cookies?

Yes (Cookies are small files that a site or its service provider transfers to your computers hard drive through your Web browser (if you allow) that enables the sites or service providers systems to recognize your browser and capture and remember certain information We use cookies to help us remember and process the items in your shopping cart, understand and save your preferences for future visits, keep track of advertisements and compile aggregate data about site traffic and site interaction so that we can offer better site experiences and tools in the future. We may contract with third-party service providers to assist us in better understanding our site visitors. These service providers are not permitted to use the information collected on our behalf except to help us conduct and improve our business. If you prefer, you can choose to have your computer warn you each time a cookie is being sent, or you can choose to turn off all cookies via your browser settings. Like most websites, if you turn your cookies off, some of our services may not function properly. However, you can still place orders by contacting customer service. Google Analytics We use Google Analytics on our sites for anonymous reporting of site usage and for advertising on the site. If you would like to opt-out of Google Analytics monitoring your behaviour on our sites please use this link (https://tools.google.com/dlpage/gaoptout/)

Do we disclose any information to outside parties?

We do not sell, trade, or otherwise transfer to outside parties your personally identifiable information. This does not include trusted third parties who assist us in operating our website, conducting our business, or servicing you, so long as those parties agree to keep this information confidential. We may also release your information when we believe release is appropriate to comply with the law, enforce our site policies, or protect ours or others rights, property, or safety. However, non-personally identifiable visitor information may be provided to other parties for marketing, advertising, or other uses.

Registration

The minimum information we need to register you is your name, email address and a password. We will ask you more questions for different services, including sales promotions. Unless we say otherwise, you have to answer all the registration questions. We may also ask some other, voluntary questions during registration for certain services (for example, professional networks) so we can gain a clearer understanding of who you are. This also allows us to personalise services for you. To assist us in our marketing, in addition to the data that you provide to us if you register, we may also obtain data from trusted third parties to help us understand what you might be interested in. This ‘profiling’ information is produced from a variety of sources, including publicly available data (such as the electoral roll) or from sources such as surveys and polls where you have given your permission for your data to be shared. You can choose not to have such data shared with the Guardian from these sources by logging into your account and changing the settings in the privacy section. After you have registered, and with your permission, we may send you emails we think may interest you. Newsletters may be personalised based on what you have been reading on theguardian.com. At any time you can decide not to receive these emails and will be able to ‘unsubscribe’. Logging in using social networking credentials If you log-in to our sites using a Facebook log-in, you are granting permission to Facebook to share your user details with us. This will include your name, email address, date of birth and location which will then be used to form a Guardian identity. You can also use your picture from Facebook as part of your profile. This will also allow us and Facebook to share your, networks, user ID and any other information you choose to share according to your Facebook account settings. If you remove the Guardian app from your Facebook settings, we will no longer have access to this information. If you log-in to our sites using a Google log-in, you grant permission to Google to share your user details with us. This will include your name, email address, date of birth, sex and location which we will then use to form a Guardian identity. You may use your picture from Google as part of your profile. This also allows us to share your networks, user ID and any other information you choose to share according to your Google account settings. If you remove the Guardian from your Google settings, we will no longer have access to this information. If you log-in to our sites using a twitter log-in, we receive your avatar (the small picture that appears next to your tweets) and twitter username.

Children’s Online Privacy Protection Act Compliance

We are in compliance with the requirements of COPPA (Childrens Online Privacy Protection Act), we do not collect any information from anyone under 13 years of age. Our website, products and services are all directed to people who are at least 13 years old or older.

Updating your personal information

We offer a ‘My details’ page (also known as Dashboard), where you can update your personal information at any time, and change your marketing preferences. You can get to this page from most pages on the site – simply click on the ‘My details’ link at the top of the screen when you are signed in.

Online Privacy Policy Only

This online privacy policy applies only to information collected through our website and not to information collected offline.

Your Consent

By using our site, you consent to our privacy policy.

Changes to our Privacy Policy

If we decide to change our privacy policy, we will post those changes on this page.
Save settings
Cookies settings

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

FPGA | Arduino | Matlab | Cours will use the information you provide on this form to be in touch with you and to provide updates and marketing.