PDA

View Full Version : ADC trouble with PIC16F88



inventosrl
- 30th November 2008, 09:40
Hello all, :confused:

I'm newbie, the goal of my project it's to use only RA0 in ADC mode and
the rest of TRISA in a digital input but, in this setting don't work.

Any help will be appreciated.

Thanks a lot and regards

giorgio

The Code :

'************************************************* ***************
'* Name : CONTROLLER.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 26/11/2008 *
'* Version : 1.0 *
'* Notes : *
'* Chip : PIC16F88 *
'************************************************* ***************
INCLUDE "MODEDEFS.BAS"
define OSC 4
adval VAR BYTE
i var BYTE
RPM VAR BYTE




ADCON0.7 = 1 ' right justify result
ANSEL = %00000001 ' set AN0 analog, rest digital
CMCON = 7 ' analog comparators off

TRISA = %00001111 'RA.0:3 Input
TRISB = %00000000 'all PORTB output

Output PORTB.4 ' set RB0 as output
Output PORTB.5 ' set RB1 as output

loop:
ADCIN 0,adval
IF adval < 90 THEN
HIGH PORTB.4
endif

IF adval > 100 THEN
LOW PORTB.4
endif

COUNT PORTA.2,250,RPM
for i = 1 to rpm
toggle PORTB.5
PAUSE 25
NEXT i
LOW PORTB.5
GOTO loop 'repeat

mikendee
- 30th November 2008, 10:11
Hi and welcome,

The code appears to be okay to me ( another newbie).
You don't need these lines as you already set TRISB = 0
Output PORTB.4 ' set RB0 as output
Output PORTB.5 ' set RB1 as output

I just wondered if you have a resister on RA0 to limit the current into the pin.
If you don't you may damage the PIC.
Hope this may help.

Mike

mackrackit
- 30th November 2008, 11:01
Howdy,

This


ADCON0.7 = 1 ' right justify result

should be


ADCON1.7 = 1 ' right justify result

This may help also
http://rentron.com/PIC12C67XAD.htm
Different PIC, same type of ADC.

inventosrl
- 30th November 2008, 21:40
Hi and welcome,

The code appears to be okay to me ( another newbie).
You don't need these lines as you already set TRISB = 0
Output PORTB.4 ' set RB0 as output
Output PORTB.5 ' set RB1 as output

I just wondered if you have a resister on RA0 to limit the current into the pin.
If you don't you may damage the PIC.
Hope this may help.

Mike

Thanks , it was a mistake

inventosrl
- 30th November 2008, 21:43
Howdy,

This


ADCON0.7 = 1 ' right justify result

should be


ADCON1.7 = 1 ' right justify result

This may help also
http://rentron.com/PIC12C67XAD.htm
Different PIC, same type of ADC.

Hello Dave, thanks a lot, but the very big problem it's the IC-PROG and JDM Programmer, that apparently don't give any error but the PIC is not programmed.
Tomorrow try to unreverse the serial communications signal in the JDM section.

TNX
giorgio

mackrackit
- 30th November 2008, 21:56
Save your headaches and look to getting a PICKIT2 from MicroChip.

inventosrl
- 2nd December 2008, 18:11
Save your headaches and look to getting a PICKIT2 from MicroChip.

Hello Dave,
pickit buyed and running, I've too mounted a 18 pin in a board connected with the ICSP signal.
It's all ok with pic 16f628, but with 18f88 have this alarm message
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2744&stc=1&d=1216305160

The code :
'************************************************* ***************
'* Name : CONTROLLER.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 26/11/2008 *
'* Version : 1.0 *
'* Notes : *
'* Chip : PIC16F88 *
'************************************************* ***************
INCLUDE "MODEDEFS.BAS"
TRISA = %11111111 'RA.0:3 Input
TRISB = %00000000 'all PORTB output

ANSEL=%00000001'only porta.0 is analogue
ADCON1=%00000010'right justify the result(top bits are read as zero)
CMCON = 7 'Turn off comparators

adval VAR BYTE
i var BYTE
RPM VAR BYTE

' Define ADCIN parameters
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
PAUSE 500

loop:
ADCIN 0,adval

serout PORTB.6,n2400, [$FE, 1]
serout PORTB.6,n2400, [$FE, 2, "pressione ", #adval]
serout PORTB.6,n2400, [$FE, $C0, "giri", #rpm]

IF adval < 90 THEN
HIGH PORTB.4
endif

IF adval > 120 THEN
LOW PORTB.4
endif

COUNT PORTA.2,250,RPM
for i = 1 to rpm
toggle PORTB.5
PAUSE 25
NEXT i
LOW PORTB.5
GOTO loop 'repeat

Any help will be apreciated,
Thanks a lot

giorgio

mackrackit
- 2nd December 2008, 22:10
Can you post you inc file with the config settings?

inventosrl
- 2nd December 2008, 22:24
Hi Dave , I'm at home now, but have the original one from MPASM 8.10 ans pbc Pro 2.50. MicoCode Studio Plus last release.

Tomorrow (now it's 23,20 pm) I'll post the file.

tnx

inventosrl
- 3rd December 2008, 12:56
Hi Dave , I've posted the files in a PicBasicPro forum:


http://www.picbasic.co.uk/forum/showthread.php?t=10207