Menu

Reading ADC Values

2018-11-16
2018-11-16
  • Dermot Donnelly

    Dermot Donnelly - 2018-11-16

    Hi. I need a little help to get started. I have used the picaxe but want to migrate to GC Basic. I'm a bit confused with how the pins are designated especially with regard to reading an analogue value from a pin.
    Perhaps I can make clearer my problem if I show the picaxe code I want to convert to GCBasic:

    'picaxe 14M2

    readadc C.4,b0 'reads the value on pin C.4 (leg 3 of 14M2 which is 16F684) and stores it in variable b0

    pause 50

        if b0>=120 then goto State0001   'if it is above a certain value then the code brings us to somewhere else in the program but I don't know where to store the value to put in the if statement
    

    In GCBasic I think it should be something like:

    ReadAD(A????

    but I don't know what to call the ADC pin.
    Any help would be much appreciated. I have looked at the examples section but unfortunately the only relevant example I came across was something requiring a chinino library?
    regards
    Dermot

     
  • stan cartwright

    stan cartwright - 2018-11-16

    hi
    portc.4 is not an a-to-d pin. port c.3 is and it's called an7
    14m2 is pic 16f1825...see data sheet..page 4 http://ww1.microchip.com/downloads/en/DeviceDoc/40001440E.pdf

    dim adcval as byte ;variable to store adc
    dir port c.3 in ;make port input
    adcval=readad (an7) ;read adc and store in adcval
    
     
    • Dermot Donnelly

      Dermot Donnelly - 2018-11-16

      Thanks very much for that stan. That was exactly the information I was looking for.

       
  • William Roth

    William Roth - 2018-11-16

    Hi Dermot,

    Welcome to GreatCow BASIC

    With PICAXE, you probably never had to look at a PIC Datasheet. With Great Cow BASIC you will need to look at a PIC Datasheet from time to time.

    Each PIC Datasheet has a PIN section and a Table where the pins and their related uses are shown. This is usually Table 1 and is found in the first few pages of the Datasheet, Attached is Table 1 for a PIC 16F1825 which is the PIC equivalent of Picaxe 14M2.

    In the first column it shows the PORT/ PIN and in the 4th colum it show the ADC channel designator. Example RC2 - AN6

    You may want to print this chart out when using a PIC for the first time. I have a folder full of them for varius devices.

     

    Last edit: William Roth 2018-11-16
    • Dermot Donnelly

      Dermot Donnelly - 2018-11-16

      Thanks very much for that William. Looks like I'll have to RTFM from now on! I found the data sheets a bit daunting but you've cleared away some of the fog. Thanks again.

       

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.