12f675 making me a crazy person


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52

    Default 12f675 making me a crazy person

    Hi folks,

    Here is some code. I am looking for some wisdom. It runs great. ONCE. It appears that the variable is either never counting to "300", or not getting reset to "10". The input causes the other output to go high, as it should, in a very repeatable manner.
    Ideas?
    Gary

    DEFINE OSC 4
    ANSEL=%00000000
    CMCON=7
    trisio = %00000100

    ' Chubb input gpio.5
    ' Output to panel - Trig var gpio.2
    ' Photo Guy gpio.4
    input gpio.5
    Chubb var gpio.5
    output gpio.4
    Led var gpio.4
    low led
    output gpio.2
    Trig var gpio.2
    low trig

    'Variable for the photo guy
    x var word
    x = 10

    ' Test the photo guy
    PAUSE 2000
    HIGH LED
    PAUSE 250
    LOW LED
    PAUSE 250
    HIGH LED
    PAUSE 250
    LOW LED
    PAUSE 2000

    'start here
    loop:
    if Chubb = 0 then
    high trig
    endif

    if Chubb = 0 then
    if X < 11 then
    X = 12
    gosub cola
    endif
    endif

    if chubb = 1 then
    low trig
    endif

    if x > 11 then
    x = (x + 1)
    endif

    if x >= 300 then
    x = 10
    endif

    if x = 100 then
    GOTO foto1
    endif

    pause 100
    goto loop
    end


    foto1:
    high led
    pause 100
    low led
    pause 250
    high led
    pause 100
    low led
    return
    goto loop

    cola:
    high led
    pause 100
    low led
    return
    goto loop
    end

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


    Did you find this post helpful? Yes | No

    Default

    You have RETURNs with GOTOs .
    Try going to the subroutines with GOSUB and then RETURN. Not both GOTO and RETURN.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Dave,

    There are two iterations of that, in a somewhat silly attempt to validate that the RETURN was working - or failing. No difference. Irrespective, they've been removed.
    The TRIG output goes high and low exactly as it should, when the CHUBB input goes high or low. That tells me the loop is looping. (Loopy?)
    After startup, the TWO led routines do work. ONCE.
    I can't see anything that is unhappy in the counting, the compiler likes it, and it seems to read ok, it just doesn't work.

    What the heck....

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


    Did you find this post helpful? Yes | No

    Default

    Hi Gary,
    try ADCON0 = 0
    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.

  5. #5
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Joe,

    No better.
    This is very very strange....

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE OSC 4
    ANSEL=%00000000
    CMCON=7
    trisio = %00000100
    
    ' Chubb input gpio.5
    ' Output to panel - Trig var gpio.2
    ' Photo Guy gpio.4
    input gpio.5
        Chubb var gpio.5
    output gpio.4
        Led var gpio.4
        low led
    output gpio.2
        Trig var gpio.2
        low trig
    
    'Variable for the photo guy
    x var word
        x = 10
        
    ' Test the photo guy
    PAUSE 2000
        HIGH LED
            PAUSE 250
        LOW LED
            PAUSE 250
        HIGH LED
            PAUSE 250
        LOW LED
    PAUSE 2000
    
    'start here
    loop:
        if Chubb = 0 then
            high trig
            if X < 11 then
                X = 12
                gosub cola
            endif
        else
            low trig
        endif
    
        if x > 11 then
            x = (x + 1)
        endif
    
        if x >= 300 then
            x = 10
        endif
    
        if x = 100 then
            GOTO foto1
        endif
    
    pause 100
    goto loop
    end
    
    
    foto1:
        high led
            pause 100
        low led
                pause 250
        high led
            pause 100
        low led
    goto loop
    
    cola:
        high led
            pause 100
        low led
    return
    end
    This should work

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


    Did you find this post helpful? Yes | No

    Default

    Something is strange.

    I just tried your code for giggles and this is what happened.
    Executing: "C:\PBP\PBPW.EXE" -ampasmwin -oq -z -p12F675 "C:\MAC\PIC PROGS\TEST\12f675.bas"
    PICBASIC PRO(TM) Compiler 2.50c, (c) 1998, 2008 microEngineering Labs, Inc.
    All Rights Reserved.

    ERROR: RAM END must be defined.
    ERROR: RAM BANKS must be defined.
    ERROR: No LIBRARY statement or LIBRARY parameter.
    ERROR: No LIBRARY statement or MACRO parameter.
    ERROR: Unable to open file PBPMAC.INCHalting build on first failure as requested.
    BUILD FAILED: Tue Sep 15 20:40:41 2009
    It is not your code, something else is the matter. A lot of folks seem to be having problems with this chip....
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Dave,

    That's interesting.....
    I tried with various settings in the config, watchdogs on and off, etc. I always use a 4k7 from MCLR to +5. That's just a "standard" here, and I always use the internal osc, and have never strayed far from 4mhz, so suffice to say that the config is pretty "plain".

    Most of the timing floats someplace around variations of 1000 so that an aprox count in seconds should tell me when things happen.

    The ONLY change here since the last functional chip is 4.31 software on the MELabs Programmer. And it's interesting that there's another thread nearby that the fellow is using the same programmer (although a much older code) and having "odd" issues.

    Once again I've shipped it over to MELabs with a request for help.

    Thanks to all who have responded. This kind of discussion is enlightening..

    Cheers
    Gary

  9. #9
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Jerson,

    The only change I see in your suggestion is an "else" for the Chubb. That part of the code is the only part that works repeatedly....

    There is something whacked in the way the counter stuff is getting either compiled or put to the chip, or interpreted by the chip. That part is going off into lala land.

    Gary

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Here is the V2.60 Answer :

    C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 63: Syntax error.
    C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 76: Syntax error.
    C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 83: Syntax error.
    C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 34: LOOP without a matching DO.Halting build on first failure as requested.
    BUILD FAILED: Wed Sep 16 09:47:12 2009
    Translated : Do not use " Loop " but "LoopA" ...

    No more error after changing " loop "



    Considering your program behaviour ...

    The IF THEN sequences looks highly Hazardous to me ...

    I'd recommend you to make it somewhat clearer ... but it's me !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Gary,

    Can you add the following lines to your code and compile it with the PM assembler like this
    C:\PBP\PBPW.EXE -apm -p12F675 "C:\MAC\PIC PROGS\TEST\12f675.bas

    Code:
    @ device  INTRC_OSC_NOCLKOUT, WDT_OFF
    @ device  MCLR_OFF, PWRT_ON
    @ device  CPD_ON, PROTECT_ON
    This will embed the configuration into the HEX file. The way you have it now, I have simulated the code and find it is incrementing and repeating after 300. If you want the code to block per trigger of Chubb, you need to add the following to your trigger code

    Code:
        if Chubb = 0 then
            high trig
            if X < 11 then
                X = 12
                gosub cola
                while Chubb : wend    ' wait while Chubb is 1
            endif
        else
            low trig
        endif
    Good luck

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Lightbulb

    Quote Originally Posted by Meriachee View Post
    Jerson,

    The only change I see in your suggestion is an "else" for the Chubb.

    Gary
    Not so sure ... you caught it !

    the "foto1" Label MUST end with a " GOTO " ...

    Lala land is the GOSUB result ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  13. #13
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Jerson,

    That won't work. The Chubb needs to be high or low irrespective of the Led.

    Alain,

    P&J, toast and jam, goSUB and return. Can't change one without the other. Code works like a charm. It may not be elegant, but I'm not charging myself very much for it either...

    Cheers
    Gary

  14. #14
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Try this for the PM assembler. If you hold Chubb high, foto1 will fire repeatedly. Release Chubb and trig will go low

    Enjoy

    Code:
    @ device  INTRC_OSC_NOCLKOUT, WDT_OFF
    @ device  MCLR_OFF, PWRT_ON
    @ device  CPD_ON, PROTECT_ON
    
    DEFINE OSC 4
    ANSEL=%00000000
    CMCON=7
    trisio = %00000100
    
    ' Chubb input gpio.5
    ' Output to panel - Trig var gpio.2
    ' Photo Guy gpio.4
    input gpio.5
        Chubb var gpio.5
    output gpio.4
        Led var gpio.4
        low led
    output gpio.2
        Trig var gpio.2
        low trig
    
    'Variable for the photo guy
    x var word
        x = 10
        
    ' Test the photo guy
    PAUSE 2000
        HIGH LED
            PAUSE 250
        LOW LED
            PAUSE 250
        HIGH LED
            PAUSE 250
        LOW LED
    PAUSE 2000
    
    'start here
    loop:
        if Chubb = 0 then
            high trig
            if X < 11 then
                X = 12
                gosub cola
            endif
        else
            low trig
        endif
    
        if x > 11 then
            x = (x + 1)
        endif
    
        if x >= 300 then
            x = 10
        endif
    
        if x = 100 then
            GOTO foto1
        endif
    
    pause 100
    goto loop
    end
    
    
    foto1:
        high led
            pause 100
        low led
                pause 250
        high led
            pause 100
        low led
    goto loop
    
    cola:
        high led
            pause 100
        low led
    return
    end

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Meriachee View Post

    Code works like a charm.Gary
    Hi, Gary

    I did understand it was the reason for you to show it here ... sure !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Originally Posted by Meriachee

    Code works like a charm.Gary
    So you have it all figured out now? What did you do to fix it?
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    There was a goto a subroutine, and a return at the end of it. Funny how PBP doesn't understand that it was s'posta go back to where we left off.

    The panel got installed this afternoon, and after a small expected timing change to the photoguy, it works like a charm.

    Thanks for all the help.

    Gary

Similar Threads

  1. 12F683 vs 12F675.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th July 2009, 04:58
  2. Instant Interupts with a 12f675
    By wlundonly in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th January 2008, 01:52
  3. 12F675 won't reprogram or erase
    By modifyit in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 19th May 2006, 05:07
  4. 12f675 serial pic2pic
    By tagan in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th March 2006, 22:55
  5. Multitasking 12F675 I/O
    By jpeakall in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th November 2003, 00:57

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