PDA

View Full Version : 16F88 ADC problem



greensasquatch
- 5th September 2008, 20:11
I'm trying to get a 16f88 to read a voltage and display it on a LCD.

I have been able to display code on an LCD before, and using a 12f683 I have output serial data to a PC. With this project I am trying to display the analog data directly onto a LCD screen.

The LCD is connected to the default connections on the 16f88, an LED connected to RB1, and a variable voltage to AN0.

The code compiles correctly without errors however when I hook everythign up I get no readout on the LCD and the LED does not flash.

I'm hoping it's just something simple as this is my first time using the pic16f88 although I've been using the 16f84, 16f627a, 16f683 and 16f675 for about a month.

If anyone has any pointers I've really appreciate hearing them.

Thanks


CODE:

'************************************************* ***************
'* Name : LCDTest2.pbp *
'* Author : Greensasquatch *
'* Notice : Copyright (c) 2008 greensasquatch.ca *
'* : All Rights Reserved *
'* Date : 05/09/2008 *
'* Chip : PIC16F88 *
'* Version : 1.0.1 *
'* Notes : Send a message to a LCD on default pins *
'* : read an analog value and outout on the LCD *
'************************************************* ***************
'* PicBasicPro program to demonstrate operation of an LCD *
'* in 4-bit mode. *
'* THIS VERSION: To function on a PIC16F88 and output the *
'* voltage on the second line of the LCD. *
'************************************************* ***************

INCLUDE "MODEDEFS.BAS"

@ DEVICE INTRC_OSC_NOCLKOUT, MCLR_OFF

DEFINE OSC 8 ' define ADCIN parameters
DEFINE ADC_BITS 10 ' set number of bits in result
DEFINE ADC_CLOCK 3 ' set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' set sampling time in uS

adval VAR WORD ' store adc value
redLED VAR PORTB.1 ' alias redLED with RB1


ADCON0.7 = 1 ' right justify result
ANSEL = %00000001 ' set AN0 analog, rest digital
CMCON = 7 ' analog comparators off
Output PORTB.1 ' set RB1 as output
Pause 1500 ' wait for LCD to startup

loop: Toggle redLED
ADCIN 0, adval ' read channel 0 to adval (0-1023)
adval = (adval */ 500)>>2 ' equal to (adval * 500)/1024

Lcdout $fe, 1 ' clear LCD screen
Lcdout "Greensasquatch"' display Greensasquatch on 1st line

' move cursor to 2nd line, display voltage
Lcdout $fe,$c0, "DC Volts= ", DEC (adval/100), ".", DEC2 adval

Pause 1000 ' wait 1 second

Goto loop ' loop forever

Darrel Taylor
- 5th September 2008, 20:29
I'm trying to get a 16f88 to read a voltage and display it on a LCD. ...

The LCD is connected to the default connections on the 16f88, an LED connected to RB1, and a variable voltage to AN0.

The "Default" LCD pins have the data bus on PORTA<3:0>.

It will be difficult to also read an analog voltage on AN0 (PORTA.0)
<br>

greensasquatch
- 5th September 2008, 23:02
Thank you for pointing out what should have been very painfully obvious. I'll redo the code tonight and post the results.

greensasquatch
- 6th September 2008, 08:13
So one thing at a time, I want to get the LCD working again but on PortB. I've gone back to my code for the 16f627A and I want to get it working there before going back to the 16F88 and trying the ADC again.

I have used defines for LCDout so that I only use port B.

It compiles alright but when I run it on the PIC the LCD does not initialize. The light comes on, boxes are displayed (as the code used to do before initializing), the LED begins to toggle, but no change on the LCD.

The Code:

'************************************************* ***************
'* Name : LCDTest1.pbp *
'* Author : Greensasquatch *
'* Notice : Copyright (c) 2008 greensasquatch.ca *
'* : All Rights Reserved *
'* Date : 05/09/2008 *
'* Chip : PIC16F627A *
'* Version : 1.1 *
'* Notes : Send Hello World to a LCD on PORTB pins *
'* : blink a LED connected to RB6 as a status light *
'************************************************* ***************
'* PicBasicPro program to demonstrate *
'* operation of an LCD in 4-bit mode. *
'************************************************* ***************
'*
'* Connections are as follows:
'*
'* N/C -01-|####|-18- N/C
'* N/C -02-|####|-17- N/C
'* N/C -03-|####|-16- N/C
'* N/C -04-|####|-15- N/C
'* Gnd -05-|####|-14- V+
'* LCD Pin DB4 on RB0 -06-|####|-13- RB7, N/C
'* LCD Pin DB5 on RB1 -07-|####|-12- RB6, to red LED
'* LCD Pin DB6 on RB2 -08-|####|-11- RB5, E on LCD
'* LCD Pin DB7 on RB3 -09-|####|-10- RB4, RS on LCD
'*
'************************************************* ***************

