PDA

View Full Version : Pic16f88



Maurice
- 29th March 2004, 13:42
Hi,
I'm trying to get a 16F88 to gather four analog inputs on portA and then send out a computed result as a HPWM on portB.3

I need to switch the HPWM to port 3 since the hardware is already made and I was using that port on a 16F628.

Could somebody please tell me

A) the official way to open up 4 analog portA and 1 digital PORTA is it :-

ADCON1=7
ANSEL=%01111

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

B) How on earth do I make the 16F88 swap its CPP1 drom portB.0 to portb.3 ?

Maurice

Melanie
- 29th March 2004, 14:57
a). You are correct that ANSEL=%00001111 will cause ANS0 thru ANS3 to become Analog. It would also be best to switch off the Comparators CMCON=7, unless you're particularly skilled and need to use them simultaneously.

I don't understand what you're trying to accomplish by setting ADCON1=7 (see Datasheet section 12 Register 12-2). The most important are bits 5 and 4 which determine your source of VRef, otherwise the ADCIN defines take care of the rest. If you're using Vdd and Vss for Vref, 10-bit mode, then I'd set ADCON1=%10000000.

b). Setting the alternate pin for PWM output is a function of the configuration word bit 12 (CCPMX). Assuming you're using PBP's Assembler (by default), then by setting...

@ DEVICE pic16F88,CCPMX_ON

or

@ DEVICE pic16F88,CCPMX_OFF

at the start of your program, you can set RB0 or RB3 accordingly. Make the appropriate config line adjustments if you're using MPASM as the assembler. See Datasheet section 15 esp Register 15-1.

It's all in the Datasheet... you gotta make friends with it if you want to be proficient - there's no substitute.

Melanie

Maurice
- 29th March 2004, 15:20
Thanks Melanie!
that seems to answer most of it. I am fairly new to all of this and do spend a lot of time misunderstanding the datasheet :-) I spent a lot of time failing to write to bit 12 of the CONFIG1 register. I tried the following methods and failed:-

CONFIG1.12 = 0

CONFIG1=CONFIG1 & 10111111111111

CCPMX=0

Are any of the above valid but wrong in their numeric content because they did not work? Can you write to such a register from PBP or are we restricted to just the magic (and seemingly invisible in the manual) PBP defines?

A couple of words would be very much appreciated here :-)

all best and thanks for your reply

Maurice

Melanie
- 29th March 2004, 15:37
None of those you list are valid because the CONFIG register is not accessible from within your program code. You can only PRESET the contents of the CONFIG register using defines as I have indicated in my example, or at program time within the options displayed by your programmer/programmer software.

What defines? I can hear you ask... go to the \INC sibdirectory of your PBP installation, therein you will find a whole heap of files like M16F62X.inc, go and open one...

Near the top it will tell you what PIC's this file applies to... underneath you will find the CONFIGurations that apply, and below that are the registers listed that you can access directly. See section 6.1 in the PBP manual. The CONFIG options in the .INC file should match the CONFIG option in the PIC's Datasheet section "Special Features of the CPU".

Admittedly the PBP manual is a little spartan in some things. But it's a little like accounting software for example - where do you draw the line between telling somebody how to use the accounts package, and teaching them how to be an accountant.

Melanie

Don Mario
- 15th May 2004, 14:39
HI Melanie,

My name is Mario and I'm from Bucgarest,Romania.
I work with flash PIC and PBP (2.43 now) from 2 year.
Now, I try to work with 16F88,but I have a problem like Maurice,with DEFINE.Not all bits in CONFIG1 & CONFIG2 register
are recognized by PBP.
CCPMX,CPD,LVP,IESO - work
Fosc0,Fosc1,Fosc2,MCLRE,WDTEN,FCMEM - don't work
What's your opinion ? What can I do ?
I'll apreciate your answer !

Don Mario

P.S. scuse my bad english

Melanie
- 16th May 2004, 12:32
Hi Don Mario

I believe version 2.43 doesn't support 16F88. Check here...

http://www.melabs.com/support/upgrade.htm

That's why various registers are missing. You have two choices... either upgrade (best and recommended option), or create your own INC files (not recommended for beginners), I have previously discussed their creation and you can search the archives for this at...

http://list.picbasic.com/cgi-bin/board-search.cgi

It's not a quick job and a lot of hard work (several hours for someone experienced at best)... but at least you have plenty of examples to compare against and help you along.

Melanie

Don Mario
- 16th May 2004, 12:52
Hi Melanie,

