PDA

View Full Version : PIC16F685 RA4/RA5 pins



Adrian
- 8th November 2008, 13:52
I thought(!) I understood that PortA 4 & 5 on a PIC16F684 could be used as general purpose I/O pins with an internal oscillator. So far I have been unable to achieve this. I have this at the top of my programme:-

@_CONFIG INTOSCIO & _WDT_ON & MCRE_OFF & _CP_OFF
ANSEL = $00
OSCON = %01100001
CMCON0 = 7
TRISA = $00
TRISC = $00

All other pins work fine but A4 continues to display a pretty 1Mhz clock output and A5 just looks at me!
I've RTFM endlessly and tried several things including subtle changes to the oscillator configuration fuse to no avail. So, to stop premature baldness can someone tell me what the problem is!

Many thanks

Adrian

mackrackit
- 8th November 2008, 14:33
Not sure I remember, but I think the comparators on that chip are under the
CM1CON0 and CM2CON0 registers. And A4 is open collector.
http://www.picbasic.co.uk/forum/showthread.php?t=562

You may want to look at the inc file in MPASM to be sure.

Adrian
- 8th November 2008, 15:01
Thanks mackrackit but still no joy. I've tried the open collector thing and I believe the COMCON0 to be right. This is puzzling me. I would have thought there should not be clock on A4 when INTOSCIO is chosen as a fuse. I'll keep trying (or change the PIC type.....!!!!)

Adrian

Acetronics2
- 8th November 2008, 16:05
Hi,

May be the underscore befre INTOSCIO ... ???




_EXTRC_OSC_NOCLKOUT EQU H'3FFE'
_EXTRC_OSC_CLKOUT EQU H'3FFF'
_INTOSCIO EQU H'3FFC'
_INTOSC EQU H'3FFD'
_EXTRCIO EQU H'3FFE'
_EXTRC EQU H'3FFF'



Beer for everyone !!!

Alain

Bruce
- 8th November 2008, 16:25
@_CONFIG INTOSCIO & _WDT_ON & MCRE_OFF & _CP_OFF ; 5 errors here
ANSEL = $00
OSCON = %01100001 ; 1 error here
CMCON0 = 7 ; 1 (maybe 2) errors here
TRISA = $00
TRISC = $00
First person to find them all gets the beer...;o}

Adrian
- 8th November 2008, 16:30
Hi Alain

Sadly not, so no beer - not even a good Cotes du Rhone from E.Guigal........! Unfortunately this was a typo error on my post. It was correct in the programme. Rest of programme is fine but RA4/RA5 stubbornly refuse to do anything useful. If someone out there has a 16F684 I'd like them to try it!

adrian

Adrian
- 8th November 2008, 16:34
Sorry for wrong information. This should be Pic16F684 not 685. Must be getting tired. HOWEVER it still doesn't work!!

Bruce
- 8th November 2008, 16:43
It would be a bit different if it's not a 685. Try something like this, and make sure your
device programmer keeps your config settings. You'll also need to comment out the default
config setting in the 16F684.INC file for MPASM.



@ __CONFIG _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF

ANSEL = $00
OSCCON = %01100000
CMCON0 = 7
TRISA = $00
TRISC = $00

Adrian
- 8th November 2008, 16:47
Hi Bruce

Working through the errors!

OSCCON is typo in my post - OK in programme
MCLRE ditto
underscore in INTOSCIO ditto
Can't see anything wrong with CMCON0Apologise for wrong PIC reference in post and typos
Still stuck

Adrian

Adrian
- 8th November 2008, 17:03
Hi Bruce

My programme is exactly the same as yours (I removed the 1 from OSCCON bit 0). It is just the same as before. I have a 1 Mhz square wave on pin 4 and a sawtooth waveform on pin 5. I have removed everything else in the programme now apart from a LED flashing on RA1. If I try to do that on RA4/RA5 - zilch. The relevant config line was commented out in the PBP pic inc file but I had also tried programming both ways with no luck.

mackrackit
- 8th November 2008, 17:31
Copy/paste your whole code and inc file so we can see everything.

Adrian
- 8th November 2008, 17:51
Hi mackrackit

Here it is.

To be clear I have removed the PIC from it's PCB and stuck it on a breadboard and just programmed it with these 10 lines of code. I have programmed it both with MPASM and PM with line in inc file restored.
None of the pins are connected apart from LED on PORTA.0 which flashes. Do that on RA4 or RA% and nothing. I get a nice square wave at 1Mhz on RA4 and a sawtooth on RA5. Logic tells me I am not programming an I/O on RA4/RA5 but can't see why. Maybe there is something obvious that I keep overlooking - just too tired or too stupid. Hope you find it!!

