Continue to Site

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.

  • 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.

Adding A/Ds to 12F683 in Oshonsoft

Status
Not open for further replies.

camerart

Well-Known Member
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:
 

Attachments

  • Analogue 29.bas
    1.3 KB · Views: 360
Last edited:
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
Thanks Ian,

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

Camerart
 
This will run in Oshon

Code:
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

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

This second module has more options.
https://www.electro-tech-online.com...-simulator-16fanalogramp3-external-modul.115/

Thanks Eric,

This works fine.

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

Cheers, Camerart.
 
Thanks Eric,

This works fine.

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

Cheers, Camerart.

hi,
Its a 'leftover' from a program, I cut n pasted the snippet which I posted for you... ignore it.
E
 
hi,
Its a 'leftover' from a program, I cut n pasted the snippet which I posted for you... ignore it.
E
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:
 

Attachments

  • Timer with AD inputs 29.bas
    1.7 KB · Views: 339
hi,
You cannot have gled for both.
Code:
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:
'If an0 >= 100 Then
    gled = 1
    WaitMs 10
    'Else
    gled = 0
    WaitMs 10
'Endif
 
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.
 
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
 
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

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.
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
 
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

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
 
hi,
Yes you can load T1CON in one go, if you wish
Either by Bits or a Byte value.
E
 
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.
 

Attachments

  • led test.bas
    1.6 KB · Views: 365
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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top