Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC Volt & Amp Meterattin6

Status
Not open for further replies.
avr volt amp meter

hi

here is voltmeter based on pic16F84a and all sources asm file proteus simulation for for your help

regards
Fragrance
 

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!!!!
 

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
 

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
 

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!
 

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
 

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
 

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 :D

sounds like you are getting there slowly and i bet you have lernt alot too by playing :D

wizpic
 

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
 

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
 

pic16f volt and amper meter

Hey WizPic! thaks for all the help... Sounds like I'm not too far from ya with the grey hairs lol lol Its fun messing with these PIC's but can be a PAIN too lol The main thing is I dont know how it is supposed to react... When I increase the voltage to the ADC pin it would incriment such as from 00.000V to 00.064, 0.128, 00.192, 00.256, 00.320, 00.384, ect. ect. all the way up to 65.472 I would think it would go like 00.001, 00.002, 00.003 and so on.... Guess Ill have to live with it lol.......
 

ugn3505

chevymn1964 You gave me the bug agian, has i have not played with my meter design for a long time, Reading this and inputing to this topic i just had to get my development board back out and start playing,

I took some readings samples and i got my routine to start off 0.00Amps then increase the current and it goes like this
0.01
0.02
0.03
...
...
4.93A

so i think it can be done here is a pic off it, i tried to get my PSU in it (brought one) the output on the PSU was set at 13.82V and has you can see my PIC amp/meter reads 13.81V is that close enough for you ?:D
and the amp draw was 3.88 well i think that is close enough for me
 

pic volt meter

Hey WizPic! That is just what I need to have it diplay but I cant get her down to 0.01v.... is the pic youre using have a 10 bit ACD or a 12 bit ADC??? when I increase the voltage to the ADC Pin from zero I read:

00.000Vdc
00.066Vdc
00.122Vdc
00.199Vdc
00.255Vdc
ect
ect..................................
I would like to read:
00.000
00.010
00.020
00.030
ect
ect.................................

looks like I have some more work to do if yours works that way...... :(

Added after 5 hours 7 minutes:

Hey WizPic.... How did you get that high of a voltage reading (12.31)with a 10 bit adc??? I dont know.... I have some strange stuff going on..... lol lol I have the software set to read the adc, convert the reading to bcd using a 16 bit binary to bcd converter, and displaying it.... Heres the strange part.... When I have the ADC set to right justify it only displays the last 3 digits and get readings from 0 to 1024.... when i set to left justify i can get readings from 0 to 65477 but it incriments in steps of 66??????? I dont know what the heck is going on... thats why I cant figure out how in the world you can get it to work????? lol lol :)
 

pic divide by 16 math routines

is the pic youre using have a 10 bit ACD or a 12 bit ADC???

It's only a 10bit PIC

How did you get that high of a voltage reading (12.31)with a 10 bit adc???

I can get it to read up to 50V but as you know the pic only works with a maxium of 5V

I use a routine that samples 64 times then take an avarage reading, Even tried it at 100 samples then take an average reading which get even closer and all that only takes milli seconds i use 18F452 runing at 20MHZ,
Have considered unsing PIC basic (Proton Plus it's wicked and easy)

What PIC are you using now telll me your set up and i will convert the code then send you the hex file then you can see for yourself and test it

Have you seen my photo of my meter I know i am using a GLD but i can run it on a LCD, The reason why i used GLCD is that i can have diferent sidewd fonts


wizpic
 

volt amp meter

Hey WizPic how are you doing???? Thank You for all the help so far..... Now back to work..... lol lol

I have the routine that you sent to sample the ADC many times:
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
I was playing around with the routine and was wondering what files hold the MSB and LSB? I'm thinking it would be OutBuff and OutBuff1 but wich ones are msb and lsb???

Here is the info for the PIC I am using:
PIC16F676 Using Internal Osc. Vref> Vcc
RC0 > LCD D4

RC1> LCD D5

RC2> LCD D6

RC3> LCD D7

RC4> LCD R/S

RC5> LCD E

AN0> Vin
let me know If that is all you need.... I cant wait to see this!!! lol lol Thanks Again!!!

Added after 34 minutes:

Also on the routine that you gave me, It seems to loop for ever.... Hummmmmm

Added after 20 minutes:

HEY WIZPIC!!!! Youre not gonna believe This!! I got her working and It incriments in 10ths of a volt just like it sould!!! Now I just got to figure out the current side :(
The trick was the routine you gave me. Took alittle tweaking but it works! Thanks again!!!!

Added after 1 hours 50 minutes:

Okay next question.... How would you multiply the adc result and divide that result to get actual Voltage??? Right now Im just displaying the adc result and its not very accruate....
 

lcd volt amper meter

Try this code I am not 100% sure that it's working as i do not have 16f676 chip and isis will not sim it, the one thing that i did find with my routine and the 16f676 chip with would not complie with 4 or even 2 channels, and it just smack bang on the limit with the 16f676, try it and let me know

HEY WIZPIC!!!! Youre not gonna believe This!! I got her working and It incriments in 10ths of a volt just like it sould!!! Now I just got to figure out the current side
The trick was the routine you gave me. Took alittle tweaking but it works! Thanks again!!!!

glad to ear that you are getting some where



Okay next question.... How would you multiply the adc result and divide that result to get actual Voltage??? Right now Im just displaying the adc result and its not very accruate....
I know how to do it in basic but noy ASM i havr started to learn ASM but not that good yet, may be one day i wil

Now my code works like this..... with 2.50V on your Adin pin 0 you should dispaly on the lcd 25.01V

and the next one is the amp reading now with 2.50V on adin 0 you should read 5.01A on LCD

let me know if it works but i personally woud upgrade to 18f452 or the 18f4520 better PIC i think

good look

wizpic
 

pic current metre

Hey WizPic.... Tryed the hex code but, it wont even initialize the lcd... just get a blank screen hummm thanks for the try! I've been looking for some code for the math... gets confusing because I need to multiply by 488 and then divide back down to a 16 bit number.... Its getting FUN!!!! lol lol
 

epe voltmetre

Right i think i know where i went wrong try this one and let me know, In the end i simed it on a 16f876 same port config and that did not display any thing but i think i have sort it now
It will need a 4MHz crystal connected, i will look into setting up the internal one if you have not got a cystal but will to read up on the data sheet

EPE did a volt meter some time ago have you had a look at that to see if that will help you,

let me know how you get on with that one

wizpic
 

voltage meter using pic

Hey WizPic how are you doing? I tried the downloading the file and noticed that its in a bas file and I cant compile into a hex.... I've been having fun trying to figure out the math to get actual volts to display.... wish me luck! lol
 

divide by resistance ampere shunt 10a 65 mv

Chevym

How hard can your math be?

You have a reference voltage divided by the bit range. Guessing you use the VCC for reference and a 10 bit ADC it totals to 5V/1024 ~ 5mV for each step.

This means for every 5mV your ADC adds 1 to the returned value. If you took a simple resistor divider to scale down your input voltage range to match the 0V to 5V on your Pic, then just multiply your result with this factor and you're done.

Example: If your Resistor divider has a factor 6, and your ADC returns the value 514 this means you measured: 5mV * 514 * 6 = 15.42V

Of course, you can combine the resistor divider with the ADC step size into one number. In this case being 30mV, which in turn you can substitute for division by 33.33 or something rounded off near this.

514/33.33 ~ 15.42 also. Making the math pretty straight forward. Be sure to use atleast 16 bit math, since 8 bit will not give you much of a result.

For references on how to do 16 bit math on an 8 bit processor, take a look here:



Or use a higher language such as C to take care of this for you.

Goodluck!
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top