| Author |
Message |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
04 Nov 2006 9:02 pic voltage meter |
|
|
|
|
Hello Everyone,
Im looking for any suggestions for a PIC Controlled DVM to read Voltage (0-30vdc) & Current (0-10A).... I have on hand some PIC16F84's and some TLC0831 ADC's I need some help on code (assembly) any ideas or links out there???
|
|
| Back to top |
|
 |
Kripton2035
Joined: 19 Jul 2001 Posts: 587 Helped: 20 Location: Earth
|
04 Nov 2006 10:03 pic current meter |
|
|
|
|
| take a look at application note AN557 from microchip...it should help a lot !
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
04 Nov 2006 11:52 pic volt meter |
|
|
|
|
I have designed and built my own using a PIC18F4520 runnig at 20Mhz ans it's for 4 chanels 2 x volts 0-50V and 0-10A 0.02mv +/- readings
I ma in the process of laying out PCB for it has it has got to be right becasue of nosie which would affect the readings
But i have donw it in Proton Plus (basic)
wizpic
|
|
| Back to top |
|
 |
alec82
Joined: 25 Oct 2006 Posts: 215 Helped: 65
|
05 Nov 2006 7:51 pic amp meter |
|
|
|
|
hi
for reduce nois you can a simple low pass filter in input &use capacitor near power pin of micro
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
06 Nov 2006 9:27 pic ampmeter |
|
|
|
|
| Hey everyone.... Well, I got the project working somewhat. I have the PIC reading the two ADC's and displaying the reading as Vdc on the top line and Adc on the lower line... But, the problem I'm having is displaying the reading with 10ths Right now it displays Vdc=5.0 I would like to display Vdc=5.00 I dont know much about Binary to BCD conversion and how to display it.... Anyone have any Assembly code I could look at to figure it out??? Thanks
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
07 Nov 2006 8:22 pic volt amp meter |
|
|
|
|
Hey Everyone... I found a routine for Binary to BCD and I cant figure out how to get the 1's 10's 100's to be displayed any ideas???? Right now I have it displaying 1's and 10's....
;*******************************************************************
; Binary to BCD Converter
;
; Input: Two bytes of RAM; L_Byte, H_Byte
; Output: Three bytes of RAM; R0, R1, R2
;
; Usage: Put value into L_Byte and H_Byte, call B2_BCD, result in
; R2 is LSD and R1 is MSD: Four digits (nibbles) in 2 bytes
; Lower 4 bits of LSD are least sig. digit, upper 4 are 2nd
; digit.
;*******************************************************************
B2_BCD
bcf STATUS,0 ;Clear carry bit
movlw .16
movwf count ;Set counter to 16
clrf R0
clrf R1
clrf R2
loop16
rlf L_Byte
rlf H_Byte
rlf R2
rlf R1
rlf R0
decfsz count
goto adjDEC
RETLW 0
adjDEC
movlw R2
movwf FSR
call adjBCD
movlw R1
movwf FSR
call adjBCD
movlw R0
movwf FSR
call adjBCD
goto loop16
adjBCD
movlw 3
addwf 0,W
movwf B2temp
btfsc B2temp,3 ;Test if result > 7
movwf 0
movlw 30
addwf 0,w
movwf B2temp
btfsc B2temp,7 ;Test if result > 7
movwf 0 ;Save as MSD
RETLW 0
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
08 Nov 2006 5:31 volt meter pic |
|
|
|
|
| Hey Everyone! Well, Im having fun trying to figure out how to get 4 digits from and 8 bit ACD. Im wondering if it is even possible? What I am doing is I want to use some old parts I have laying around ( PIC 16F84 and ADC0831 ) and make an LCD Volt and Amp Meter. So far I figured out how to read the two ADC's and display the voltages on the LCD. The problem is that it only displays 1.0 for 1v and 10.0 for 10volt ect ect I would like to make it more pricession such as 1.00v and 10.00 volts or better....
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
08 Nov 2006 7:19 volt amp meter lcd |
|
|
|
|
I'm Not sure that you can get 4 digit reading using 8Bit you might be able to but it would not be pricession as you would like it to be 10bit would be a little bit better.
I get 4difit's with mine and i can even get 5digits with my routine but as i said it's in basic
have fun
wizpic
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
10 Nov 2006 0:22 voltage meter pic |
|
|
|
|
| Hello all! Well I decided to go with another PIC.... I have a PIC16F677 sitting around and noticed that it has Analog PORTS built in so here I am.... The problem is I cant figure out how to configure the ports for digital or analog use? I went over the data sheet for the 16f677 but no luck.... It only shows an example of how to config for digital I/O use only.... Does anyone have an example that I could go by???
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
20 Nov 2006 20:42 pic ac current meter |
|
|
|
|
| Hey WizPic, would you mind letting me know how you took the current measurements??? Or a schematic??? Right now I have a 16F676 Reading 2 ADC's and displaying the results V=xx.xxxVdc and C=xx.xxA ( voltage ) on an 16 x 2 LCD I was thinking of using an op amp to measure the voltage drop across a shunt resistor???
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
20 Nov 2006 23:52 ampmeter pic |
|
|
|
|
Here you go the volatge mesurement dvides the input voltage and the current mesurement times the voltage which goes across the shunt resistor but you may have to paly a round with the values fisrt befor you connect it up to the pic
I done this one some time ago and can't remember what teh voltage was
the current part shuod be ok though but it gives youa basic idea
wizpic
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
21 Nov 2006 19:27 lcd volt amp meter |
|
|
|
|
| Hey Everyone! Yet another question.... I never really messed around with math with a uC.... I want to take the ADC readings stored in H_Byte_2, L_Byte_2 & H_Byte_3, L_Byte_3 and subtract to get the voltage drop across my shunt resistor and then divide that from the resistance of the shunt (.150 Ohms) to get the Current in AMPS..... Is that even possible???? Thanks!
|
|
| Back to top |
|
 |
