1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Program to read A/D on firefly...

Discussion in 'Microcontrollers' started by RobertD, Jul 1, 2008.

  1. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    You must not have work tomorrow! 3:00AM in Brampton land. I gotta go sleep soon. Must slave away tomorrow.

    Send me your VR1 code to test. If it works for me and not for you then we will have confirmed that your problem is not likely hardware. Probably user error. :D

    Is the 16F88 the right way around in the socket? :p Seated fully? Grasping at straws...
     
    Last edited: Jul 3, 2008
  2. RobertD

    RobertD New Member

    Joined:
    May 20, 2008
    Messages:
    216
    Likes:
    1
    Location:
    Brampton Ontario
    10-4

    :)

    Goodnight...
     
  3. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    ONLINE
    I just dug out my FireFly and tried the code and it works as expected.

    BTW, the reason the debugging is so slow is because the 88 is running at 32k. If you add,
    Code (text):

        bsf STATUS,RP0
        movlw   0x70
        movwf   OSCCON
        bcf STATUS,RP0
     
    to your start up code it runs much faster.

    Mike.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    ONLINE

    If it helps, this is how my MPLAB window looked. I added a label "Again" so count got reloaded and put a breakpoint on that line. Pressing F9 makes it execute the look again.

    [​IMG]

    Mike.
     
    Last edited: Jul 6, 2008
  6. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Yup. :D

    Doh! I should have thought of that! :eek:
     
  7. Boomslang

    Boomslang Member

    Joined:
    Mar 3, 2007
    Messages:
    253
    Likes:
    4
    Location:
    South Africa
    Also note, the register values will not update while the program is running, it will only do so when you pause it, or when it reaches a breakpoint.
     
  8. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Ya, I pointed that out to Robert a page or two back. :)
     
  9. Boomslang

    Boomslang Member

    Joined:
    Mar 3, 2007
    Messages:
    253
    Likes:
    4
    Location:
    South Africa
    :D ...just want to make sure, he did not give confirmation that he know/saw it....
     
  10. RobertD

    RobertD New Member

    Joined:
    May 20, 2008
    Messages:
    216
    Likes:
    1
    Location:
    Brampton Ontario
    Hi there, just finished work, get right back into the firefly. I really have to get this thing to read. So I added the 4 lines OSCCON and it does run faster, but I still don't get any reading on the ADRESH/L when I run to cursor from goto loop

    I'm so glad to hear that my code works fine for you guys. Maybe the other dip switches make a difference, I have junebug connected to Firefly, and the junebug dips are setup 00011111 this way. The firefly dips are 010111. I'm still running on RA3 since it works for you, so there is nothing wrong with the code, and I have 4.3v on the pot and on the pin, so the ADRESH/L should be somewhere around 3f or so. I have zero, nothing moving.

    It hangs on: btfsc ADCON0,GO ;conversion done?

    The animate just hangs there and doesn't go anywhere... like the GO bit doesn't clear.

    You mentionned something about the MPLAB running another program than the one I'm compiling is that a possibility?
     
    Last edited: Jul 3, 2008
  11. RobertD

    RobertD New Member

    Joined:
    May 20, 2008
    Messages:
    216
    Likes:
    1
    Location:
    Brampton Ontario
    I also would like to point out that the junebug has yellow and red LED on all the time. The firefly has the green LED on at the end of the ZIF socket. So I'll try to reprogram for the RA1 and see what happens.
     
  12. Boomslang

    Boomslang Member

    Joined:
    Mar 3, 2007
    Messages:
    253
    Likes:
    4
    Location:
    South Africa
    In the Debugger menu, did you select PICKIT2?
    In the Programmer menu, "None" should be selected.

    Run your program for 10 seconds, pause it and check the registers.
    Press play again, and pause it after 10 seconds. Do the readings change?

    Can you make a print screen of your MPLAB screen and attach it, maybe someone can spot something. Can you also attach a pic of the dip switches on your hardware?
     
    Last edited: Jul 3, 2008
  13. RobertD

    RobertD New Member

    Joined:
    May 20, 2008
    Messages:
    216
    Likes:
    1
    Location:
    Brampton Ontario
    OK I changed the code to RA1, and PORTA reads 00001000, if that means anything. I changed ADCON0 to B'10001001', and I ran to cursor, with... nothing still.


    Yes debugger is on PICKIT2, and none for programmer. And when I run the program with view registers, they change when the animate is going through the paces.

    Hey I just got a message saying : "unable to enter debug mode." That's got to be what the problem is.

    Code (text):

        LIST    p=16F88
        include "P16F88.inc"
        __config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON &  _LVP_OFF

        count   equ     0x22

            bsf     STATUS,5
            movlw   B'00000010'
            movwf   TRISA ;all outputs except RA1
            movwf   ANSEL
           
            movlw   0x2
            movwf   ADCON1
            bcf     STATUS,5
           
            movlw   B'10001001'
            movwf   ADCON0 ; channel 0, FOSC/8, enable A/D
            bsf STATUS,RP0
            movlw   0x70
            movwf   OSCCON
            bcf STATUS,RP0
           
            movlw   0x06
            movwf   count ;initialize count

        loop
            decfsz  count,F
            goto    loop ;until finished

       
            bsf     ADCON0,GO ;initiate conversion
       

        test
            btfsc   ADCON0,GO ;conversion done?
            goto    test ;not finished

            end
     
    Last edited: Jul 3, 2008
  14. Boomslang

    Boomslang Member

    Joined:
    Mar 3, 2007
    Messages:
    253
    Likes:
    4
    Location:
    South Africa
    Did you try play/pause/play/pause, animating can take so long somtimes that it looks like the program is stuck.... sorry if it sounds like repetitive questions, just want to make sure we are not going in circles like the MPLAB SIM part...
     
  15. RobertD

    RobertD New Member

    Joined:
    May 20, 2008
    Messages:
    216
    Likes:
    1
    Location:
    Brampton Ontario
    I tried play pause and the program just hangs there. The whole MPLAB is very slow when I start playing around with the animate and run to cursor, I often get Microsoft error messages when I try to close it. I'm relieved to know the program is running OK, at least I know the code is OK, so the problem has to be either firefly or MPLAB... or me, that's not properly setting up MPLAB, but after talking to you guys, and trying just about everything, I think there might be a problem with my computer, or something like that. I think I'll just let it sit for now, and work on getting a table to read and output correctly. That's the other half of the program I'm trying to set up.
     
  16. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    I unplugged the PICkit 2 and plugged in my Junebug. My Junebug dips are 00000000. Only the first three matter in this case though, so don't worry that yours is different.

    Yup.

    Don't animate it. Use run to cursor (or do a breakpoint like Pommie suggested - same thing either way). Waiting for the GO bit to clear in animation can take a long time.

    Just double check that the Source File listed in the Project window is the same source file that you're looking at in the editor window.
     
  17. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Firefly LEDs - don't really care. They can turn blue for all I care, as they're not being used in this program.

    Junebug should NOT have a red LED on though. You're talking about the green/yellow/red status LEDs up by the USB port? If you're seeing a red LED there, unplug your Junebug and replug it. Then hit ALT-D and C to get MPLAB to reconnect to it before trying again.

    The green one should be on. That's the power LED.

    The yellow one should be off unless you're powering your Firefly separately (not from the Junebug).
     
  18. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Na. The PICkit 2 does that occasionally. Just reset everything, as in, unplug the Junebug and replug it. Possibly restart MPLAB. Don't worry too much about it. It's just a bit of flakiness that happens once in a while with the software. Doesn't hurt a thing.
     
  19. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    I usually unplug and replug the junebug and press that little check connection button and poof it works.
     
  20. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Found some small problems with your source code. Here it is with everything fixed. I may have to repost to tell you exactly what I changed...

    Runs perfect in the debugger. Gives correct results in the Watch window.
    Code (text):
        LIST    p=16F88
        include "P16F88.inc"
        __config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
        ERRORLEVEL 0, -302

        cblock  0x20
        count
        endc

        banksel TRISA       ;bank 1
        movlw   B'00000010'
        movwf   TRISA       ;all outputs except RA1
        movwf   ANSEL
        movlw   b'11000000'
        movwf   ADCON1
        banksel PORTA       ;bank 0
        movlw   B'01001001'
        movwf   ADCON0      ; channel 0, FOSC/8, enable A/D
        bsf STATUS,RP0
        movlw   0x70
        movwf   OSCCON
        bcf STATUS,RP0
    bleh    movlw   0x06
        movwf   count       ;initialize count
    loop    decfsz  count,F
        goto    loop        ;until finished
        bsf     ADCON0,GO   ;initiate conversion
    test    btfsc   ADCON0,GO   ;conversion done?
        goto    test        ;not finished
        goto    bleh
        end
    Here's what I changed:
    1. I put "ERRORLEVEL 0, -302" so I don't have to see all those warnings.

    2. I put a cblock for the variable instead of the EQU.

    3. Used banksels cuz I like them better than that cryptic bsf status crap.

    4. You had ADCON1 set wrong. "2" just won't do it. :p

    4. I changed the aquisition time for 8MHz, though the program isn't running that fast. Now you can speed up the clock and it'll still work well

    5. You had nothing at the bottom of the program to catch it from running away. I made it loop back to re-read the A/D.
     
    Last edited: Jul 3, 2008
  21. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    I don't even see those buttons. :D I hit ALT-D and C in debug and in programming mode I hit ALT-G and C.

    I have some carpal tunnel problems from way too long at this computing stuff, so I learn keyboard shortcuts for everything I can. The mouse is pure evil.
     

Share This Page