Code cut & pasted



@__CONFIG _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF
ANSEL = $00
CMCON0 = 7
OSCCON = $60
TRISA = $00
TRISC = $00

Start:
TOGGLE PORTA.0
PAUSE 250
goto start


INC File



NOLIST
ifdef PM_USED
LIST
include 'M16F684.INC' ; PM header
device pic16F684, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F684, r = dec, w = -302
INCLUDE "P16F684.INC" ; MPASM Header
;__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
NOLIST
endif
LIST


regards

Adrian

Bruce
- 8th November 2008, 17:55
Wow that is strange. I don't have a 16F684, but this works as expected on a 16F688.


@ __CONFIG _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF

ANSEL = $00
OSCCON = %01100000
CMCON0 = 7
TRISA = 0
TRISC = 0

Main:
PORTA = %00010000
PAUSE 500
PORTA = %00100000
PAUSE 500
GOTO Main

END
Try the attached .hex file. It's the same code - but compiled for your 684.

If it doesn't work, try reading it back from the chip and verifying the config settings.
Sounds to me like your programmer isn't using the config settings embedded in the .hex.

Note: If your device programmer isn't programming the config regs, then that would explain
what you're seeing. The default clock would be external RC with clock out on OSC2.

The funky signal you're seeing on OSC1 is the internal clock drive assuming an RC oscillator
circuit is on OSC1.

The 1MHz signal on OSC2 is the internal oscillator output. It defaults to internal osc since
your external RC oscillator circuit isn't there. Controller thinks it has failed, defaults to
internal 4MHz, and still outputs clock/4 on OSC2.

Adrian
- 8th November 2008, 18:25
Thanks Bruce
I'll try that tomorrow morning. Just jumping into a bath for a night on the town..!! Well not quite on the town.... at my age its more sedate but I'll have a go tomorrow and let you know. Thanks to you all

Adrian

Adrian
- 9th November 2008, 13:35
Hi Bruce

Problem solved!

Your download produced the same symptoms as my programme, but when I read it back it certainly didn't show INTOSCIO - from memory it might have been INTRC also MCLR was ON. Obviously not picking up the correct config settings as you suspected.

I had a lucky flash of inspiration and in Microcode went to Options||More Options and pressed Set Options to Defaults.

Immediately all came good and the PIC programmed perfectly.

So thank you (and thanks to the others) for your help and I can get back to my PCB testing.

I have no idea why my Microcode would not be locked solid onto its defaults. Maybe I hit something by mistake. Also would you know what parameter stopped this from programming correctly?

Useful to remember to check in future and would save 24 hours of hair tearing......

Regards

Adrian

Bruce
- 9th November 2008, 14:07
I think you may be confusing MicroCode Studio editor with your programmers software.

I'm sure you selected something like meProg software Options, More Options, then
Set Options to Defaults..., which reset programmer options. It most likely was not
loading & using config settings embedded in your .HEX file.

If you comment out all config options in your code, compile, then program, you'll see that
all config options are at the default unprogrammed settings. This leaves /MCLR ON, sets
the oscillator to external RC with clock out on OSC2, and produces exactly the same
scenario you were seeing.

I duplicated it exactly by doing the same thing here. Somewhere along the line you had
changed your programmer settings to not use config settings in your .HEX file - or not
program them.

Check the attached graphic. I commented out the config statement in the example above,
compiled, and launched the programmer. Check the config settings.

The PIC is still going to run because there is no external RC clock, it assumes the external
osc has failed, and switches over to the default internal 4MHz osc, and keeps going.

But now you have Fosc/4 out on OSC2, and a ping signal on OSC1, which is the internal
driver ping to tickle the external RC osc, which you don't have...;o}

Check the diagram in the datasheet under RC OSCILLATOR MODE for a drawing of what's
going on with these two pins when this osc mode is selected.

Adrian
- 9th November 2008, 15:45
Yes thanks Bruce. Slip of the tongue between Editor & Programmer. It was the Programmer I set back to default options. I guess I must have jiggered one of the default settings which as you say stopped it loading and using the embedded settings.

Thanks for explanation of clock settings on the 16F684. I have looked up the datasheet and see exactly what you mean.

It's a long and slippery road but a great learning curve..........

Regards

Adrian