TOGGLE will not go LOW


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Adding these 2 lines should allow you to drive the pin.

    ADCON1=15 'Set all A/D pins digital
    CMCON=7 'Turn off comparators
    Shawn

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    If you look at section 19.5 of the datasheet for the 18F4620 you'll find this:
    When reading the Port register, all pins configured as analog input channels will read as cleared (a low level). Pins configured as digital inputs will convert as analog inputs. Analog levels on a digitally configured input will be accurately converted.
    So if you do a TOGGLE on a pin which has NOT be set to digital it will read '0', the bit will then flipped to '1' and written back to the port. Next time you do that TOGGLE it will again read the bit as '0' (even though it was previously set to '1'), flip that bit to '1' and write it to the port. Ie. it will never toggle it low because every time its told to toggle the bit it's read as low and gets toggled to high.

    Page 224 in the same datasheet shows how to set ADCON1 up in order to configure the various pins as either analog or digital. And then there's the compartor as have been pointed out, see page 234. However for the 18F4620 the comparators are OFF by default so you strictly speaking you don't need to turn them off again. ALWAYS make a habit of checking IF you need to turn comparators off and/or enable digital mode on the pins you're using and HOW to do that - not all chips are the same.

    /Henrik.

  3. #3
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Yes, thanks all, Henrik is correct.


    I can drive the pin low. I was losing confidence when TOGGLE did not blink. I just did not think about the need of TOGGLE to read the state of an analog pin to blink an LED.


    The Olimex board came with LED hardwired to PORTA.0 I am doing ADC on 6 other A/E ports (replacing cadmium sulfide photoresistors with more durable phototransistors in eyes of solar dish trackers) (also replacing expensive pulse/I2C tilt accelerometers with cheaper analogs).


    I can make the LED blink by adding 1 to a tracking bit and not use TOGGLE in this instance. I doubt the need for an LED on solar dish PC boards. PORTA.0 will be liberated. Thanks again -- Doug.


    P.S. You can see progress -- Google -- matrix solar dish

  4. #4
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Just ran into this on a 18F4431 trying to get a heartbeat to work inside a ISR using DT-INTS:

    Code:
    '**** TMR0 Int Handler ******
    ToggleLED:
       HIGH PORTA.0
       PAUSEUS 100
       LOW PORTA.0
    @INT_RETURN
    ...Worked, while:
    Code:
    '**** TMR0 Int Handler ******
    ToggleLED:
       TOGGLE PORTA.0
    @INT_RETURN
    Did not.
    Thanks for posting this. I don't know if I would have figured it out on my own.
    Bo

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Did you happen to try LATA.0 vs PORTA.0 ?

    Like this
    Code:
    '**** TMR0 Int Handler ******
    ToggleLED:
       TOGGLE LATA.0
    @INT_RETURN

  6. #6
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Just tried it. Works wonderfully.
    One benefit of "HIGH, PAUSEUS, LOW" way is that I can only get brief flash, which is nicer to look at for a heartbeat, but the other side of that, is that with the "TOGGLE LATx", you can save some time in the ISR by eliminating the pause.

    Thanks for the heads up.
    Mark

Similar Threads

  1. Super low cost USB solution
    By Jumper in forum General
    Replies: 2
    Last Post: - 18th January 2013, 12:21
  2. high/low of 14 numbers
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th December 2012, 10:43
  3. LCD Low Power
    By kduck63 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th December 2012, 01:05
  4. PCB low volume production
    By sales5 in forum Adverts
    Replies: 0
    Last Post: - 29th November 2012, 04:43
  5. Replies: 3
    Last Post: - 25th November 2012, 21:26

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