Go Down

Topic: Accurate voltmeter (or could be renamed : uC's ADC ... State of the art) (Read 938 times) previous topic - next topic

retrolefty



Quote
As I said, I don't know how to "read" :
"ADCSRA |= _BV(ADSC);"
"BV" means "bit value", so given a bit position as a number (LSB is zero), it turns that into a bit mask.
BV(2) is the same as 1 << 2, which is same as 4.
"|=" says bit wise OR the variable on the left with the mask on the right, and assign the result to the variable on the left.


So can I say :
ADCSRA |= _BV(ADSC);
is equivalent to :
ADCSRA = ADCSRA | _BV(ADSC);
is equivalent to :
ADCSRA =ADCSRA | 0b01000000  (see Atmel datasheet, -BV(ADSC) = 0b01000000)
is equivalent to :
ADSRA = ADCSRA | 0x40
is equivalent to :
ADCSRA |= 1<<6
is equivalent to :
ADCSRA |= 64


Mmmm ! So many writting to say the same thing ! No wonder why a beginner can't understand !



I think what you may be missing is that by using the _BV(ADSC) method that the function will work correctly for the different AVR chips versions that the IDE supports that otherwise if you used fixed values like 64 it might work correctly on a 328P chip but not a 2560 chip. Same goes for using register names like ADCSRA where the actual physical address of that register might again be different for the different AVR chips used in the Arduino world. They are pretty cryptic to read, at least for me also, but there is a method to their madness.


retrolefty


What chance has the beginner (or indeed anyone) if you just wrote
Code: [Select]
ADCSRA |= 64?
At least the BV form gives an idea what is going on.

(BTW, you realise ADCSRA is a macro too, don't you?   ;). )


Is it a macro, or a defined constant that can change with AVR chip type?

hary

I'm now wondering if using 1024 or 1023 in the calculation of VCC !

http://forum.allaboutcircuits.com/showthread.php?t=80018


What chance has the beginner (or indeed anyone) if you just wrote
Code: [Select]
ADCSRA |= 64?
At least the BV form gives an idea what is going on.

(BTW, you realise ADCSRA is a macro too, don't you?   ;). )


ADCSRA ? A macro ? I don't see what you mean.

This topic  is really leading me to deep. Somebody to help stay tuned on the most important things ?
Properly using uC seems to be quite difficult indeed ! Interesting, but a little bet hard for a beginner !

AWOL

Quote
I'm now wondering if using 1024 or 1023 in the calculation of VCC !

Ask yourself why semiconductor manufacturers like TI or National would go to the trouble of designing and marketing reference voltage devices with strange, non-physical constant (like band gap voltage) voltages, like 1.024V.

I think then your question answers itself.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AWOL



What chance has the beginner (or indeed anyone) if you just wrote
Code: [Select]
ADCSRA |= 64?
At least the BV form gives an idea what is going on.

(BTW, you realise ADCSRA is a macro too, don't you?   ;). )


Is it a macro, or a defined constant that can change with AVR chip type?


Of course it is a macro.
How could you have a constant on the left-hand side of an assignment?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty




What chance has the beginner (or indeed anyone) if you just wrote
Code: [Select]
ADCSRA |= 64?
At least the BV form gives an idea what is going on.

(BTW, you realise ADCSRA is a macro too, don't you?   ;). )


Is it a macro, or a defined constant that can change with AVR chip type?


Of course it is a macro.
How could you have a constant on the left-hand side of an assignment?


Hell I don't know, solder it in?

Robin2


This topic  is really leading me to deep. Somebody to help stay tuned on the most important things ?
Properly using uC seems to be quite difficult indeed ! Interesting, but a little bet hard for a beginner !


As with every area of expertise (lawyers, doctors ....)  people who know stuff like to talk about the things they know.

The trick is to take what you need from the arcane discussions.

You seem to have it figured out when you listed all the options. Just use the system that will best help you to know what your code means when you come back to it after a 6 month break.

...R

Go Up