TOGGLE will not go LOW


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    60

    Default TOGGLE will not go LOW

    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

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

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

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

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

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

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    before you go too far down the wrong road read this thread about pbp and latx

    http://support.melabs.com/threads/99...using-lat-regs

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


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Thanks. of course Darrel would be the one to find something that obscure. Bet there's a story and some lost hours on that one.
    Mark

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    I have experienced this probably 50% of the time I have attempted to use toggle, High & Low commands and as such do not even attempt to use them.
    Is there a definite cause / effect or relationship to their failure to work and setting TRIS registers? Can anyone point to a paragraph in the manual?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    from the pbp3 manual for HIGH
    HIGH Pin
    Make the specified Pin high. Pin is automatically made an output. Pin may be a constant, 0-15, or a variable that contains a number 0-15 (e.g. B0) or a pin name (e.g. PORTA.0).
    HIGH 0 ' Make Pin0 an output and set it high (~5 volts)
    HIGH PORTA.0 ' Make PORTA, pin 0 an output and set it high (~5 volts)
    led Var PORTB.0 ' Define LED pin
    HIGH led ' Make LED pin an output and set it high (~5 volts)
    Alternatively, if the pin is already an output, a much quicker and shorter way (from a generated code standpoint) to set it high would be:
    PORTB.0 = 1 ' Set PORTB pin 0 high
    Since this command automatically sets the data-direction of the pin it acts on, the Pin parameter should only be a PORT or GPIO register (or an alias to a PORT or GPIO register). If the command is directed to act upon a LAT output or a bit within a variable or SFR, it will attempt to set a data-direction register that doesn't exist. The result may be unexpected behavior since a bit is changed in a seemingly random memory location. This can be very difficult to debug.
    its also mentioned for other commands
    Last edited by richard; - 9th August 2014 at 05:13. Reason: pbp3

  11. #11
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: TOGGLE will not go LOW

    Ok I did some testing and I found:
    1. High & Low worked without Tris or Ports set or analog settings set to digital
    2. Setting port to 1 and zero worked with Tris & Ports set without analog settings set to digital
    3. Toggle would not work without setting the analog stuff to digital, but when properly set it did.
    it otherwise would go high and stay high.

    Test chip 16F690 on Microchip demo board
    Interesting, Since Both posters are using portA in their examples I think some analog register is blocking it working.
    Which is what Mackrackit alluded to in post #3, I found it interesting it did not affect #2 in my test.
    HTH
    JS
    Last edited by Archangel; - 9th August 2014 at 07:40.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Super low cost USB solution
    By Jumper in forum General
    Replies: 2
    Last Post: - 18th January 2013, 11:21
  2. high/low of 14 numbers
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th December 2012, 09:43
  3. LCD Low Power
    By kduck63 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th December 2012, 00:05
  4. PCB low volume production
    By sales5 in forum Adverts
    Replies: 0
    Last Post: - 29th November 2012, 03:43
  5. Replies: 3
    Last Post: - 25th November 2012, 20: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