Menu

PIC12F1501 ADC problem

2017-05-19
2018-01-21
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    Hi,

    I'm trying to use a program that runs fine on a 16F690, on a 12F1501.

    I am using RA0 and RA1 as ADC inputs with this simple line:
    if ReadAD(AN0) < ReadAD(AN1) then ...

    When compiling in MPLAB for 12F1501 it complains:
    "Symbol not previously defined (ADCS1)" and "Symbol not previously defined (ADCS0)"

    The only instances of ADSCx in the asm file (that GCB generated) is this:
    banksel ADCON1
    bcf ADCON1,ADCS1
    bsf ADCON1,ADCS0

    -Is it me (doing something the PIC is not capable of) or is GCB doing something wrong?

    ====

    ;Chip Settings
    #chip 12F1501,0,125
    #config OSC=INTOSC
    
    dir PORTA.0 in
    dir PORTA.1 in
    DIR PORTA.2 out
    DIR PORTA.3 out
    
    'Main code
    set PORTA.2 off
    set PORTA.3 off
    
    stopdo=0
    
    Do Forever
    
    if stopdo=4 then
    exit do
    end if
    stopdo= stopdo + 1
    
    set PORTA.2 on
    wait 1 s
    
    if ReadAD(AN0) < ReadAD(AN1) then
    opendo = 1
    else
    opendo = 0
    end if
    
    if opendo = 1 then
    For i = 0 to 100
    set PORTA.3 on
    wait 1 ms
    set PORTA.3 off
    wait 9 ms
    next
    end if
    
    if opendo = 0 then
    For i = 0 to 100
    set PORTA.3 on
    wait 2 ms
    set PORTA.3 off
    wait 8 ms
    next
    end if
    
    set PORTA.2 off
    
    wait 2 s  
    
    loop
    
    'close lid and quit forever
    set PORTA.2 on
    wait 1 s
    
    For i = 0 to 100
    set PORTA.3 on
    wait 2 ms
    set PORTA.3 off
    wait 8 ms
    next
    
    set PORTA.2 off
    end
    
     

    Last edit: Roger Jönsson 2017-05-19
  • kent_twt4

    kent_twt4 - 2017-05-19

    Looks like a malformed chipdata file for the 12f1501. Goto gcbasic/chipdat/12f1501.dat and add the clock select bits (copy and paste) then save the file.

    Chipdata file [bits]

    ADFM,ADCON1,7
    ADPREF0,ADCON1,0
    ADPREF1,ADCON1,1
    

    Should be:

    ADFM,ADCON1,7
    ADCS2,ADCON1,6
    ADCS1,ADCON1,5
    ADCS0,ADCON1,4
    ADPREF1,ADCON1,1
    ADPREF0,ADCON1,0
    

    Also the number sign (#) is required when dealing with chip and config lines, like so:

    #chip 12F1501, 0.125
    #config OSC=INTOSC
    

    So now the program should compile.

     
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    The "#" was lost when pasting the code to the forum. I now fixed that post.

    After editing the DAT file with GCB Version 1.0 2015-07-12, it throws up (opening Hardware settings):
    "The chip model currently selected for this program is not valid, please check that the model of chip is correct" then "Great Cow Graphic BASIC could not find any config settings for this chip" when trying to select 12F1501.
    Replacing with the original 12f1501.dat it works as before.
    Some checksum error or what?

    Is there some special trick needed to edit the .dat files (I tried several editors)?
    The last version of the .dat file is attached.

     

    Last edit: Roger Jönsson 2017-05-19
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    With GCB 0.9.14 the edited .dat file is accepted. Why is 1.0 not accepting the edited 12f1501.dat?

    (RA3 would not output, but now I see that it is not a general output...)

    Edit (later): I was wrong!!! GCB 0.9.14 still used the .dat file that came with it. AND IT WORKS without editing!

     

    Last edit: Roger Jönsson 2017-05-19
  • Anobium

    Anobium - 2017-05-19

    May I check? What version of the Great Cow BASIC compiler release are you using?
    And, you are using Great Cow Graphical BASIC Version 1.0 2015-07-12?

     
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    I downloaded the complete Great Cow Basic IDE yesterday, in which I found Version 1.0 2015-07-12 and that is what I tried to use. If I just open 1.0 2015-07-12 and try to select the 12f1501, it says it does not exist after I have edited the .dat (which works with the old 0.9.14). 1.0 2015-07-12 finds the unedited .dat fine.

    When I went back to my old GCB 0.9.14 it works (writing the code in the old Crimson Editor and then doing "Compile and Download with GCBasic" and using the edited .dat.

    EDIT: Again I was wrong. The old 0.9.14 used the .dat file that came with it.

     

    Last edit: Roger Jönsson 2017-05-19
  • Anobium

    Anobium - 2017-05-19

    Can you please try your code in the latest build with NO editing to any of the .dat files.

    Your code works here - so, I am puzzled.

     
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    To clarify I used the GCB_Installer-97.exe 2017-03-05 to install yesterday.
    Is there an unofficial newer build? If so where do I find it?

     
    • Anobium

      Anobium - 2017-05-19

      If you used the GCB_Installer-97.exe 2017-03-05 to installed yesterday - can you confirm the results?

      I get a good build. Do you? I have attached my program.

       
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    As said, I can not even open the edited 12f1501.dat in the new GCB.
    I now tried with the older 12f1501.dat (2013-03-25) from the old GCB and now when I compile with the latest CGB the build seems fine in MPLAB, but the programmed PIC doesn't do anything, so that workaround did not work...

    Your program didn't work until I changed the 0.125 tp 0,125 (point to a comma). I do not know why this is. Maybe something about the language of the OS (XP), but weird it is.
    Then it passed MPLAB without build errors.

    #chip 12F1501,0.125
    changed to:
    #chip 12F1501,0,125
    

    With the original 12f1501.dat that came with the latest GCB it complies in this latest GCB, but when I try to build it in MPLAB v8.92 the build fails:
    "Symbol not previously defined (ADCS1)" and "Symbol not previously defined (ADCS0)"

    Since the edited 12f1501.dat (suggested in this thread) is not accepted by this latest GCB, I am out of ideas to try.

    I was wroing about the GCB 0.9.14. It always used the original .dat file that came with it.

     

    Last edit: Roger Jönsson 2017-05-19
  • Anobium

    Anobium - 2017-05-19

    OK. Why not try using the in-built compiler and assembler within Great Cow BASIC? Does this work?

    I do get the same two errors in MPASM - so, please use the assembler within Great Cow BASIC - the generated HEX should be the same.

     
  • Anobium

    Anobium - 2017-05-19

    The root cause of the issue is that the MPLAB include file is missing a set of bit/registers. We know they are missing so we correct in our dat files - however, when you try to use with MPASM the corrections will not work - hence the error.

    If you still want to use MPASM add the following to your user code and all should work fine.

    #define ADCS0 ADCON1.4
    #define ADCS1 ADCON1.5
    #define ADCS2 ADCON1.6
    
     
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    Ok. Thanks for the help.

    It looks like I should have a look at generating HEX-files and where to put them and what to use to get the code into the PIC. It is so long since I fiddled with HEX-files and serial programmer, that I have no idea where to start. -Well to be honest I havenät really looked yet :)

     
    • kent_twt4

      kent_twt4 - 2017-05-19

      Big fan of the Pickit 2, mostly because of GUI it comes with, and the improved device file that William here made up. Device file can found in GCB, and it will handle the 12f1501 and many other newer devices. Clones can be had for cheap, and with a dupount cable, or right angle header, can plug right into a breadboard for in circuit programming (that is 90% of my use).

      Another option is a Pickit 3 along with the MPLAB IPE.

       
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    I have both. Pic Kit 2 is great as it works fine without MPLAB, but how does one make it support 12f1501? 12f1501 was the reason I bought Pickit 3 !... but then I had to use MPLAB, which has worked fine for many years until the A/D converter problems turned up.
    I looked at getting Pickit 3 working directly with GCB a year or so ago, but I couldn't figure out how to make it work.

     
  • kent_twt4

    kent_twt4 - 2017-05-19

    Here is a link to the PicKit 2 device.dat file, https://sourceforge.net/p/gcbasic/discussion/629990/thread/7c0f5a1a/#7682 just drop it in your PK2 folder. I don't have the location of this file in the IDE, but there have been a couple of threads on this.

     
  • Roger Jönsson

    Roger Jönsson - 2017-05-19

    Thanks. I will have a look at it later.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.