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


Results 1 to 3 of 3

Threaded View

  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

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 : 0

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