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

Adding A/Ds to 12F683 in Oshonsoft

Discussion in 'Oshonsoft' started by camerart, Jan 29, 2014.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    I want to add a couple of Analogue inputs to a 12F683 Oshonsoft program. How do I set up the code (ADCON0, ANSEL, ADCON, ADON or whatever) for this please? I will use AN1 and AN2. I'm happy with similar examples!

    Code attachment:
     

    Attached Files:

  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Have you enough pins?... If you set the ANSEL reg up you can just call ADCIN channel, variable

    ADCIN 0,adcres1
    ADCIN 1,adcres2
    ADCIN 2,adcres3
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    This will run in Oshon

    Code (text):

    Define SIMULATION_WAITMS_VALUE = 1

    AllDigital


    Dim an0 As Word
    Dim an1 As Word

    ANSEL = 0x03
    ADCON0 = 0x85

    loop:
    Adcin 0, an0
    Adcin 1, an1
    Goto loop

    End      
    You will find this external module useful for Analog, its named 16F, but it will run on 12F

    http://www.electro-tech-online.com/blog-entries/oshonsoft-simulator-16fanalog3-external-module.113/

    This second module has more options.
    http://www.electro-tech-online.com/...-simulator-16fanalogramp3-external-modul.115/
     
    Last edited: Jan 29, 2014
  4. dave

    Dave New Member

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


     
  5. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.

    Thanks Ian,

    I only need two pins. I'm not advanced enough to know how to set such things as ANSEL.

    Camerart
     
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Thanks Eric,

    This works fine.

    Can you tell me why you have 'ALLDIGITAL' early in the code, when it has analogue pins?

    Cheers, Camerart.
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    ericgibbs... He doesn't need the alldigital command..( I know it won't make any difference to your code as you re-set the adcon0 reg...)
     
  8. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    So, I'm guessing that the later orders over ride the earlier ones?

    Thanks Ian.
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Kinda... But the control on the little pic12's is in the ANSEL reg not the adcon0 reg
     
  10. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Its a 'leftover' from a program, I cut n pasted the snippet which I posted for you... ignore it.
    E
     
  11. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Thanks Both,

    On Eric's code that he posted there is both ANSEL and ADCON0 and that bit worked ok.

    I have added that to a previous TIMER code, and it fails at the LOOP.

    See attached:
     

    Attached Files:

  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    You cannot have gled for both.
    Code (text):

    Dim an0 As Word
    Dim an1 As Word
    Dim gled As Bit
    Dim t As Word

    ''Symbol gled = GP2
     
    You have also remmed out the conditional IF...ELSE statement subr

    Code (text):

    'If an0 >= 100 Then
        gled = 1
        WaitMs 10
        'Else
        gled = 0
        WaitMs 10
    'Endif
     
  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Eric,

    I remmed out the Gled for a simpler (desperate:}) code.

    Also I chose the SYMBOL option, and I found another mistake, I had it as Symbol gled 'AS' GP2 instead of equal.

    Anyway, It's flashing now, thanks a lot.

    Camerart.
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Camerart,
    I would suggest that you tidy up your header layout on the program, there are 'bits' everywhere, makes it hard to follow.:)
    Eric
     
  15. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,
    You might remember helping me with a TIMER program last week? This is an add on to it, and will use a timer in conjunction with the A/Ds. So both programs have been merged. I don't fully understand the 'bits' in the header, even though I spend quite a time trying in the data sheets. I wouldn't dare try changing them, in case it has repercussions, that I again wouldn't understand.
     
  16. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
  17. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    I was looking at the header layerout and noticed (e,g,
    T1CON = %00110000 '0x30 = 8:1, so thats 1MHz/8= 125KHz or 8uSec
    T1CON.T1OSCEN = 1
    T1CON.TMR1ON = 1
    T1CON.TMR1CS = 0

    Am I correct, that at the 'T1CON' line '.T1OSCEN-TMR1ON and TMR1CS' can be 'catered for by changing the %00000000 bits?

    Cheers, Camerart
     
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Yes you can load T1CON in one go, if you wish
    Either by Bits or a Byte value.
    E
     
  19. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.

    Attached Files:

  20. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,427
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    Since I posted the 'tidied up' program I've slipped back down the well. I must have altered something, but I can't find the problem. Should I go back to before I changed it?

    I added a led to a spare pin, as a kind of diagnostic help, but I couldn't get it to work. So I changed the LOOP as a simple LED toggle. I have added a LED to the 3 spare output pins and a pause only, but PINs 2 and 3 don't seem to work.

    Can anyone help please? Code attached:

    Camerart.
     

    Attached Files:

  21. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,244
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    It works for me in simulation,
    You have this remmed out Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

    So the sim will take ages to run.
    E
     

Share This Page