roykyn
Joined: 15 Sep 2006 Posts: 254 Helped: 7
|
21 Nov 2006 20:39 current meter pic |
|
|
|
|
do u want to do it using pic....instead use a less expensive ic like icl7106/7107....
this can measure from 0 to 200 milli volts....wat is the use rt.....use a resistor divider to read large voltage......measure voltage across a .1Ω resistor to get current flowing through the ckt....i am suggesting this because a 10 bit adc changes every 5 milli volt...hence for a 0-30v the sensitivity will be 30milli V ....it means the reading changes every 30 milli volt....if its 8 bit then .11 V....
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
22 Nov 2006 0:52 volts and amps glcd |
|
|
|
|
| Yes, I would like to us a PIC because I want to display it on a LCD with high and low limits... So far, I have the PIC measuring the voltage across the shunt resistor with 2 ADC ports and subtracting the two adc results... Now I need to figure out how to divide that number by .15 ohms to get the current.... C=V/R.... Any PIC Math Wiss's out there willing to help???
|
|
| Back to top |
|
 |
csaba411
Joined: 15 Jun 2006 Posts: 37 Helped: 4
|
22 Nov 2006 2:32 pic16* amper meter |
|
|
|
|
OK
Here you go
v1---/\/\/\/\---v2
3.35v............3.15v
The different between v1 and v2 is 200mv
Lets say you using the PIC VCC for reference "5V"
10 bit ad 5/1024 =0.0048828125
Each step is equal with 0.0048828125 volt
So if you read 512 from you AD registers, that will be 512*0.0048828125=2.5V
Floating point math would be to hard on you, so scale it up and round it.
Make each step to be 488 instead of the 0.0048828125.
Then again if you read 512 form your AD register's multiply it with 488.
512*488=249856 uV, the error is ~0.5%, isted of 250000 uV
On your ADCH0 you will get 686 in the AD registers, and for ADCH1 you get 645
the different is 686-645=41, now multiply this 41 with 488 and you get 20008.
That is very close to the real value of 20000 uV.
Now divide this 20008 uV with the upscaled resistor value of 15, it is 100 times more than the actual resistance.
So 20008/15=1333.86, now divide it by 1000 or move you decimal point 3 digit to the left, and you get 1.333 A
If you AD register different is 1 then, ((1*488)/15)/1000 or move decimal 3 times to the left. equal 0.032 Amp, in the real life the current is 0.032552083 Amp.
As you can see, the resolution is 32mA
Now if you need higher precision, and you maximum current is low, then you can use different voltage divider on the ADCH1 to make it 10*more than ADCH0.
This way you can get 3.2mA resolution.
There is many free examples of 16,24,32 bit math asm code out there, find them and use them.
If I'm wrong about this or you did not get it, "SORRY"
I'm just a human
Csaba
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
22 Nov 2006 10:54 ampere meter with pic |
|
|
|
|
| Okay Thanks for your help Csaba... I will search the web for the math routines. That is where I am having the most trouble with learning. It would be great to see some assembly examples of code for the process that you describe... It makes since of how to do it but, I have no idea of writing the code for math functions.....
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
22 Nov 2006 18:08 voltage meter with pic |
|
|
|
|
Try this code it's a 64bit maths routine and gives very close results i was given it but never tried has i use basic but i have been told that it works well when included
'ADC must ge set to right Justify
ADmain ;main loop for ADC
clrf OutBuff
clrf OutBuff1
clrf cnt
movlw 0x40 ;set counter to 64
movwf cnt
st
decf cnt
bsf ADCON0,GO ;start A/D
l3
btfsc ADCON0,GO ;A/D conversion done
goto l3
bsf STATUS,RP0 ;select bank 1
movfw ADRESL
bcf STATUS,RP0 ;select bank 0
addwf OutBuff1
btfsc STATUS,C
incf OutBuff
movfw ADRESH
addwf OutBuff
movf cnt
btfss STATUS,Z
goto st
return
try it and let us know
If you tell me what your pin configuration are for ADIN put nas LCD i will send you hex file to try on your curcuit and see if that's close enough for you
wizpic
|
|
| Back to top |
|
 |
