A/D conversion problem with 18F2455


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Angry A/D conversion problem with 18F2455

    Hi everybody. I am now working on 18F2455 because of its USB feature. But I got some troubles with converting.I use 4MHz crystal/resonator. I apply a sinusoidal signal with the amplitude 2,5 or 5 volts and a frequency 2kHz from function generator to PORTA.0. And want an output from PORTA.1. But it behaves strange. The negative parts of this sinusoidal is cut off. It only receives the positive parts. I monitored this event on the scobe. And guess what I got as an output. It is 5V DC. It doesn't change. Today I will try it one more time. Does anyone have any suggestions?
    What am I doing wrong?

  2. #2
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abdy37 View Post
    The negative parts of this sinusoidal is cut off. It only receives the positive parts.
    You need to offset it. For example, if peak to peak is 5V then you need to reference the center to 2.5V. This is effectively your 0V rail when compared to actual AC. AC isn't AC unless it swings below the 0V rail.

  3. #3
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16


    Did you find this post helpful? Yes | No

    Exclamation

    Quote Originally Posted by T.Jackson View Post
    You need to offset it. For example, if peak to peak is 5V then you need to reference the center to 2.5V. This is effectively your 0V rail when compared to actual AC. AC isn't AC unless it swings below the 0V rail.
    Hi T.Jackson. I will try it out tomorrow. I think it is caused by configuring the VREF+ and VREF-. I configured them as VREF+=Vdd and VREF-=Vss. So I think this why the negative sinusoidals are truncated. But in spite of this I think the A/D module must work. I don't have a chance to change the offset voltage to 2,5 volts as you offered. But I think can figure this out with VREF+=AN2 and VREF-=AN3 by pulling AN2 to +2,5 volt and AN3 to -2,5 volt.
    Here is the code I used:

    W0 VAR WORD

    TRISA.0 = 1 ' Set pin 0 of PORTA an input

    TRISA.1 = 0 ' Set pin 1 of PORTA an output

    PORTA.1 = 0 ' Clear pin 1 of PORTA

    ADCON0 = %00000001 ' Configuring Analog Channel Select bits, A/D

    ' Conversion Status bit, A/D On bit

    ADCON1 = %00001110 ' Configuring Voltage Reference Configuration bits,

    ' A/D Port Configuration Control bits

    ADCON2 = %10010000 ' Configuring A/D Result Format Select bit (Right justified ),

    ' A/D Acquisition Time Select bits (4 TAD), A/D Conversion

    DEFINE OSC 4

    DEFINE ADC_BITS 10

    DEFINE ADC_CLOCK 1

    DEFINE ADC_SAMPLEUS 11

    Conversion:

    ADCON0.1 = 1 ' Set GO/(DONE)' bit. Wait the Automatic Acquisition Time and Start Conversion

    PAUSEUS 50

    IF ADCON0.1 = 0 THEN ADC_BIT_RECEIVING

    IF ADCON0.1 = 1 THEN Conversion

    ADC_BIT_RECEIVING:

    ADCIN 0,W0

    W0.0 = PORTA.1

    PAUSEUS 10

    W0.1 = PORTA.1

    PAUSEUS 10

    W0.2 = PORTA.1

    PAUSEUS 10

    W0.3 = PORTA.1

    PAUSEUS 10

    W0.4 = PORTA.1

    PAUSEUS 10

    W0.5 = PORTA.1

    PAUSEUS 10

    W0.6 = PORTA.1

    PAUSEUS 10

    W0.7 = PORTA.1

    PAUSEUS 10

    W0.8 = PORTA.1

    PAUSEUS 10

    W0.9 = PORTA.1

    END
    Don't worry be happy....

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abdy37 View Post
    But I think can figure this out with VREF+=AN2 and VREF-=AN3 by pulling AN2 to +2,5 volt and AN3 to -2,5 volt.
    Good luck with that AN3 theory and hopefully you've got a couple of extra 18F2455's laying around.
    Reference the 18F2455 datasheet, Section 28.0 and Table 28-28, Parameter A22.

  5. #5
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    Suggest some good reading material on OPAMPS - Operational Amplifiers. You need to vertically shift up that sine wave so that 0v is actually 2.5v

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    w0 var word:trisa.0=1:trisa.1=0:porta.1=0:adcon0=1:adcon1=14:adcon2=$90
    DEFINE OSC 4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 1
    DEFINE ADC_SAMPLEUS 11
    Conversion:
    ADCON0.1 = 1:PAUSEUS 50 :IF ADCON0.1 = 0 THEN ADC_BIT_RECEIVING
    IF ADCON0.1 = 1 THEN Conversion                        
    ADC_BIT_RECEIVING:
    adcin 0,w0:w0.0=porta.1:pausus 10:w0.1=porta.1:pausus 10:w0.2=porta.1:pausus 10
    w0.3=porta.1:pausus 10:w0.4=porta.1:pausus 10:wo.5=porta.1:pausus 10
    w0.6=porta.1:pausus 10:w0.7=porta.1:pausus 10:w0.8=porta.1:pauseus 10
    w0.9=porta.1
    END
    What is this program supposed to do anyways?
    Might help if we saw the whole thing...

  7. #7
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16


    Did you find this post helpful? Yes | No

    Question No subject

    Hi Skimask. Thank you for concerning with my problem. Now I am working on a little project or the beginning of a big project. I will explain it shortly.
    I am applying a sinusoidal signal with the offset voltage of 2,5 volts and an amplitude of 5 volts to PORTA.0 . Its frequency is 1khz. So, it varies between (0~5) volts. I want a digital output coming from PORTA.1 . But however, so far
    I get 5V(DC) from PORTA.1 . By the way, I use 10 bit ADC and the converted
    digital values I want to get serially every time when the conversion is over.
    The detail is as follows: When the GO/DONE bit is set, the ADC starts. It gathers
    the 10 bit sampled value and writes it into ADRESH(highest 2 bits) and ADRESL(least 8 bits). I did not use it. I used ADCIN 0,W0 which reads the values
    from PORTA.0 and writes to W0. After that, if you look at the code you can see that I am trying to get those values with delay(PAUSEUS). I am using 18F2455
    and could not find much relating A/D Conversion with it. Maybe you have some suggestions. Because you know it is nothing but the beginnig of the project
    and you can not come over the problem. It makes me really crazy. I need working ADC.
    Don't worry be happy....

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abdy37 View Post
    I am applying a sinusoidal signal with the offset voltage of 2,5 volts and an amplitude of 5 volts to PORTA.0
    1st problem - A/D inputs on a PIC don't work with negative voltages. See Post #4.

    Its frequency is 1khz. So, it varies between (0~5) volts. I want a digital output coming from PORTA.1
    Do you mean you want to output, on A.1, a serial output representation of the analog input on A.0?

    But however, so far I get 5V(DC) from PORTA.1
    That's good because I don't see anything in your program that says to change the output on PortA.1 other than it's initial setup.

    By the way, I use 10 bit ADC and the converted digital values I want to get serially every time when the conversion is over.
    And again, I don't see any serial output commands.

    I used ADCIN 0,W0 which reads the values from PORTA.0 and writes to W0. After that, if you look at the code you can see that I am trying to get those values with delay(PAUSEUS).
    And again, how do you plan to see this output? Serial output? LCD? There aren't any in the program.

    I am using 18F2455 and could not find much relating A/D Conversion with it.
    You're kidding me right? Section 21 of the 18F2455 has no information in it that you can use?

    I need working ADC.
    You've got a working ADC, what you need to do is to get it to work FOR you. I think what you need to do is play around with the PIC and PBP first. Get an LCD working, get a pushbutton or something working with it...then, hook up a POT across an A/D input pin, then display the value of the POT, doesn't have to be resistance, doesn't have to be voltage, doesn't have to be anything in particular, just display a number that corresponds with the position of the POT as you turn it. Then when you get that working, you can easily work on reading a sine wave.

    And besides, even though the A/D on a '2455 is rated for 100ksps and the PIC can run at 48Mhz, you won't be able to get any useful DSP out it. Not enough horsepower under the hood.
    Last edited by skimask; - 6th May 2007 at 19:03.

  9. #9
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by skimask View Post
    1st problem - A/D inputs on a PIC don't work with negative voltages. See Post #4.

    I do not use negative voltage. It varies from 0v to 5v. Sine waves' center
    or offset voltage is 2,5 volts above 0v.

    Do you mean you want to output, on A.1, a serial output representation of the analog input on A.0?

    I want to use A.1 as output and monitor it on the scobe. It consists of getting the sampled 10 bit values gathered from A.0 and transmitting out
    from A.1 bit by bit.(Serially). That is what I mean serially.


    That's good because I don't see anything in your program that says to change the output on PortA.1 other than it's initial setup.

    Why is that so? As far as I know TRISA.1=0 configures that pin as output and not sets it to high from its initial value. So I do not see any problem there.

    And again, I don't see any serial output commands.

    Is it compulsory to use serial commands? Can't I monitor values on the scobe
    without the commands.

    And again, how do you plan to see this output? Serial output? LCD? There aren't any in the program.

    It is labeled with ADC_BIT_RECEIVING. I am planning to see that on the scobe. I think I could monitor that because after all there must be 0's too and not only 1's.

    You're kidding me right? Section 21 of the 18F2455 has no information in it that you can use?

    What section do you mean exactly? The section on the forum. I will be glad
    if there is some information concerning my question.

    You've got a working ADC, what you need to do is to get it to work FOR you. I think what you need to do is play around with the PIC and PBP first. Get an LCD working, get a pushbutton or something working with it...then, hook up a POT across an A/D input pin, then display the value of the POT, doesn't have to be resistance, doesn't have to be voltage, doesn't have to be anything in particular, just display a number that corresponds with the position of the POT as you turn it. Then when you get that working, you can easily work on reading a sine wave.

    Ok. I will try LCD and POT.

    And besides, even though the A/D on a '2455 is rated for 100ksps and the PIC can run at 48Mhz, you won't be able to get any useful DSP out it. Not enough horsepower under the hood.
    What did you mean exactly by "enough horsepower under the hood".
    Don't worry be happy....

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abdy37 View Post
    What did you mean exactly by "enough horsepower under the hood".
    Have you ever seen how much math is involved in doing most kinds of Digital Signal Processing?
    Do a search on DFT or FFT and you'll see what I mean.
    What exactly do you want the end result of this project of yours to do?

  11. #11
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16


    Did you find this post helpful? Yes | No

    Cool

    Quote Originally Posted by skimask View Post
    Have you ever seen how much math is involved in doing most kinds of Digital Signal Processing?
    Do a search on DFT or FFT and you'll see what I mean.
    What exactly do you want the end result of this project of yours to do?
    I do not have too much knowledge about FFT or DFT. I have been dealing with
    them just using MATLAB. There are ready commands such as fft(signal), so I do not know much of its details.
    My project is PIC to PC and PC to PIC communication. I mean FuLL Duplex channel between them. But to communicate with PC I must have digital values
    and not analog. That is why I want to use ADC feature of PIC 18F2455. I want to observe if I get those digital values from PORTA.1 bit by bit. This is exactly what I want to do.
    Don't worry be happy....

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abdy37 View Post
    My project is PIC to PC and PC to PIC communication. I mean FuLL Duplex channel between them. But to communicate with PC I must have digital values and not analog. That is why I want to use ADC feature of PIC 18F2455. I want to observe if I get those digital values from PORTA.1 bit by bit. This is exactly what I want to do.
    So what you're saying is that you want your PC to talk to your PIC, bidirectionally.
    What port do you want to use on the PC to do this? The speaker/microphone port?
    You know there's fully functional serial port on the PIC18F2455, as well as most others, that is easily used to communicate with a PC, with a little bit of extra hardware. See the PBP book for more details...

  13. #13
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    So what you're saying is that you want your PC to talk to your PIC, bidirectionally.
    What port do you want to use on the PC to do this? The speaker/microphone port?
    You know there's fully functional serial port on the PIC18F2455, as well as most others, that is easily used to communicate with a PC, with a little bit of extra hardware. See the PBP book for more details...
    I am looking forward to use USB communication for that. Because the main part of the project is USB.
    Don't worry be happy....

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abdy37 View Post
    I am looking forward to use USB communication for that. Because the main part of the project is USB.
    But why do you need to use the ADC of the PIC to talk to the PC?
    Do a search on 'USBDemo'

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2007, 23:03
  4. A/D conversion problem with pic16F88
    By Tapio Linkosalo in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th August 2006, 11:42
  5. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts