| Electronics Forum |
Help
Search
Members
Calendar
|
| Welcome Guest ( Log In | Register ) | Resend Validation Email |
![]() ![]() ![]() |
| chephia |
Posted: December 11, 2010 06:54 am
|
|
Member ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 102 Member No.: 23,058 Joined: March 17, 2009 |
Hi folks…
I’m learning how to make a 4-digit digital voltmeter using 8-bit ADC, µC, and 7-segment. I’m a little bit confused of the value I should use in program for division to get value for each 7-segment. Which one should I use 256 (from 2^8) or 255 (decimal value of 11111111B)? |
| GPG |
Posted: December 11, 2010 11:12 am
|
![]() Forum Addict ++ ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Spamminator Taskforce Posts: 6,166 Member No.: 792 Joined: April 25, 2004 |
255. There are 256 values in 2^8 but one of them is zero. 255 = 11111111
|
| millwood |
Posted: December 11, 2010 02:07 pm
|
|
Forum Addict ++ ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 1,823 Member No.: 25,377 Joined: July 26, 2009 |
255 is the right number.
but then, dividing by 256 is so much easier and so much faster. but in case you really want to divide by 255, there is a (slightly) faster way: 1/255 = 1/(256-1) = 1/256 * (1/(1-1/256)) ~= 1/256 * (1+1/256) obviously, the math doesn't matter until you get into 16-bit figures. |
| Sch3mat1c |
Posted: December 11, 2010 08:14 pm
|
![]() Forum Addict ++ Group: Moderators Posts: 18,142 Member No.: 73 Joined: July 24, 2002 |
You'll probably end up multiplying by a calibration factor anyway, so you can simply take your 8 bit value, treat it like a 16 bit value, and multiply by your scale factor. Then you get between zero and eight bits in the upper byte. Discard the lower eight bits. This is equivalent to dividing by 256 if you multiply by 1 (i.e., no bits in the result), or any other number when you multiply by the reciprocal. Multiplication is faster than division on most microcontrollers (particularly the ones with a hardware multiplier, e.g. AVR), so you save on code and execution time.
Tim -------------------- Answering questions is a tricky subject to practice. Not due to the difficulty of formulating or locating answers, but due to the human inability of asking the right questions; a skill that, were one to possess, would put them in the "answering" category.
|
| chephia |
Posted: December 23, 2010 12:33 pm
|
||
|
Member ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 102 Member No.: 23,058 Joined: March 17, 2009 |
Hi...thanks for the answers. Sorry for this late responds. @millwood: you are right. I found dividing by 256 is so much easier and so much faster. @Tim: your reply was so helpful. This is the first time I use ADC and µC, if you didn't tell me about the "upper byte" probably I had lost when I wrote the code. Thanks Below is code to get the ADC output value and keep them in R0-R3.
More question. May I build the circuit for ADC Vinput (IN0) in these stage: AC source (220-240V) --> diode --> voltage divider --> ADC IN0? |
||
| millwood |
Posted: December 24, 2010 02:28 am
|
||
|
Forum Addict ++ ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 1,823 Member No.: 25,377 Joined: July 26, 2009 |
the answer to your question is "yes" and "no". directly rectifying ac mains is OK, and as long as your divider utilizes high resistance, it wouldn't fry your mcu pin - they are clamp'd in both direction. however, if you check the mcu's datasheet, you may notice that it likely has requirements on source impedance, which is likely to have been violated by your divider. not to mention the safety issue from connecting your mcu to mains directly. the "proper" approach is to use at least an isolation transformer to separate the mains from your mcu, or to use a current transformer + a resistor to "infer" the ac mains voltage. or to use an opto-coupler, etc. - not as accurate though. and then buffer the isolated ac voltage, if necessary. it all depends on your design requirements.
and for 12-bit adc, dividing by 255 vs. 256 makes no difference, accuracy wise. |
||
| chephia |
Posted: December 25, 2010 06:01 am
|
|
Member ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 102 Member No.: 23,058 Joined: March 17, 2009 |
Source impedance? I don't understand about impedance so far. Could you explain it in very simple language? I've already googling and read about it but still don't get it. I know the teory but practically I'm still confused.
Anyway thanks for your reply |
| colin55 |
Posted: January 30, 2011 08:47 pm
|
|
Jr. Member ![]() ![]() ![]() Group: Trusted Members Posts: 88 Member No.: 30,119 Joined: July 24, 2010 |
Impedance is really resistance. When we say "impedance" we really means "resistance."
But if the resistance changes when the frequency of the signal (going through the resistance) changes, we call the resistance an IMPEDANCE. For instance, a 1/2watt resistor will have the same resistance if the signal going through it is 50Hz or 100kHz. But if we have a coil of wire with many turns, the current through it will be less when the signal increases from 50Hz to 100kHz. The current reduces because the effective resistance of the coil increases and because the resistance increases, we call the resistance AN IMPEDANCE. The same reasoning applies to SOURCE IMPEDANCE. A SOURCE is something that “supplies” or “delivers” a quantity. The quantity may be a voltage or a current. Whenever we draw (take) current from a source, the voltage of the source drops (decreases). This applies to the 120v mains or 240v mains or even a 12v battery when we use the starter-motor. The voltage may drop from 12v to 8v. We can work out the exact resistance of the battery that is causing the 4v drop when 300 amps is flowing but because the resistance is not an actual resistor, we call the value an IMPEDANCE. You can call the value: INTERNAL RESISTANCE of the battery or INTERNAL IMPEDANCE. When it comes to a mains transformer supplying 120v or 240v, the winding has a resistance (called the DC resistance) but when a current is flowing, the resistance-value of the secondary winding will be higher than the DC resistance of the winding. Thus we have to give the value a different name and we call it IMPEDANCE. |
| chephia |
Posted: March 08, 2011 09:02 am
|
|
Member ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 102 Member No.: 23,058 Joined: March 17, 2009 |
Colin55...thank you so much for the answer. You explained it very well.
For others, thanks for helping me here, finally I did it. |
| Gorgon |
Posted: March 08, 2011 12:21 pm
|
|
Forum Addict ++ ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 2,927 Member No.: 3,861 Joined: December 18, 2005 |
You should be aware that the 240vac rectified via a diode will be pulses of about 340V(dc), since 240V is the rms value of the ac voltage.
To make 240(F0h) equal to 240V you need to adjust the resistor network accordingly. TOK -------------------- Light travels faster than sound. That's why some people appear bright until they speak!
|
| chephia |
Posted: March 11, 2011 03:33 pm
|
|
Member ![]() ![]() ![]() ![]() Group: Trusted Members Posts: 102 Member No.: 23,058 Joined: March 17, 2009 |
Thanks..I know Vp=2^0.5*Vef
For ADC input I took millwood advice to use a transformer |
![]() |
![]() ![]() ![]() |
:: support us ::