New to mikroE C

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
One Question:

The program displays ADC value and it's AN0 corresponding voltage.
In this case ADC count is 0-1023 and V=0 to 5V.
Display OK.

I managed to change the voltage to my target Value which is 23VDC.
The display shows the value but is having issues. Will get to that later.

Q: is that will the actual voltage applied to the AN0 through the divider will be equal to the displayed value if I scale it to 23volts/1023 ?
 

t06afre

Joined May 11, 2009
5,934
Q: is that will the actual voltage applied to the AN0 through the divider will be equal to the displayed value if I scale it to 23volts/1023 ?
Just a little detail. Each bit will have a weight equal to 23/1024 not 23/1023 The bit weight using ADCs is always ((voltage range)/(2^n) there n is the number of bits in the ADC
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
Let's see if I get it right.

ADC is 10 bits. that is 1024 bit count.
At 23 Volts max each bit change corresponds to 0.0225 Volts change in the display
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
How can I change the reading to a 10mV count.
That is my target is 23.00V. Which is 4 digit.
That will be 10mV (0.01V) accuracy.

Will it be able to just change the volt display every 10mV increment ?

Right now it is 5.000V. Which is 4.8mV
 

THE_RB

Joined Feb 11, 2008
5,438
Add up a number of ADC samples, taken over 1 mains cycle (at 50Hz = 20mS). Like take 20 samples over 20 mS.

The total will include a small noise factor, and have a much higher resolution than one single ADC sample. And you get the added bonus of cancelling noise caused by the AC mains EMI.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
Add up a number of ADC samples, taken over 1 mains cycle (at 50Hz = 20mS). Like take 20 samples over 20 mS.

The total will include a small noise factor, and have a much higher resolution than one single ADC sample. And you get the added bonus of cancelling noise caused by the AC mains EMI.

Easier than done I believe. I am still learning.

I know you are telling me to sample for 20ms at 1ms interval.

I just dunno how to go abt it yet. :(
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I am trying to put a dp between the 5000 characters.
If I put the DP I get 5.00. Which is just replacing the 100th by a dot(.)

I am exhausted trying to figure out how to just keep the "5" at it's location for now and shift the other three bits to the right just one position so I can put the dot where it should be as in "5.000".

Any pointers ? Or and the

XXX = (YYY/1000)%10 + 48 gives some operator cannot be used in operand sorta error.



{Edit; After 2Hrs} I did it, I did it :D.

Now to test with the a divider..!

Still need to find a way to mask the Leading zero in the 10th before decimal place. :confused:

Got to sleep !

Later Guys.

PS. t06...I think it's working cause I can program. Still not sure though, gonna add some codes like display scrolling.
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
Easier than done I believe. I am still learning.

I know you are telling me to sample for 20ms at 1ms interval.

I just dunno how to go abt it yet. :(

The compiler lets you make a 1mS delay like this;
Delay_ms(1);

Then just loop 20 times, and every time sample the ADC and add the result into a variable.

After 20 mS it is done, and you have a combined ADC value of 20 ADC reads added together. (range 0-20460). That still fits in an unsigned int 16bit variable.

I'm not going to write the code for you because you need the practice! ;)
:)
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I asked once to write a code when I joined and I got the answer I was giving now.
And I got angry. Never knew what it meant then. But I promised I will learn and I am still learning.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
While doing my first learning lesson I thought why not do something I can use and since since this was something I wanted to do badly.

The project and learning lesson evolved and came to this.

The VA meter project finally is giving me some things I never thought I could accomplish.

The targeted PSU is below, something I had for like years.

The meter now in it are so far the most expensive any one will ever get. Totally useless and so good that you can't even see it. :D

see what I mean,



There was one time I gave up. But not this time. This time I am getting some where. See what I mean below.

The VA meter voltage part is desighned to show what the above PSU can supply, basically it's 0-20V but at light loads it is around ≈22VDC
Current is 8A cont. and 10A peak.

I like things to be fancy. The welcome msg is the result. :D



After 5s



Circuit will beep when the PIC activates the output of the supply.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
The input is scaled down by a VR (divider) and the supply is connected.

And it works so good.

This is at 0V. Need to stabilize the ADC input ( but later )











Not good as the Fluke but not bad either, EH!

Voltage part is now almost done.

Now for Current part. (The Amps value in the pictures is the ADC value).
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
You've done good! It doesn't take long to get the code sorted if the hardware is already wired right and working. That's the thing i like the most about the EasyPIC dev boards. :)

Just be aware that IF you are using Vdd and Vss (5v and 0v) as the ADC references, you have calibrated your voltmeter code using the EasyPIC7 5v supply as the reference. That is actually your PC's USB 5v supply, and USB 5v rails are notorious for being off, like 4.9, 5.1 or 5.25v.

Since the final application will have its own 5v regulator you will need to re-calibrate your voltmeter and ammeter code to suit that 5v rail.

Congrats! :)
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I knew the 5V is always be off usually.
I would need to change the ADC multiplier value later.
 

THE_RB

Joined Feb 11, 2008
5,438
The main advantage being that the calibration will still be good even if Vdd voltage varies, so you can calibrate on the EasyPIC and it will still be accurate when you switch to another 5v regulator later.
 
Top