INCLUDE "MODEDEFS.BAS"

@ DEVICE pic16F627A, INTRC_OSC_NOCLKOUT, MCLR_OFF

DEFINE LCD_DREG PORTB ' LCD data port
DEFINE LCD_DBIT 0 ' LCD data starting pin, RB0-RB3
DEFINE LCD_RSREG PORTB ' LCD register select port
DEFINE LCD_RSBIT 4 ' LCD "RS" register select pin
DEFINE LCD_EREG PORTB ' LCD enable port
DEFINE LCD_EBIT 5 ' LCD "E" enable pin
DEFINE LCD_BITS 4 ' LCD data bus size
DEFINE LCD_LINES 2 ' number of lines on the LCD
DEFINE LCD_COMMANDUS 1500 ' command delay in us
DEFINE LCD_DATAUS 44 ' data delay in us


'LED Connected to PortB.0 to circuit is doing something
LED var PORTB.6

CMCON = 7 'Turn off comparators
Pause 2000 ' Wait for LCD to startup

loop: toggle LED
Lcdout $fe, 1 ' Clear LCD screen
Pause 500 ' Wait .5 second
Lcdout "Greensasquatch" ' Display Greensasquatch on 1st line
Pause 500 ' Wait .5 second
toggle LED
Lcdout $fe,$c0,"Hello" ' move cursor to 2nd line, display Hello
Pause 1000 ' Wait 1 second
toggle LED
Lcdout $fe,$c0,"World" ' move cursor to 2nd line, display World
Pause 1000 ' Wait 1 second
toggle LED
Goto loop ' Do it forever

mackrackit
- 6th September 2008, 08:36
LCD4 TO RB4
LCD6 TO RB5
LCD11 TO RB0
LCD12 TO RB1
LCD13 TO RB2
LCD14 TO RB3

I think it is wierd wrong :)

Melanie
- 6th September 2008, 08:47
In no particular order...

1. Turn down the Contrast...

2. Double-Check your LCD wiring

3. Some LCD's need DB0-DB3 grounded to work in 4-Bit Mode.

4. Some LCD's need their R/W pin Grounded

