If you dont have outnumbering pin issues then go with 10bit. you can measure up to 102.4V---> 0.1V per bit. If you want to work with its 8 pins then 5/1024 = 4.8828 mV per bit, multiplying it by 256 gives 1.25V. So now you have to build you voltage division network so that it gives 1.25V at 30V. Your problem would be solved.
But if you are using external ADC then using 8bit ADC would reduce your effort and expense.
What 10Bit ADC you are using?
Buitlt in using pic16F676
Romel:
i also made a rpm counter for a diesel testing machine but i used a sensor the small industry owner give me calls proximity sensor price in Pakistan $2 . But he dont know that i didn't know electronics at all actually i made a digital speed o meter for my bike with youtype optocoupler counting rpm and speed and trip distance and odo metre. I wan testing it in football ground. He was also there . he saw that readings were matched with the real bike metre so he asked one design for him as he used china made rpm counter. So i made one for him with lcd and also give him the .hex file only in so much low money. He is happy that he made me fool and got unlimited rpm counter in just half price of one but i am happy that my rpm meter are exporting to UAE. and it is working proper as i have visit his factory :twisted:
Here is the first code i use for my speedo metre may be it is not the final as i have not ever made a proper record of my hobbies
processor PIC16F676
#include <p16f676.inc>
__config _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF
d1 equ 21h
d2 equ 22h
d3 equ 23h
r1 equ 24h
; Binary To Decinal Locations
o1 equ 25h
o10 equ 26h
o100 equ 27h
t1 equ 28h
w2 equ 29h
L_byte equ 2A
H_byte equ 2B
aac0 equ 2C
aac1 equ 2D
aac2 equ 2E
aac3 equ 2F
aac4 equ 30
;MUL Locations
mulcnd equ 31h ; 8 bit multiplicand
mulplr equ 32h ; 8 bit multiplier
stmr equ 33h
;H_byte equ High byte of the 16 bit result
;L_byte equ Low byte of the 16 bit result
Same equ 34h
org 0x00
goto main
org 0x04
goto int
main:
banksel ANSEL
movlw B'00000000'
movwf ANSEL
banksel CMCON
movlw d'7'
movwf CMCON
banksel PORTA
clrf PORTA
banksel TRISA
movlw b'00000100'
movwf TRISA
banksel PORTC
clrf PORTC
banksel TRISC
clrf TRISC
InitializeLCD:
banksel PORTC
bcf PORTC , 2
call t10ms
movlw d'56'
movwf r1
call serout
call t10ms
movlw d'56'
movwf r1
call serout
call t10ms
movlw d'56'
movwf r1
call serout
call t10ms
movlw b'00111000'
movwf r1
call serout
call t10ms
movlw B'00001000'
movwf r1
call serout
call t10ms
movlw b'00000001'
movwf r1
call serout
call t10ms
movlw b'00000010'
movwf r1
call serout
call t10ms
movlw b'00001100'
movwf r1
call serout
call t10ms
Start_LCD_DATA:
bsf PORTC , 2
movlw 'S'
movwf r1
call serout
movlw 'p'
movwf r1
call serout
movlw 'e'
movwf r1
call serout
movlw 'e'
movwf r1
call serout
movlw 'd'
movwf r1
call serout
movlw ' '
movwf r1
call serout
bcf PORTC , 2
movlw d'139'
movwf r1
call serout
bsf PORTC , 2
movlw ' '
movwf r1
call serout
movlw 'k'
movwf r1
call serout
movlw 'm'
movwf r1
call serout
movlw '/'
movwf r1
call serout
movlw 'h'
movwf r1
call serout
bcf PORTC , 2
movlw d'192'
movwf r1
call serout
bsf PORTC , 2
movlw ' '
movwf r1
call serout
movlw 'r'
movwf r1
call serout
movlw 'p'
movwf r1
call serout
movlw 'm'
movwf r1
call serout
movlw ' '
movwf r1
call serout
bcf PORTC , 2
movlw d'203'
movwf r1
call serout
bsf PORTC , 2
movlw ' '
movwf r1
call serout
movlw ' '
movwf r1
call serout
movlw 't'
movwf r1
call serout
movlw 'd'
movwf r1
call serout
bcf PORTC , 2
movlw 04h
movwf r1
call serout
Timers:
banksel OPTION_REG
bsf OPTION_REG , 5
bcf OPTION_REG , 4
bsf OPTION_REG , 3
banksel INTCON
bsf INTCON , 7
bsf INTCON , 6
banksel PIR1
bcf PIR1 , 0
banksel PIE1
bsf PIE1 , 0
banksel T1CON
bcf T1CON , 6
bsf T1CON , 4
bsf T1CON , 5
bcf T1CON , 3
bcf T1CON , 1
movlw B'11011100'
movwf TMR1L
movlw B'00001011'
movwf TMR1H
bsf T1CON , 0
goto fin
table:
addwf PCL , f
retlw d'48'
retlw d'49'
retlw d'50'
retlw d'51'
retlw d'52'
retlw d'53'
retlw d'54'
retlw d'55'
retlw d'56'
retlw d'57'
fin:
goto fin
int:
movf TMR0 , 0
movwf stmr
bcf T1CON , 0
movlw B'11011100'
movwf TMR1L
movlw B'00001011'
movwf TMR1H
clrf TMR0
bsf T1CON , 0
bcf PIR1 , 0
bcf PORTC , 2
movlw d'202'
movwf r1
call serout
bsf PORTC , 2
movf stmr , 0
movwf L_byte
movlw d'60'
call multiply
movf aac0 , 0
call table
movwf r1
call serout
movf aac1 , 0
call table
movwf r1
call serout
movf aac2 , 0
call table
movwf r1
call serout
movf aac3 , 0
call table
movwf r1
call serout
movf aac4 , 0
call table
movwf r1
call serout
bcf PORTC , 2
movf stmr , 0
movwf L_byte
movlw d'6'
call multiply
movlw d'138'
movwf r1
call serout
bsf PORTC , 2
movf aac0 , 0
call table
movwf r1
call serout
movlw '.'
movwf r1
call serout
movf aac1 , 0
call table
movwf r1
call serout
movf aac2 , 0
call table
movwf r1
call serout
movf aac3 , 0
call table
movwf r1
call serout
retfie
t10ms:
movlw 0xCE
movwf d1
movlw 0x08
movwf d2
t10ms_0
decfsz d1, f
goto $+2
decfsz d2, f
goto t10ms_0
goto $+1
nop
return
serout:
movlw 0x08
movwf d3
testbit:
bcf PORTC , 4
btfsc r1 , 7
bsf PORTC , 4
bsf PORTC , 3
bcf PORTC , 3
rlf r1 , f
decfsz d3 , f
goto testbit
bsf PORTC , 5
bcf PORTC , 5
return
decimal:
swapf L_byte,w
addwf L_byte,w
andlw 0x0f
skpndc
addlw 0x16
skpndc
addlw 0x06
addlw 0x06
skpdc
addlw -0x06
btfsc L_byte,4
addlw 0x15+0x06
skpdc
addlw -0x06
movwf aac0
swapf H_byte,w
addwf H_byte,w
andlw 0x0f
skpndc
addlw 0x16
skpndc
addlw 0x06
addlw 0x06
skpdc
addlw -0x06
btfsc H_byte,0
addlw 0x05+0x06
skpdc
addlw -0x06
btfsc H_byte,4
addlw 0x15+0x06
skpdc
addlw -0x06
addlw 0x06
addwf aac0,w
skpdc
addlw -0x06
movwf aac0
movwf aac1
swapf aac1,f
movlw 0x0f
andwf aac0,f
andwf aac1,f
rrf H_byte,w
andlw 0x0f
addlw 0x06
skpdc
addlw -0x06
addlw 0x06
addwf aac1,w
skpdc
addlw -0x06
btfsc L_byte,5
addlw 0x03+0x06
skpdc
addlw -0x06
btfsc L_byte,6
addlw 0x06+0x06
skpdc
addlw -0x06
btfsc L_byte,7
addlw 0x12+0x06
skpdc
addlw -0x06
btfsc H_byte,0
addlw 0x25+0x06
skpdc
addlw -0x06
btfsc H_byte,5
addlw 0x09+0x06
skpdc
addlw -0x06
btfsc H_byte,6
addlw 0x08+0x06
skpdc
addlw -0x06
btfsc H_byte,7
addlw 0x06+0x06
skpdc
addlw -0x06
movwf aac1
swapf aac1,w
andlw 0x0f
btfsc H_byte,1
addlw 0x05+0x06
skpdc
addlw -0x06
btfsc H_byte,5
addlw 0x01+0x06
skpdc
addlw -0x06
btfsc H_byte,6
addlw 0x03+0x06
skpdc
addlw -0x06
btfsc H_byte,7
addlw 0x07+0x06
skpdc
addlw -0x06
movwf aac2
swapf aac2,w
movwf aac3
movlw 0x0f
andwf aac1,f
andwf aac2,f
andwf aac3,f
rrf H_byte,w
movwf aac4
rrf aac4,w
andlw 0x0f
addlw 0x06
skpdc
addlw -0x06
addlw 0x06
addwf aac3,w
skpdc
addlw -0x06
btfsc H_byte,6
addlw 0x16+0x06
skpdc
addlw -0x06
btfsc H_byte,7
addlw 0x32+0x06
skpdc
addlw -0x06
movwf aac3
movwf aac4
swapf aac4,f
movlw 0x0f
andwf aac3,f
andwf aac4,f
return
multiply:
mult MACRO
btfsc STATUS,C
addwf H_byte,F
rrf H_byte,F
rrf L_byte,F
ENDM
clrf H_byte ;* 1 cycle
rrf L_byte,F ;* 1 cycle
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
call decimal
end
---------- Post added at 07:54 ---------- Previous post was at 07:49 ----------
i have stolem binary to decimal and multiplying routines from PICLIST web ;-)
But i dont know how he is using this negative signs in mathematics -0x06 etc
Is it possible to use minus or nagative digits as -255 or -250
and can i use 2.50 or -2.65
as i have used the point with in my speed calculation manually
addlw -0x06
movwf aac0
swapf H_byte,w
addwf H_byte,w
andlw 0x0f
skpndc
addlw 0x16
skpndc
addlw 0x06
addlw 0x06
skpdc
addlw -0x06
btfsc H_byte,0
addlw 0x05+0x06
---------- Post added at 07:54 ---------- Previous post was at 07:54 ----------
and what is mult?
i cant find this mult instruction in PIC data sheet????????:sad: