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.

Need help finding a conflict with PIC12F675 GP0

Status
Not open for further replies.

MalcolmZA

New Member
Folks,

I’m struggling with a small PIC12F675 program which uses 3x analog inputs, 1x digital I/P, 1x digital O/P, and 1x serial O/P from a software UART.
I’m using an existing PCB, the analogs must be AN1,2, and 3, the DI is fixed at GP3.
The DO and serial OP can be either GP0 or GP5.

My problem is with pin 7, GP0. Something seems to override my program. I’m suspecting the comparator isn’t correctly disabled but cannot find the answer in the chip data sheets or the PIC midrange manual.

If I use GP0 for the serial output, I see pulses on the pin but my terminal doesn’t show the characters. GP5 works fine and follows the state of GP3.
If I swap GP0 and 5, so the serial data is on GP5, I see the transmitted text on the terminal and if the DI is held on I see GP0 pulsing with my logic probe.
Finally , if I put an AllDigital statement at the start of the program, the DO and serial OP work on GP0 and GP5.

So it seems like something related to the analog inputs or comparator are conflicting with GP0.

The code I'm using to find the problem follows.
Cheers
Malcolm


'For simulation, REM out for final program
Define SIMULATION_WAITMS_VALUE = 0

Define SEROUT_DELAYUS = 5000

'AllDigital

Symbol ser_out = GPIO.0
Symbol dig_op = GPIO.5
Symbol dig_ip = GPIO.3

Dim x_ai As Word
Dim y_ai As Word
Dim z_ai As Word

Define ADC_CLOCK = 3
Define ADC_SAMPLEUS = 50

ConfigPin ser_out = Output
ConfigPin dig_op = Output
ConfigPin dig_ip = Input

'Enable the ADC
ADCON0.ADON = True

'set Vref to Vdd
ADCON0.VCFG = False

'Disable the comparator in PIC12F675
cmcon.CM0 = 1
cmcon.CM1 = 1
cmcon.CM2 = 1

start:

Adcin 1, x_ai
Adcin 2, y_ai
Adcin 3, z_ai


Serout ser_out, 9600, "x :", #x_ai, CrLf
Serout ser_out, 9600, "y :", #y_ai, CrLf
Serout ser_out, 9600, "z :", #z_ai, CrLf

dig_op = dig_ip

Goto start
End
 
I would guess that you need to turn off analogue with ANSEL=0. I don't know Oshonsoft so not sure.

Mike.
Actually, zero is wrong as you need some analogue inputs.
Edit2, ANSEL also contains conversion clock speed so check datasheet P44.
 
Mike ,

Thanks for the reply. You were damm close with " I would guess that you need to turn off analogue with ANSEL=0 "
Initially I disregarded your advice after your edit where you'd missed I needed analogs.
At the time I was reading about USING the comparator at https://www.best-microcontroller-projects.com/12F675-comparator.html
in the hope there was advice on disabling it, and spotted this....
One "Gotcha"
One piece of information that is only implied by the documentation is that the comparator inputs must be set to analogue inputs - otherwise the comparator does nothing!
So you need to control ANSEL.

I ran my program in Oshon and saw ANSEL.0 = 1.
ANSEL=0 was added to disable AN0 and BINGO.
The problem was GP0 being configured as a an analog rather than the comparator screwing me around ( as has happened previously)

Many thanks for the nudge to change my direction

Malcolm
The pommie in darkest Afrika
 
The analogue pins are where most people get caught out. Note that an analogue pin will still act as a digital out but will always read as zero when read as digital. So, doing AN0=1 will reset AN2 if it's an analogue pin.

BTW, I guessed SA due to the ZA on your signature. I have lots of SA friends here in Aus.

Mike.
 
My daughter was offered an internship for a year in SA (as part of her Chemistry Phd), she declined the offer - based on both the situation in SA, and that the guy in charge was a complete prat.
 
My daughter was offered an internship for a year in SA (as part of her Chemistry Phd), she declined the offer - based on both the situation in SA, and that the guy in charge was a complete prat.

Hi Nigel,

Your daughter made a wise choice. The main centers of SA have become quite a dangerous place.
I live 110km out of Joburg in a small, quiet , farming and weekend vacation town called Parys.

The guy in charge ??? Rudderless Ramaphosa perhaps. LOL
He's not in charge, he's just a front man for the rest of the criminals.

And don't underestimate the their intelligence.
Who else do you know that can steal a country from under the nose of the majority of the population whilst the idiots
voted them in time and time again.

BTW.. I'm also a pommie, lived here since the late 70's. Originally from Fleetwood in Lancashire.
I came here as a refugee from Maggie, with hind sight it wasn't the best decision of my life.

best ease ogg the politics before I get banned :)

Cheers,
Malcolm
 
The guy in charge ??? Rudderless Ramaphosa perhaps. LOL
He's not in charge, he's just a front man for the rest of the criminals.

Sorry if I confused you, by 'the guy in charge' I was referring to the guy she would have been working for - and been a clever young thing (far too smart for her own good!) she contacted the previous intern to ask their opinion, they recommended NOT going :D
 
Status
Not open for further replies.

Latest threads

Back
Top