6- Analog to Digital Converter | mikroC Pro for PIC Tutorial

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 166

  • @luisarriondo3191
    @luisarriondo3191 6 років тому +2

    Hello,when I measure voltages less than 1v I have a problem. The values in the LCD never are less than 1v.For example, if I have in the analog input 0,45V I have on the LCD 4,5V.Do you have any idea why this happens?Thanks.great tutorial.

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      Hi. I think there is some bug in the FloatToStr() function. Try to ask in mikroC forum (" forum.mikroe.com/ ") many people have complained about it. Use sprintf() function to convert float to string instead of the FloatToStr() function. So replace FloatToStr(mV, txt); with sprintf(txt, "%2.2f", mV);
      But please note sprintf() doesn't work with PIC16F series, use it with PIC18F series.
      Let us know if it works.

    • @luisarriondo3191
      @luisarriondo3191 6 років тому +1

      very well!! Thanks you.I thinks that the problem is the 0 to left. The compiler depreciate that 0 and then when show the 4 characters move the string one site to left and don't show the 0.

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      Possibly. Did you try to use sprintf() function?

    • @luisarriondo3191
      @luisarriondo3191 6 років тому +1

      No, because I am using a PIC16F877A. But I going to prove anyway and tell you what happens.
      Thanks for yours answers.
      B.r

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      You are welcome!

  • @studentcompanionsastudentc4850
    @studentcompanionsastudentc4850 9 років тому +3

    We appreciate all your feedback guys. Thanks

  • @quincymlangane37
    @quincymlangane37 7 років тому +1

    wow i really love this series, it has been a great help. thank you Student Companion. keep up the good work!!!!

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Quincy mlangane thank you for watching our videos. We appreciate your feedback.

  • @ashishpaikrao4210
    @ashishpaikrao4210 5 років тому +1

    Thanks sir, Im very happy with your teaching, Thank one's again..!!!

  • @StudentCompanion
    @StudentCompanion  9 років тому +4

    More at: www.studentcompanion.co.za/analog-to-digital-converter-with-pic-microcontroller-mikroc/

  • @bamokinamoandadestin7888
    @bamokinamoandadestin7888 5 років тому +1

    why do you declare voltageText [15] instead of voltageText[5] since 4.04 has for caracters + the{\0}. Thanks for your help!

    • @StudentCompanion
      @StudentCompanion  5 років тому +2

      The decimal point could have been more than that even though we limited it to 2 digit in this example. Yes voltageText[5] could do the job in this case.

    • @bamokinamoandadestin7888
      @bamokinamoandadestin7888 5 років тому

      @@StudentCompanion ok, I will try it.

  • @orimusic9707
    @orimusic9707 3 роки тому +1

    great tutorial, the library says that "This function doesn't work with the external voltage reference source, only with the internal voltage reference. "
    in your adc input section consider that i use 3.3v source instead of 5, i will get a better resolution so will it be good?
    Thanks

    • @StudentCompanion
      @StudentCompanion  3 роки тому +1

      Is your PIC running at 3.3V?

    • @orimusic9707
      @orimusic9707 3 роки тому +1

      @@StudentCompanion no at its at 5v , so for me what is happening is the current sensor gives outputs in uA so i thought better resolution would be better

    • @StudentCompanion
      @StudentCompanion  3 роки тому +2

      You can't use 3.3V while your PIC is running at 5V because that library doesn't work with external reference. You can use the ADC by accessing directly the SFR registers of your PIC. Read your datasheet to learn how to do it:
      download.mikroe.com/documents/compilers/mikroc/pic/help/predefined_globals_and_constants.htm

    • @orimusic9707
      @orimusic9707 3 роки тому +1

      @@StudentCompanion ok will do thanks👍🏿

    • @StudentCompanion
      @StudentCompanion  3 роки тому +1

      You are welcome!

  • @RazibShahadat
    @RazibShahadat 5 років тому +1

    Sir, I am trying to read ADC value using the pic 16f72 and 16f73 but it not working. Can you help me please?

    • @StudentCompanion
      @StudentCompanion  5 років тому +1

      Hi. How can anyone help when you are too broad with your question? The problem could be code or hardware or both. You are not saying exactly what is not working. Whether your code is not compiling or no value is received or wrong values. Be specific and you might get assistance.

    • @RazibShahadat
      @RazibShahadat 5 років тому +1

      @@StudentCompanion Thanks for your replying. when I am using pic 18f452 or 16f877 microcontroller, I can read ADC value which showing my LCD display. But when I am trying to read ADC value using the pic 16f72 and 16f73, it did not return any ADC value. I am using mikroc for pic adc library for reading the ADC value.

    • @StudentCompanion
      @StudentCompanion  5 років тому

      @@RazibShahadat can you post the code you are using to read with pic16f72?

    • @RazibShahadat
      @RazibShahadat 5 років тому +1

      @@StudentCompanion // LCD module connections
      sbit LCD_RS at RB5_bit;
      sbit LCD_EN at RB4_bit;
      sbit LCD_D4 at RB3_bit;
      sbit LCD_D5 at RB2_bit;
      sbit LCD_D6 at RB1_bit;
      sbit LCD_D7 at RB0_bit;
      sbit LCD_RS_Direction at TRISB5_bit;
      sbit LCD_EN_Direction at TRISB4_bit;
      sbit LCD_D4_Direction at TRISB3_bit;
      sbit LCD_D5_Direction at TRISB2_bit;
      sbit LCD_D6_Direction at TRISB1_bit;
      sbit LCD_D7_Direction at TRISB0_bit;
      // End LCD module connections
      unsigned int ADCResult= 0;
      char adcTxt[15];
      void main() {
      TRISB = 0; // Configure PORTB pins as digital
      TRISA = 1; // Configure PORTA pins as input
      TRISA1_bit = 1; // Configure RA1 pin as input
      ADC_Init(); // Initialize ADC
      Lcd_Init(); // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR); // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
      Lcd_Out(1, 8, "ADC");
      do {
      ADCResult = ADC_Read(1); // Get 8-bit results of AD conversion
      IntToStr(ADCResult, adcTxt); // Convert voltage to string
      Lcd_Out(2,1,"adcValue: "); // Write string "Voltage: "in first row
      Lcd_Out(2,10, adcTxt); // Write voltage in second row
      Delay_ms(100);
      } while(1);
      }

    • @StudentCompanion
      @StudentCompanion  5 років тому +1

      @@RazibShahadat Are you connecting the analog sensor/potentiometer on RA1? The only other thing that could be wrong is your configuration bits if you did not set them properly. In Edit project, make sure the oscillator selection is set correctly, correct oscillator frequency and those other bits are set correctly.

  • @ronaldfombe8195
    @ronaldfombe8195 7 років тому +1

    Great tutorials! The best I've seen so far. Please keep it up.
    I have two questions:
    1. Why did you add the line "voltageTxt [4]=0;"
    2. How do you know that your voltageTxt string is supposed to have a length of 15?

    • @StudentCompanion
      @StudentCompanion  7 років тому +2

      Thank you for watching our tutorials and for your feedback. much appreciated.
      1. We just wanted to display our value to 2 digits decimal point, the 3rd digit if any should be 0 and ignored. Two digits before decimal points and two after decimal points (= 4 characters array)
      2. According to FloatToStr function conversion requirement, the Destination string should be at least 14 characters in length.
      You can learn more at: download.mikroe.com/documents/compilers/mikroc/pic/help/conversions_library.htm#floattostr

    • @ronaldfombe8195
      @ronaldfombe8195 7 років тому +1

      Thank you for your prompt response! Definitely subscribing to your channel.

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Ronald Fombe Thank you.

  • @Orprime
    @Orprime 6 років тому +1

    How can I use the ADC_Get_sample to get 230 AC volt as my final result displayed on my LCD. Also, how can also use the above coder to get current value of 230 AC volt displayed on my LCD. I don't know what next to do after that point. Thanks

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      Hi. A PIC can only work with DC voltages from 0 to 5V. You must find a way to step down your 240 AC volt and rectify it to DC. This low voltage can be ready then you can multiply the read value with the step down factor to get the full voltage value.

    • @Orprime
      @Orprime 6 років тому +1

      Thanks for your reply. I used Transformer to step down 230 volt to 12 volt, then used rectifier to convert the 12dc volt to pulsating dc and finally with capacitors and 7805 IC, to get 5volt dc as output. The major issue I am having is which of the step down factor should I use to multiply the reading ADC. Is it the capacitor values or others. my capacitor values are 2200uf and 0.1uf. my transformer step down values in henry (Primary = 1H, seconday = 0.00137H. the rest remains same in proteus.

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      When you step down a voltage from 220v to 12v, by how much did you step it down? That's the simplest question you can ask. Read the comments on this thread to learn more: www.microchip.com/forums/m/tm.aspx?m=76012&p=1

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      For accurate measurement a transformer will not always give you the correct accurate values because the input voltage is not always stable. Microchip application notes describes energy measurement in details. You can search those application notes.

    • @ElectronicsMadeEasy
      @ElectronicsMadeEasy 6 років тому +1

      U cn use rsistor network to stepdown the vtg.

  • @jamescullins2709
    @jamescullins2709 7 років тому +1

    Question Have programmed the new PIC18F26K40 chips. I have the EasyPIC v7 board. I can't get the ADCC or the Euart to work. Would be helpful for a video on this chip. MPLAB wouldn't do it either. Thanks my friend.

    • @StudentCompanion
      @StudentCompanion  7 років тому +2

      +James Cullins Are you sure you are setting correctly all the jumper switches of EasyPIC v7 board to use this PIC? The EasyPIC can program many different types of PIC in different package sizes and I think the default is set to use the 40 pin package. So check if your package (28 pin) us selected correctly

    • @jamescullins2709
      @jamescullins2709 7 років тому +1

      yes have gone over settings .i/o work just not the ADC & USART

    • @jamescullins2709
      @jamescullins2709 7 років тому +1

      I had analog and uart working on a different chip. The pic18f26K40 is a different beast. I have something not set up right in the regs I think.

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +James Cullins They must be something you are not setting up correctly. Can you post your ADC code?

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Student Companion and EUART code?

  • @paulotutse5084
    @paulotutse5084 7 років тому +1

    Wow! awesome presentation, plus thanks for ur selection of topics. can u add keypad interfacing with an lcd?

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Paulo Tutse thank you for watching our videos and for your feedback. We will upload a keypad tutorial soon. At the moment you can watch this video part 1 and part 2 it has a keypad and lcd: ua-cam.com/video/s6GXfBZRoRM/v-deo.html

    • @StudentCompanion
      @StudentCompanion  7 років тому +2

      +Paulo Tutse this is part 2: ua-cam.com/video/m7wCqsdbas0/v-deo.html

    • @paulotutse5084
      @paulotutse5084 7 років тому +1

      thanks a lot students companion. but i keep getting an error when i type ANSELE & TRISE1_bit. saying Undeclared identifier, could u please help me fix it

    • @StudentCompanion
      @StudentCompanion  7 років тому +2

      Which PIC microcontroller are you using?

    • @paulotutse5084
      @paulotutse5084 7 років тому +1

      pic18f45k22. and when i use ANSELA & TRISA1_bit it is not showing any error

  • @sakibhasan9077
    @sakibhasan9077 6 років тому

    thanks a lot for this tutorial.

  • @marcodomingo6763
    @marcodomingo6763 8 років тому +1

    Hi love your videos. I ran the simulation but the LCD display is wrong when the voltage is less than 1V. For example if the voltage is 0.95V it will display 9.5V, i think it's just an error on how the float is formatted for the LCD. Could you give insight on this. Thanks!

    • @StudentCompanion
      @StudentCompanion  8 років тому +1

      +Marco Domingo Hi. is this error observed in simulation or in hardware?

    • @marcodomingo6763
      @marcodomingo6763 8 років тому +1

      Hi the error is in the proteus simulation. The value is still correct if you think about it it's just the decimal that is wrong. It doesn't output 0.0V to 0.99V

    • @StudentCompanion
      @StudentCompanion  8 років тому +1

      +Marco Domingo ok. Let us go through thaf code again. We're gonna let you know the problem. Thanks

    • @marcodomingo6763
      @marcodomingo6763 8 років тому +1

      Thanks for the quick response i really appreciate it and i'm learning a lot from your videos!

    • @StudentCompanion
      @StudentCompanion  8 років тому +1

      Thanks

  • @luisarriondo3191
    @luisarriondo3191 6 років тому +1

    The comments are in Spanish! because I'm from Uruguay.// PROGRAMA PARA USAR MODULO DE CONVERSION A/D
    //PIC 16F877A
    // ENTRADA ANALOGICA PIN RE0 - PIN 8 - AN5
    // LCD PUERTO B// Lcd pinout settings
    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;// Pin 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;float valor_AN5; // valor_AN5 sera saber el voltaje analogico en an5
    // float para que mida valores con coma
    float voltage; // float para tener valores con coma
    int VOL;
    char voltageTXT[15]; // dato tipo matriz o array para llevar el texto al LCD
    const short VREF = 5; // VREF es el voltaje de alimentacionvoid main()
    {
    CMCON = 0b111; // APAGHO COMPARADORES
    TRISB = 0x00; // PUERTO B COMO SALIDA. LCD
    TRISE = 0xFF; // PUERTO E ENTRADA
    ADCON1 = 0b0000; // PUERTOS ANO - AN7 SON ANALOGICOS
    ADCON0.CHS0 = 1; // CONFIGURO LA ENTRADA ANALOGICA QUE VOY A USAR, LA AN5
    ADCON0.CHS1 = 0;
    ADCON0.CHS2 = 1;
    ADCON0.ADCS0 = 0; // SELECCIONO CONVERSION CLOCK EN ESTE CASO fOSC/2
    ADCON0.ADCS1 = 0;
    ADCON1.ADCS2 = 0;
    ADCON0.ADON = 1; ADC_Init(); Lcd_Init(); Lcd_cmd(_LCD_CLEAR);
    Lcd_cmd(_LCD_CURSOR_OFF); Lcd_out(1,7, "ADC");
    while(1)
    { valor_AN5 = ADC_Get_Sample(5);
    VOL = (valor_AN5 / 1024)*500;
    if (VOL >= 100) {
    valor_AN5 = ADC_Get_Sample(5);
    voltage = (valor_AN5 / 1024)*VREF; //regla de 3 para saber a cuanto equivale en binario el valor en AN5
    FloatToStr(voltage, voltageTXT); // convertir valor voltage en string para el LCD
    voltageTXT[4]=0; // [4] cantidad de caracteres a mostrar
    Lcd_Out(2,1,"VOLTAGE:"); // escribir VOLTAJE:
    Lcd_Out(2,9,voltageTXT); //escribir el string con el vsalor de la regla de 3
    Lcd_Out(2,14, "V"); // escribo la unidad
    delay_ms(200);
    }
    else {
    valor_AN5 = ADC_Get_Sample(5);
    voltage = (valor_AN5 / 1024)*500; //regla de 3 para saber a cuanto equivale en binario el valor en AN5
    FloatToStr(voltage, voltageTXT); // convertir valor voltage en string para el LCD
    voltageTXT[2]=0; // [2] cantidad de caracteres a mostrar
    Lcd_Out(2,1,"VOLTAGE:0."); // escribir VOLTAJE:0.
    Lcd_Out(2,11,voltageTXT); //escribir el string con el vsalor de la regla de 3
    Lcd_Out(2,14, "V"); // escribo la unidad
    delay_ms(200);
    } } // end while}// end void main

    • @StudentCompanion
      @StudentCompanion  6 років тому +2

      No problem with the comments. Thank you very much!

  • @salmam5118
    @salmam5118 6 років тому +1

    salut j'ai un petit problemme pendant que la tension de potentiometre est inferieure a 1 il me donne sur lcd des nombre different que celui de potentiometre , c'est qoi le problemme??

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      Une autre personne a déjà posé la même question dans cette vidéo, veuillez lire les commentaires de Luis Arriondo. il y a une solution à votre question.

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      c'est pourquoi nous ne fournissons pas d'assistance dans les messages privés. les réponses précédentes peuvent aider les autres.

    • @salmam5118
      @salmam5118 6 років тому +1

      @@StudentCompanion j'ai lu le commentair de cet amis at sa solution q'il a trouvu mais j'ai pas bien compris tu peux me l'a traduire bien et explique moi bien si tu veux monsieur

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      Quel PIC tu utilise?

    • @salmam5118
      @salmam5118 6 років тому +1

      c'est ca le commentaire que j'ai pas compri bien explique moi bien s'il vous plait >>>>>>>> very well!! Thanks you.I thinks that the problem is the 0 to left. The compiler depreciate that 0 and then when show the 4 characters move the string one site to left and don't show the 0.

  • @ojieokogua4605
    @ojieokogua4605 4 роки тому

    Thanks for the video sir, following your video and using MikroC pro for pic vs 7.6.0,I declared " char voltageTxt[15]; to convert my voltage from adc channel 0 to float using PIC16F877a .When i compiled the code it gives me error 1511 IRP bit must be set manually for indirect access to ' voltageTxt' variable.How do I resolve this sir?

    • @StudentCompanion
      @StudentCompanion  4 роки тому +1

      You must post the full error message and your code so we can see what could be wrong. We can't determine without full info

  • @RazibShahadat
    @RazibShahadat 7 років тому +1

    have any serial monitor for pic microcontroller like arduino?

  • @victorandrespolo
    @victorandrespolo 6 років тому +1

    You are so fkng great, thank you so much!

    • @StudentCompanion
      @StudentCompanion  6 років тому +2

      You are welcome. Thanks for watching our videos and for your feedback.

  • @tota896
    @tota896 9 років тому +2

    Thanks.

  • @worldchannel6518
    @worldchannel6518 8 років тому +2

    Nice.

  • @deveshdangi7209
    @deveshdangi7209 7 років тому +2

    how to increase the accuracy of the output

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Devesh what do you mean by increasing accuracy? This PIC has 10 channels of 10-bit ADC. You can't get more than 10-bit unless you use a different PIC which has higher especially a dsPIC or a PIC32. Or you can use a specialized ADC chip.

    • @deveshdangi7209
      @deveshdangi7209 7 років тому +2

      see I am using lm35 and when i send a analog signal for eg 49.56 then on the LCD I get something 49.00 or 40.13 but not the accurate value

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Devesh what do you mean by 49.56? Is that a voltage? Because the LM35 doesn't produce such high voltage. You might be losing accuracy in your calculations. It's got nothing to do with the ADC resolution of the PIC.

    • @deveshdangi7209
      @deveshdangi7209 7 років тому +1

      its temprature control

    • @StudentCompanion
      @StudentCompanion  7 років тому +1

      +Devesh that's more with your floating point calculation when you are converting your ADC value to temperature i think.

  • @dsimiyu520
    @dsimiyu520 9 років тому +3

    this my choice always 24/7/360

  • @vaideshshankar9899
    @vaideshshankar9899 6 років тому +1

    in which library FloarToStr function in present??

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      Conversions ---> C_String. Read more here: download.mikroe.com/documents/compilers/mikroc/pic/help/conversions_library.htm

    • @vaideshshankar9899
      @vaideshshankar9899 6 років тому +1

      Student Companion i am unable to run digital thermometer program on microc as i am using a demo version.It is throwing me the "demo limit" error.Is there a way to get original version of microC...i m keen to learn these things..plz reply!

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      To get the professional version of mikroC you must buy it from Mikroelekronika: www.mikroe.com/mikroc

    • @vaideshshankar9899
      @vaideshshankar9899 6 років тому +1

      Student Companion can i get your email id?

    • @StudentCompanion
      @StudentCompanion  6 років тому +1

      We communicate with email only for private related stuff at info@studentcompanion.net
      But anything public related to tutorials we only engage publicly here on UA-cam or in the Forum on our website. We won't answer tutorial issues in email.

  • @smartcircuits7505
    @smartcircuits7505 5 років тому +1

    SHOWING WRONG RESULT WHEN ADC RESULT IS LESS THAN 1 (0.9 OR SOMETHING LIKE THAT)

    • @StudentCompanion
      @StudentCompanion  5 років тому

      Hi. We have discussed this same topic before. Please read the commments on this video. The top pinned comment.

  • @dsimiyu520
    @dsimiyu520 9 років тому +3

    this my choice always 24/7/360

    • @StudentCompanion
      @StudentCompanion  9 років тому +2

      thank you very much. We appreciate it.

    • @StudentCompanion
      @StudentCompanion  9 років тому +3

      what is your take so far to our new mikroC playlist? what kind of tutorials you'd like to watch in this playlist? Your feedback and of others will highly be appreciated. Thanks