How do I read my ADC input only after the transition from a low to high occurs?


Closed Thread
Results 1 to 3 of 3
  1. #1
    jessey's Avatar
    jessey Guest

    Default How do I read my ADC input only after the transition from a low to high occurs?

    Hello Everyone,

    I have a CMOS circuit that forms a square wave oscillator with approximately a 10/90 mark-space ratio and I'd like to be able to read the high pulses using an ADC input on my 18f452. I only want to take my AD reading after the voltage has gone from low to high each time. I don't have any problems on how to set up the ADC but I just can't think of the best way to only read the highs and ignore the lows from the transition of a low to a high signal.

    I wrote some code below just off the top of my head but haven't tested it yet. Would this be a good approach to accomplishing this or is there a better way of approaching this? I'm not sure exactly what is the best way of doing this is. Maybe I should have some pauses in my While...Wend statement? The program will be running off Timer1 with a 32 KHz oscillator or I could switch it to the main oscillator while I'm reading the ADC.

    Prepare_To_Read_ADC_Input:
    WHILE a = 0 'A always equals 0
    IF Read_Pin = 0 THEN
    IF Read_Pin = 1 THEN Read_ADC_Input
    ENDIF
    WEND

    Read_ADC_Input:
    adcon1=%00000100
    TRISA.0 = 1 'input to read ADC value
    ADCON0 = $41 'Set A/D to Fosc/8, Channel 0, On
    Pauseus 50 ' Wait for channel to setup
    ADCON0.2 = 1 ' Start conversion
    Pauseus 50 ' Wait for conversion
    Moist = ADRESH
    ADCON1 = 7 'shut off (Disable) ADC
    Return

    Thanks
    jessey
    Last edited by jessey; - 17th February 2006 at 05:49. Reason: wanted to added some code to question

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Use an interrupt.

    Hi,

    I would recommend that you tie the square wave input to the INT pin and set the AD conversion bit as soon as an interrupt occurs. Also set a software flag so that your program knows that a new sample is available. You can call this routine or just poll the software flag to update your results. However you should also introduce some delay before setting the ADON bit to ensure proper acquisition.

    Regards

    Sougata

  3. #3
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default I take it that I'll be using the PORTB Interrupt-on-Change feature

    Thanks Sougata,

    I'll have to look into the manual more and try to absorb some of the information on how to do that. I've never used interrupts before so this will be a learning experience for me. After a quick look ay the manual, I take it I can connect my square wave output from the CMOS circuit to either pin INT0 (pin 33), INT1 (pin 34) or INT2 (pin 35).I guess I'll be using the PORTB Interrupt-on-Change feature.

    Anyways it's getting late here so I'll have another look tomorrow evening and see what I can come up with between the manual and the archives. When I get a better understanding of what I'll have to do to use the Interrupt-on-Change feature (which will probably take me a few days but will be time well spent) then I'll come back with some questions.

    Thanks Again
    jessey

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 06:28
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Fade out LEDs question
    By Sam in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd June 2008, 10:50
  4. Someone help me to simplify this
    By thrix in forum General
    Replies: 4
    Last Post: - 21st February 2004, 05:01
  5. Help wanted..
    By thrix in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th February 2004, 23:44

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