5. Increase LCD_COMMANDUS to 2000 and LCD_DATAUS to 50 (values which seem to work with most LCD's).

6. Check your code is the same as that which you have posted... if you have a typo in the LCD DEFINEs it will not throw up an Error at compile time.

Archangel
- 6th September 2008, 10:05
Everything Melanie said, and bypass the LCD's power leads with an .01 &micro;F cap between them. I ran into a Display which wouldn't work otherwise, and it was attached to a 16F628A.

greensasquatch
- 6th September 2008, 18:05
Thanks for the help first of all.

I've rewritten the code and connections as per the example in the picbasic pro manual.

Works great on the 16F627A, now to port it over to the 16F88.

I'll post the results when it's done.

'************************************************* ***************
'* Name : LCDTest1.pbp *
'* Author : Greensasquatch *
'* Notice : Copyright (c) 2008 greensasquatch.ca *
'* : All Rights Reserved *
'* Date : 05/09/2008 *
'* Chip : PIC16F627A *
'* Version : 1.1 *
'* Notes : Send Hello World to a LCD on PORTB pins *
'* : blink a LED connected to RB6 as a status light *
'************************************************* ***************
'* PicBasicPro program to demonstrate *
'* operation of an LCD in 4-bit mode. *
'************************************************* ***************
'*
'* Connections are as follows:
'*
'* N/C -01-|####|-18- N/C
'* N/C -02-|####|-17- N/C
'* N/C -03-|####|-16- N/C
'* N/C -04-|####|-15- N/C
'* Gnd -05-|####|-14- V+
'* E on LCD on RB0 -06-|####|-13- RB7, LCD Pin DB7
'* RS on LCD on RB1 -07-|####|-12- RB6, LCD Pin DB6
'* N/C -08-|####|-11- RB5, LCD Pin DB5
'* red LED on RB3 -09-|####|-10- RB4, LCD Pin DB4
'*
'************************************************* ***************

INCLUDE "MODEDEFS.BAS"

@ DEVICE pic16F627A, INTRC_OSC_NOCLKOUT, MCLR_OFF

' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50


'LED Connected to PortB.3 to circuit is doing something
LED var PORTB.3
output PORTB.3

CMCON = 7 'Turn off comparators
Pause 2000 ' Wait for LCD to startup

loop: toggle LED
Lcdout $fe, 1 ' Clear LCD screen
Pause 500 ' Wait .5 second
Lcdout "Greensasquatch" ' Display Greensasquatch on 1st line
Pause 500 ' Wait .5 second
toggle LED
Lcdout $fe,$c0,"Hello" ' move cursor to 2nd line, display Hello
Pause 1000 ' Wait 1 second
toggle LED
Lcdout $fe,$c0,"World" ' move cursor to 2nd line, display World
Pause 1000 ' Wait 1 second
toggle LED
Goto loop ' Do it forever

greensasquatch
- 7th September 2008, 01:12
So I've now got a new problem, can you tell I'm a noob yet?

I've created a program now to make sure the 16F88 is working ok.

I load the program in to the pic, compile, burn and it works. LED flashes away merrily.

My problem now is that I can no longer reprogram the chip.

If I connect my JDM programmer to the serial port I can detect the programmer with PICPgm and if i then insert the chip I can detect it. BUT when I try to burn the new hex file it immediately says No chip found, and then no programmer found.

I'm wondering if it has something to do with using the RA6 and RA7 pins that are normally OSC pins. It almost seems like the programmer is fine until the PIC gets power and starts doing it's blink code. (just guessing, I'm really new at this and grasping at straws).

Any suggestions?

the code in case that helps:

'************************************************* ***************
'* Name : 88Blinker.pbp *
'* Author : Greensasquatch *
'* Notice : Copyright (c) 2008 *
'* : All Rights Reserved *
'* Chip : PIC16F88 *
'* Date : 06/09/2008 *
'* Version : 1.0 *
'* Notes : To set up the most basic settings to flash *
'* : an LED on a PORTB pin using only the internal *
'* : oscillator and MCLR turned off. *
'* : *
'************************************************* ***************
'*
'* Connections are as follows:
'*
'* RA2 -01-|######|-18- RA1
'* RA3 -02-|######|-17- RA0
'* RA4 -03-|######|-16- RA7 to LED
'* RA5 -04-|######|-15- RA6 to LED
'* Gnd -05-|######|-14- V++
'* RB0 -06-|######|-13- RB7
'* RB1 -07-|######|-12- RB6
'* RB2 -08-|######|-11- RB5
'* RB3 -09-|######|-10- RB4
'*
'************************************************* ***************

OSCCON = $60 'set int osc to 4mhz
ANSEL = 0 'ALL DIGITAL
CMCON = 7 'COMPARATORS OFF

TRISA = %00000000 'all output
TRISB = %00000000 'all output
PORTA = 0 'all porta low

@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
Pause 100 'wait to start

START:
High PORTA.6 'LED's on
High PORTA.7
Pause 1000
Low PORTA.6 'LED's off
Low PORTA.7
Pause 1000
GoTo START 'repeat

greensasquatch
- 7th September 2008, 06:42
I've been going over my code line by line. Finally found something odd. And I've come to the conclusion that this is the last time I copy lines from somebody else's code.

I'm sure the line <b>PROTECT_ON</b> is the reason i can no longer use this chip.

I got lazy and copied
@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
from someone else's 16f88 project without actually reading what it was set to do.

I'll have to wait until next week when my new 16F88 chips get here I think that one is now toast. Lesson learnt.

Thanks to everyone who helped, I'll post updates when I resume the project.

sinoteq
- 7th September 2008, 06:55
Hi
The chip you are using is a flash based PIC and it can be programmed many times. I don't think I have ever heard of a PIC that has been programmed too many times.

Your problem is a different one I think. Because you use INTRC_OSC and MCLR_OFF the internal Oscilator is used in the PIC and when you try to program the chip it has already started exectution of the internal Flash program you put there the first time. Your programmer can not access the chip in this case.


Please look at http://www.picbasic.co.uk/forum/showthread.php?t=5465
or http://www.picbasic.co.uk/forum/showthread.php?t=7616

and you see some more info about this problems.

skimask
- 7th September 2008, 06:55
I've been going over my code line by line. Finally found something odd. And I've come to the conclusion that this is the last time I copy lines from somebody else's code.

I'm sure the line <b>PROTECT_ON</b> is the reason i can no longer use this chip.

If PROTECT_ON is used, that means you can't READ the chip, doesn't mean you can't write to it.
ERASE the chip completely...then reprogram it...

skimask
- 7th September 2008, 07:04
Your problem is a different one I think. Because you use INTRC_OSC and MCLR_OFF the internal Oscilator is used in the PIC and when you try to program the chip it has already started exectution of the internal Flash program you put there the first time. Your programmer can not access the chip in this case.

Please look at http://www.picbasic.co.uk/forum/showthread.php?t=5465
or http://www.picbasic.co.uk/forum/showthread.php?t=7616

and you see some more info about this problems.

Hey...Good Point!
I especially like post #12 of the 2nd link...
Seems like I end up suggesting the same thing over and over again...

greensasquatch
- 7th September 2008, 07:36
Sinoteq,
thanks for the links. I'm thinking I should stop being so cheap and just get a programmer from microchip now. This JDM just doesn't seem to do everything I want it to do.

Skimask,
I have erased the chip using WinPic (or at least winpic thinks it's erasing the chip, I get no errors) but when i try to reprogram I get verify errors.

I'm going to go back to tinkering with my 16F627A's and RF for a while until I get another 16F88. I'll stay away from using INTRC_OSC and MCLR_OFF together for now.

At least I know what happened to my 12F675's now, too bad I bent the pins and tossed them.

You guys are great, thanks again.

skimask
- 7th September 2008, 08:23
I'm thinking I should stop being so cheap and just get a programmer from microchip now.
You won't be sorry when you get it... I can guarantee it...


Skimask,
I have erased the chip using WinPic (or at least winpic thinks it's erasing the chip, I get no errors) but when i try to reprogram I get verify errors.
I think that 1st link in post 11 above has the information you need to modify your programmer to get it all to work.


At least I know what happened to my 12F675's now, too bad I bent the pins and tossed them.
Drill holes in them and turn them into geek jewelry! :)

Archangel
- 7th September 2008, 09:26
Sinoteq,
thanks for the links. I'm thinking I should stop being so cheap and just get a programmer from microchip now. This JDM just doesn't seem to do everything I want it to do.

Skimask,
I have erased the chip using WinPic (or at least winpic thinks it's erasing the chip, I get no errors) but when i try to reprogram I get verify errors.

I'm going to go back to tinkering with my 16F627A's and RF for a while until I get another 16F88. I'll stay away from using INTRC_OSC and MCLR_OFF together for now.

At least I know what happened to my 12F675's now, too bad I bent the pins and tossed them.

You guys are great, thanks again.
I have 2 JDM programmers, they are different from one another, on each of them, printed on the circuit board is the orientation of the pic chips and location, As I said, they are WAY different in respect to each other. as far as issues of MCLR on/off, INTRC vs HS, xt . . . NONE. The issue I seem to have is one of them the ZIF socket is beginning to wear (the Plating) and I got tired of having to wiggle the chips before programming, that's why I have 2. #2 came in the mail today, works fine so far using ICProg.

skimask
- 7th September 2008, 09:31
The issue I seem to have is one of them the ZIF socket is beginning to wear (the Plating) and I got tired of having to wiggle the chips before programming, that's why I have 2. #2 came in the mail today, works fine so far using ICProg.

Why not swap out the ZIF socket?

Archangel
- 7th September 2008, 10:02
Why not swap out the ZIF socket?
Doable, 18 bucks delivered from CA now I have a backup. I have not yet figured out how to program 18f4550 with these, I think my PC serial port is too weak, the new programmer has a 12v input which can be jumpered in, I will try that next, and I think there is a PICKIT2 in my future, depends if my sometimes employer has caught sight of the payroll fairy, till then wallet goes under the pillow :D
EDIT: 12v did not do it either.

mackrackit
- 7th September 2008, 10:50
When I use my PicStart+ with 18s, I have to add a 22uf cap between the VDD and VSS, most time just on one side will do. Bit of a pain in the ziff. But the adapter for ICSP has them built in.

tenaja
- 7th September 2008, 16:16
...
I have erased the chip using WinPic (or at least winpic thinks it's erasing the chip, I get no errors) but when i try to reprogram I get verify errors.

I'm going to go back to tinkering with my 16F627A's and RF for a while until I get another 16F88. I'll stay away from using INTRC_OSC and MCLR_OFF together for now.

I have an MELabs programmer, and I've been very happy with it. The tech support is great, too. I had a chip with the same issue as you, so I called and asked about it. They said that the programmer relies on MCLR to program it--and since you turned it off, there is an issue. If you need to make that pin an output, you need a 1-2 second delay before setting the Tris. This might not be your exact issue since some of your settings were pasted from elsewhere, but it is something to keep in mind.

BTW, it's nice when the tech support for your hardware and software come with the same phone call.