Sharp pulse on ADC input and NAP


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default Sharp pulse on ADC input and NAP

    Hi, I have a requirement as follows;

    Wait for response on an ADC input; the trigger signal expected is around 1 volt, width of 2 ms. The moment it arrives, output a 500 ms pulse on another pin. Kind of a pulse stretcher (was thinking of using a CMOS 555, but want to avoid components and make it flexible). Very weak power supply available, so maximum consumption to be limited to 40 uA or so.

    I tried this code, and it works perfect, except of course the consumption (no load) is around 800 uA.

    TEST:;NAP 0
    ADCIN 2, LEVEL
    IF LEVEL > 5 THEN
    DEBUG #LEVEL,13,10
    HIGH LED
    PAUSE 500
    LOW LED
    ENDIF
    GOTO TEST

    I snicked in a NAP 0 command, and it stops working; triggers once in a few events.

    The NAP 0 works fine if I manually feed a wider pulse to the input trigger and consumption drops to 30 uA), so I guess its the narrow pulse that doesnt like the NAP command. Since the input transition is way less than 5 volts, I am using the pin as an ADC input.

    So my question is, how can this be done best? I'd like to avoid using any extra passive components if I can.

    Thanks and Regards,

    Anand Dhuru

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Sharp pulse on ADC input and NAP

    I would use a wake on comparator interrupt or pin change with a permanent sleep instead
    @ SLEEP

    a PIC10F204/206 can wake from a comparator or any pin change, really cheap, would be a perfect choice. Would require only a few lines of code.
    http://ww1.microchip.com/downloads/e...Doc/41239D.pdf

    Is it mandatory to supply 5V to your PIC? What's the requirement for the Output pulse amplitude?
    Why i'm asking, refer to figure 13-2 and later.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Sharp pulse on ADC input and NAP

    Thanks for the fast response, Steve. Funny, I'm using a 12F675, but did think it was an overkill and a 10FXXX would be a fine fit.

    Also thought the @ SLEEP would be the answer, but I have to admit interrupts (specially the ADC triggerred ones), are not my Forte. Could you possibly point me in the right direction?

    Actually, the supply is 3.3, and the PIC merely needs to pull down an external pin thats held high (also at 3.3) with a very weak pull-up.

    For those interested, this is a wired remote for DSLRs that uses a smartphone as a triggering device with s/w thats available free (for Androids for sure, dont know about other platforms)

    Regards,

    Anand Dhuru

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: Sharp pulse on ADC input and NAP

    I have not tested this since I don't have a 12F675, but something like this should work. You might need to tweak the internal CVref settings.

    Hook your sensor output to GPIO.1 Vin-. When your sensor outputs 1V (or anything > CVref) it should wake-up from sleep.

    If you don't have PBP3 just get rid of the config line, and use what you have.

    Code:
    #CONFIG
      __config  _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF
    #ENDCONFIG
     
    DEFINE OSCCAL_1K 1 ' load internal osc calibration value
     
    LED VAR GPIO.2      ' LED output
    CmpFlag VAR PIR1.3  ' alias comparator interrupt flag bit
    CoutBit VAR CMCON.6 ' CMCON.6 is set while voltage on Vin- > CVref
     
    ANSEL = 0          ' disable A/D
    GPIO = 0           ' LED off on POR
    TRISIO = %00000010 ' GPIO.1 = input for Vin- comparator, rest outputs
    VRCON = %10100111  ' internal CVref enabled, low range.
                       ' CVref = (VR3:VR0 / 24) * VDD.
                       ' with (VR3:VR0) = 7 we have (7/24) * 3.3V
                       ' so internal CVref = 0.9625V
                       ' a voltage > 0.962V on Vin- (GPIO.1) will set COUT,
                       ' set the comparator interrupt flag, and wake us up.
    CMCON = %00010100  ' Comparator w/o Output and with Internal Reference
     
    PIR1 = 0           ' clear flags before enabling comparator int
    PIE1 = %00001000   ' comparator interrupt enabled.
    INTCON = %01000000 ' enable peripheral interrupts for comparator
                       ' global interrupts disabled, so there's no jump to
                       ' an interrupt vector. We're just waking-up from sleep.
     
    TEST:
      WHILE CoutBit    ' wait for COUT to clear. This clears when the voltage on
      WEND             ' Vin- falls below the internal CVref
      CmpFlag = 0      ' clear comparator interrupt flag bit before entering sleep
      @ SLEEP          ' should sleep until comparator trips
      HIGH LED
      PAUSE 500
      LOW LED
      GOTO TEST
      end
    Last edited by Bruce; - 13th August 2011 at 16:53.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Sharp pulse on ADC input and NAP

    Bingo, Bruce! My mistake, the trigger amplitude is more like 0.5 volts, so I just edited the VRCON bits and it works like a charm. But, I measure around 200 uA in standby now. Still a HUGE improvement over my earlier 800 uA, but with the NAP I was getting a draw of about 30 uA. Am I doing something wrong?

    All above readings are on my breadboard at 5 volts, while testing. When its finalized the circuit will work on 3.3 volts, so I guess the consumption would be reduced significantly.

    Regards,

    Anand
    Last edited by ardhuru; - 14th August 2011 at 16:01.

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Sharp pulse on ADC input and NAP

    I have a 12LF1822 running at about 8-10ua in Sleep (the PIC 'LF' variants consume signifiantly less power in sleep, so considering moving over to a PIC that can be had in LF variant. Also, as you point out, the lower the voltage the better)

    It's imperative before putting the PIC to sleep, to get all your IO pins & PIC peripherals in the right 'state' to consume the least power while sleeping - I find the best way is studying the associated ciruit it interfaces with, then a massive amount of trial & error while checking the current draw on my DVM! (ie switch off all the uneeded PIC internal peripherals, IO pin TRIS states have the most impact along with pins being set up as analague or not...whilst there are rules of thumb - http://ww1.microchip.com/downloads/e...hapter%202.pdf - I've found the results in the real world to be somewhat random!)

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