I download the patch file 16F88.zip from melabs download page.
I upgrade 2.43 with this patch.
I make this before I write to you.
Before this upgrade PBP don't support the bit IESO from CONFIG2
register.
The INC file for 16F88 exist now in PBP/INC directories.
I think is an other problem ! ?

Thanks for your opinion & I wait you again

Don Mario

Melanie
- 16th May 2004, 13:04
I will try this ZIP on version 2.43 which I will load later when I've a free moment and will let you know what I've found...

Melanie
- 23rd May 2004, 18:57
I can confirm that the IESO and also the FCMEN configuration bits do not appear to function when set within PBP... I will investigate further later in the day to see if I can provide you with a fix...

Melanie

Don Mario
- 23rd May 2004, 20:03
Thanks Melanie,

I wait your solution !

Don Mario

Melanie
- 24th May 2004, 09:49
I don't think the v.2.43 PBP assembler is capable of accessing config words at addresses other than 2007h, this could be an oversight by MeLabs... and this is perhaps one of the reasons why you're forced to use MPASM with the 18F series...

I can see only two options at this time...

1. Use MPASM Assembler instead of PM adjusting the defines accordingly.

2. Manually override those two settings in your programmer at program time.

Both of those should keep you going, but I don't think you'll end up getting a fix for this to V2.43.

Melanie

Don Mario
- 24th May 2004, 11:06
Thanks for your answer Melanie,

But the problem is more complicated !
I work with 16F88,not 18FXX ! PBP 2.43 don't recognize all the config bits in CONFIG1 register (2007h) ? !
Fosc0,Fosc1 & Fosc2 don't work with DEFINE.
In config2 register (2008h) IESO bit work with DEFINE,
FCMEN don't work with DEFINE.
I think this is a bug in PBP 2.43 ! What do you think about it ?
Can I write to Melabs ?

Don Mario

Melanie
- 24th May 2004, 14:25
When I tried it, the FOSC settings worked as expected, however by studying the INI file I can see that FOSC can be corrupted by attempting to set FCMEN and IESO and I don't recommend inclusion of any their definitions if you are using PM assembler. I was NOT able to change FCMEN or IESO in my definition tests, they always remained ENABLED regardless...

@ DEVICE PIC16F88,FCMEN_OFF

or

@ DEVICE PIC16F88,FCMEN_ON

always produced FCMEN=Enabled, just the same as...

@ DEVICE PIC16F88,IESO_OFF

or

@ DEVICE PIC16F88,IESO_ON

always produced IESO=Enabled.


I've already contacted MeLabs about this (waiting for a reply as they wouldn't be back from the weekend yet).

Melanie
- 24th May 2004, 18:37
Jeff at MeLabs has just confirmed what I previously deduced and posted here.

The setting of the second Config Word needed a change to PBP's assembler, which I assume has been completed in the current release of PBP (2.45).

Use the two work-arounds I gave you, or upgrade your version of PBP to the latest.

As I said before, whatever you do, DO NOT USE any of the FCMEN or ICSO defines as they can impact on the Oscillator settings. This restriction does not apply if you use the MPASM assembler.

Melanie

Don Mario
- 26th May 2004, 13:37
Thanks Melanie, for your answer ! If I understand corectly,the problem with CONFIG bits are in PM assembler,not in PBP compiler.If I use MPASM assembler,CONFIG bits problem is solved,
if I understand corectly ? ! But I never work with PBP & MPASM.
Please,if you had time of course, tell me,how can I use the combination PBP & MPASM.
Thank you very much for your help and again scuse my bad english.

Don Mario

Melanie
- 28th May 2004, 12:03
You're going to need to download MPASM. PBP manual states how to use MPASM assembler within the command line... example...

PBP -p16F88 myfile -ampasm

You must assign a path from your PBP directory to the one with MPASM in it.

If you have problems, you can invoke MPASM directly and load the file for assembly into the dialogue box appropriately.

Look at the 16F88.INC file for a clue as to how to embed MPASM style defines into your program - they have to be done as one contiguous line per Config word.

mattb
- 17th November 2005, 22:46
My apologies for bringing up such an old thread, but I must note that this issue is still present in PBP version 2.46. FOSC and IESO still corrupt the last two bits of the Configuration Word 1 (oscillator settings), and it is impossible to access the actual fuses for those two settings.

Unfortuanately, I do not have access to the other assembler you reference, but is it possible to change the .inc file such that these fuses are correct? Or is this simply an error within the assembler itself?

I appreciated finding this thread (from Google) - thank you for your effort in examining this problem. It has been very helpful to read your previous responses.

Matt