roykyn
Joined: 15 Sep 2006 Posts: 254 Helped: 7
|
22 Nov 2006 19:46 epe volt amper meter |
|
|
|
|
| use c compilers like ccs c ..htpic and many more .....u can do a lot of complex calculations easily
|
|
| Back to top |
|
 |
csaba411
Joined: 15 Jun 2006 Posts: 37 Helped: 4
|
23 Nov 2006 3:43 amper+volt meter lcd |
|
|
|
|
That code is not a 64bit math, what is a loop to sample the AD input 64 times and add their value together.
As the end result will be a much more accurate representative of the real measurement . It used to get higher resolution of from a low resolution AD.
For example:
You are reading a not so stable signal, your AD reading will jump betwen 200 and 205 and 210 and 195, 10 times a second. You will see the last digit rolling as crazy .
If you sample the AD reading 10 times and display their final value on the end you will get the average value of the signal.
200+205+210+195+......../10=202.1
This way you are also gain one extra bit !
Csaba
|
|
| Back to top |
|
 |
Google AdSense

|
23 Nov 2006 3:43 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
23 Nov 2006 10:19 pic16 ампер метер |
|
|
|
|
| Ok, thanks everyone for all the help... I think I am making some progress and the only thing I need to figure out is how to divide the subtracted result from the adc's by the value of the shunt resistor of .15ohms to get the actual current ( C=V/R )..... all of the division examples that I have found on the web seems complex and I cant figure it out.....
|
|
| Back to top |
|
 |
Fragrance
Joined: 26 Jul 2002 Posts: 1385 Helped: 24
|
23 Nov 2006 13:40 avr volt amp meter |
|
|
|
|
hi
here is voltmeter based on pic16F84a and all sources asm file proteus simulation for for your help
regards
Fragrance
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
24 Nov 2006 8:32 lcd amp/volt meter |
|
|
|
|
| Ok..... I am having way too much trouble figuring out this math stuff lol..... Anyone have any assembly code for C=V/R ???????????? where V is stored in L_Byte_3 & H_Byte_3 and R is 15 or .15 Ohms (Shunt)?????? Any help here would be great!!!!
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
25 Nov 2006 4:59 amp hora meter pic |
|
|
|
|
you should try Proton Plus (picbasic) it's very easy to understand and use
You need to multiply your voltage first because normaly you only get millivolts drops across the shunt resistor this is to small for pic to mesure it
has i said before i done it in basic but you want asm but try picbasic you will be supprised how easy it is
wizpic
|
|
| Back to top |
|
 |
