ADC0808 conversion algorithm

Discussion in 'Programmer's Corner' started by FBorges22, May 27, 2009.

  1. FBorges22

    Thread Starter Active Member

    Sep 11, 2008
    104
    0
    Greetings,

    I am trying to use the ADC0808 with the 8051 microcontroller. But I am having a little trouble in the conversion of the device. Recently I programmed these functions to pulse the necessary pins of the device according to datasheet

    The code is below

    Code ( (Unknown Language)):
    1. void adc_convert()
    2. {
    3.     P2_0=0;
    4.     P2_1=0;
    5.     P2_2=0;
    6.     delay_small();
    7.     // Pulses the ALE and the START respectvely to starts the conversion...
    8.     P2_3=1;
    9.     delay_small();
    10.     P2_4=1;
    11.     delay_small();
    12.     // Disables the ALE and START...
    13.     P2_3=0;
    14.     delay_small();
    15.     P2_4=0;
    16. }
    17.  
    18. void send_portP1()
    19. {
    20.     xtod(P1);
    21.     SBUF=0x30+Hundreds_Cnt;
    22.     while(!TI);
    23.     TI=0;
    24.     SBUF=0x30+Tens_Cnt;
    25.     while(!TI);
    26.     TI=0;
    27.     SBUF=0x30+Ones_Cnt;
    28.     while(!TI);
    29.     TI=0;
    30.     SBUF=0x0A; // Sends the "\n"
    31.     while(!TI);
    32.     TI=0;
    33. }
    34.  
    35. void int0() interrupt 0
    36. {
    37.     P2_5=1; // Enables the OE
    38.     delay_small();
    39.     P2_5=0; // Disables the OE
    40.     while(IE0);
    41.     send_portP1();
    42.     REN=1;
    43.     P2=0x00;
    44. }
    Basically the P2 port is connected to the control lines of the ADC and the P1 port is connected to the data bus of the ADC. I tested this program in the HyperTerminal and the serial communications is ok but the ADC is still not converting...

    The enviroment of the experiment was in these conditions:

    12MHz of clock for the 8051 uC
    1MHz of clock for the ADC0808
     
  2. StayatHomeElectronics

    Well-Known Member

    Sep 25, 2008
    864
    40
    When you say that the ADC is not converting, do you mean that you never get the EOC, End of Conversion, interrupt?

    I am not up on my processor code so I may be wrong. It looks like you enable the OE, Output Enable, delay, and disable it again. Do you read it at all while it is enabled? It looks like you read it after it is disabled again.
     
  3. FBorges22

    Thread Starter Active Member

    Sep 11, 2008
    104
    0
    Yes, I am not getting the EOC interrupt.

    How I can fix this error?
     
  4. StayatHomeElectronics

    Well-Known Member

    Sep 25, 2008
    864
    40
    Do you have an oscilloscope so you can look at the EOC signal to see if it is actually doing anything?

    Is your interrupt set in the software to be a rising edge or a falling edge?

    Is your start timing correct? Does your 8051 produce a signal similar to that of the timing diagram? Can you verify on an oscilloscope? Can you post what the waveforms look like, clock, ALE, START, EOC?
     
  5. FBorges22

    Thread Starter Active Member

    Sep 11, 2008
    104
    0
    I will check in the oscilloscope and post the results soon enough... In the mean time to start the conversion in the ADC I need to pulse the ALE and the START pins respectively right?
     
  6. StayatHomeElectronics

    Well-Known Member

    Sep 25, 2008
    864
    40
    That is right.
     
  7. FBorges22

    Thread Starter Active Member

    Sep 11, 2008
    104
    0
    Ok,

    I pulsed the START and ALE pins but nothing happens when I try to read the data from the ADC when que uC receives the "b" character in the serial port.

    Recently I tried to bypass the INT0 pin using a switch and the interrupt was triggered and the state from the P1 port was sent and the value was 78... I was expecting 255 because nothing is connected in the ADC analog input.

    Here is a piece of the code from my program:

    Code ( (Unknown Language)):
    1.  
    2. void delay_small() _naked
    3. {
    4.     _asm
    5.         nop
    6.         ret
    7.     _endasm;
    8. }
    9. void adc_convert()
    10. {
    11.     P2_0=0;
    12.     P2_1=0;
    13.     P2_2=0;
    14.     delay_small();
    15.     // Pulses the ALE and START pins to start the conversion
    16.     P2_3=1;
    17.     delay_small();
    18.     P2_4=1;
    19.     delay_small();
    20.     // Lower the ALE and START...
    21.     P2_3=0;
    22.     delay_small();
    23.     P2_4=0;
    24. }
    25. void send_portP1()
    26. {
    27.     decimalConvert(P1);
    28.     SBUF=0x30+Hundreds_Cnt;
    29.     while(!TI);
    30.     TI=0;
    31.     SBUF=0x30+Tens_Cnt;
    32.     while(!TI);
    33.     TI=0;
    34.     SBUF=0x30+Ones_Cnt;
    35.     while(!TI);
    36.     TI=0;
    37.     SBUF=0x0A; // envia o caractere "\n"
    38.     while(!TI);
    39.     TI=0;
    40. }
    41. void int0() interrupt 0
    42. {
    43.     while(IE0);
    44.     delay_small();
    45.     P2_5=1; // Habilita o OE
    46.     delay_small();
    47.     send_portP1();
    48.     P2_5=0; // Desativa o OE
    49.     REN=1;
    50.     P2=0x00;
    51. }
    52. void receive_serial() interrupt 4 using 0
    53. {
    54.     while(!RI);
    55.     RI=0;
    56.     sbuffer=SBUF;
    57.     switch (sbuffer)
    58.     {
    59.         case 0x61: send_portP1(); break;
    60.         case 0x62: adc_convert(); break;
    61.         case 0x63: P2=0x00; break;
    62.         default: break;
    63.     }
    64. }
    What could be wrong? Why the ADC is not converting? Have anyone used this ADC with the 8051? Here is the clock waveforms...
     
Loading...