TOGGLE will not go LOW


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Quote Originally Posted by SUNFLOWER View Post
    I have been writing complicated code for years without any troubles. Now something simple will not compile correctly. TOGGLE will not toggle low but does toggle high. Everything else seems to work ok but I am worried about this instability -- Rebooting computer did not clear this issue. Ideas on what's going on here?

    DEFINE LOADER_USED 1 ' Bootloader space
    OSCCON = %01100000 ' Internal oscillator speed 4 MHz 18F4620

    MAINLOOP:

    ' LOW PORTA.0
    PAUSE 50
    TOGGLE PORTA.0
    PAUSE 50

    GOTO MAINLOOP
    Does the alternate "Low PORTA.0" work?
    Perhaps the pin cannot be driven low?

    Norm

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Thanks, I was not aware TOGGLE needs to read digital, so can not toggle while doing some ADC on higher ports of A.

    ADCON1 = %00001111 ' Make AN0-AN12 digital

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    I'm betting if you had a resistor pulling the pin low, say a 10k, you'd see it going low. I'm not familiar with the 18f4620 but on a 12f683 it needs some kind of load to pull the pin low. Don't have to be alot but something.

  5. #5
    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

  6. #6
    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.

  7. #7
    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

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