csaba411
Joined: 15 Jun 2006 Posts: 37 Helped: 4
|
25 Nov 2006 20:59 pic volt meter assembler code |
|
|
|
|
If you buy yourself a F877A or *876, I'll send you the hex for it.
Can't give you the source codes, it part of a project we have done in the past.
csaba
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
26 Nov 2006 1:15 pic tester voltage |
|
|
|
|
| Hey csaba, you think that you could please send the source for just the math???? lol or some more hints???? thank you!
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
29 Nov 2006 4:25 pic voltmeter converting a/d to bcd |
|
|
|
|
Hey Everyone! Math was never my good subject in school lol lol I have another question..... I found some routines to use for my math ( shown below ) I cant figure out witch one of the IN: is MSB and LSB right now I have result1 MSB, result0 LSB, multiplicand0 LSB, multiplicand1 MSB outputs: result3 MSB result2 result1 result0 LSB the number I want to multiply by is 488...... on the division same thing. What ones are MSB and LSB?????? I need to divide the multiply result by 15. Also I wanted to thank everyone for all of the input and helping!!!!
;; 16x16 -> 32 signed multiply.
;;
;; IN: multiplier in result1:0, multiplicand in multiplicand1:0
;; OUT: product in result3:0
;;
;; Requires a single scratch variable counter, assumes that all variables
;; are in the currently selected bank.
;;
multiply
clrf result3
clrf result2
bcf STATUS,C
rrf result1, F
rrf result0, F
movlw 16
movwf counter
top
btfss STATUS,C
goto dontAdd
movf multiplicand0, W
addwf result2, F
btfsc STATUS,C
incf result3, F
movf multiplicand1, W
addwf result3, F
dontAdd
bcf STATUS, C
rrf result3, F
rrf result2, F
rrf result1, F
rrf result0, F
decfsz counter, F
goto top
return
;------------Divide---------
divide
movlw 32 ; 32-bit divide by 16-bit
movwf bitcnt
clrf remdrH ; Clear remainder
clrf remdrL
dvloop clrc ; Set quotient bit to 0
; Shift left dividend and quotient
rlf result0 ; lsb
rlf result1
rlf result2
rlf result3 ; lsb into carry
rlf remdrL ; and then into partial remainder
rlf remdrH
skpnc ; Check for overflow
goto subd
movfw divisH ; Compare partial remainder and divisor
subwf remdrH,w
skpz
goto testgt ; Not equal so test if remdrH is greater
movfw divisL ; High bytes are equal, compare low bytes
subwf remdrL,w
testgt skpc ; Carry set if remdr >= divis
goto remrlt
subd movfw divisL ; Subtract divisor from partial remainder
subwf remdrL
skpc ; Test for borrow
decf remdrH ; Subtract borrow
movfw divisH
subwf remdrH
bsf divid0,0 ; Set quotient bit to 1
; Quotient replaces dividend which is lost
remrlt decfsz bitcnt
goto dvloop
return
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
30 Nov 2006 0:54 adc-result in floating point pic24 |
|
|
|
|
| Got another one here.... Do you need to do the math before you display the result? I have been just reading to ADC, converting binary to bcd and displaying it???? also wich way should I "Justify" the ADC result Right or Left??? when I make it right justified the lcd displays .193v and when I left justify it displays 12.35V
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
30 Nov 2006 1:57 pic16f88 voltage meter |
|
|
|
|
I normally right justify in my code,
But you have not said what the volatge is going into the PIC, If it's 1.235V then i geuss your right on justify left but if it's 1.235V on justify right then it is not ocrrect you need to redo your maths,
not usre how you set it up in ASM but here is the basic it's this ADCON1 = %10100010 'Right justify & Use +VREF
I think loking at my ASM code window it like this
equ $ ; in ADCON1 = %11100010 ' Set PORTA analog and right justify result
Movlw 226
Movwf ADCON1,0
From what i am reading and my understanding you want to mesaure 0-10amp but you do not say what voltage you are reading
Is it the volt side or amp side your not getting correct readings, you need to measure the voltage goiong into PIC and compare agaisnt your reading on lcd 1.235V into pic times this by 10 you will get 12.35v like you are getting
sounds like you are getting there slowly and i bet you have lernt alot too by playing
wizpic
|
|
| Back to top |
|
 |
chevymn1964
Joined: 01 Apr 2006 Posts: 112 Helped: 2
|
30 Nov 2006 22:09 f meter with pic |
|
|
|
|
| Well, what I'm trying to ask is if you should do the math before you display the result ( ADC Result X 488 / 100= Volts ).... Right now I am reading the ADC, converitng to BCD and displaying to the LCD but it is not very accurate within 200-300mv of the actual voltage... I would like to get down to 1mV ( 12.251V ) and be able to measure 0-30v range. I dont know if that is possible with a 10 bit ADC??? When I try to do the math the results get very strange on the LCD... What I am quessing is the ADC result is in 2 bytes (ADRESH and ADRESL) and multiply with 488 (2 byte number) then the result is in 4 bytes then divide by 100 and you get your 2 byte result, convert to bcd and display??? Im I right so far??? Im getting grey haires like crazy trying to figure this out!!! lol lol
|
|
| Back to top |
|
 |
wizpic
Joined: 23 May 2004 Posts: 380 Helped: 26
|
30 Nov 2006 22:59 amp and voltmeter pic 16f877a |
|
|
|
|
To Be honest i think you would struggle to get it down to 1mV , with 10Bit A/D 200-300Mv is very good, even with my routine that i use i can only get it to 50-150mv over 0-30Volt range, You will find it's good at the low end and quite out at the high end or visa a versa,
I think you will have to settle for the midrange and live wiht it,
My hair fell out and went gray years ago so i don't have to worry anymore LOL
good luck
wizpic
|
|
| Back to top |
|
 |