Attiny 3226 how to use two analogRead ? No reading #865
Replies: 4 comments 1 reply
-
If you feel the need to work the registers yourself, you will also need to set the input multiplexor to select a pin as per page 432 of the datasheet. But most people just let the core handle all that just like with any other Arduino ie. analogRead(PIN_PA3) etc. as described here: |
Beta Was this translation helpful? Give feedback.
-
Where did the fuicking response I wrote last night go?! There is no reason to touch any of those registers. In fact, the moment you touch any registers except through the API calls clearly described in the analog reference (https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/Ref_Analog.md), ALL FUNCTIONALITY RELATED TO THAT PERIPHERAL IS UNDEFINED. analogReturn might work, it might product bogus values, or it might cause the chip to explode - the core provides no guarantees or specification about what to expect (and if something made the chips explode, they would just note that the use must ensure that that situation is not produced). Manual vs core-mediated control of a peripheral is either or. You may EITHER use the API functions, and not call ANY of the related API functions and assume full responsibility (do if you change any register under ADC0, you must not expect correct results from analogRead, analogReadEnh or correct behavior from any othher ADC-related functionality. The same holds true of (except where specifically noted in the core reference documentation) for EVERY peripheral. It's not possible to reinitialize every peripheral, as that is a much bigger routine than init_someperiph(), as it also has to zero out every unused register, ad account for any enable locking and configuration change protection. On some of the megatinycore parts, if i did this, the largest flash size available in that pincount could not fit all of the "prior-manual-configuration-proof" initialization code. And the hardware has no facility to exclude or compensate for the possibility that registers have been modified since initialization - that simillarly breaks all expectation of correct behavior. This is clearly stated in the Readme.md - if you're modifying the registers outside of functions we provide for that purpose, any correct behavior is luck - except as noted for limited cases for specific reasons, the nature of which is described at that point inj the docs. What is truly baffling about your question is that THERE IS NO REASON TO MANUALLY TOUCH REGISTERS AT ALL ADCPowerOptions(ENABLE_ON | LOW_LAT_OFF);
analogReference(INTERNAL2V5);
Serial.println(analogRead(mypin))'; Reading a battery? How is it driving the chip? Usually when i care about power consumption, I run the chip straight off a LiPo battery (Are you using a boost converter or something)? in thecase where the chip runs straight from battery it is trivial: There are also features to change the sampling duration for high imopedance sources, perform true differential ADC measurements (not the fake ons the Dx has), and use the programmable gain amplifier - EVEN IN SINGLE ENDED MODE! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Oh, uh if you're reading VDD, why not use use the smallest reference possible 1.024V, and analogRead(VDDDIV10) input? with analogReadResolution(12); analogReference(INTERNAL1V024); analogRead(VDDIODIV10), that would mean reading of 4095 would be full scale, and would indicate that Vdd wat at 10.24v, and that the chips is likely on fire. More realistic values might be like 2000. |
Beta Was this translation helpful? Give feedback.
-
HI
I use the first analog (A3) pin PA3 to read the battery voltage and I have declared these lines in setup
when I wanted to add a second analog to read the value from the photoresistor, I still have the same value because these lines in setup make a collision.
How to solve it so that it can read the voltage using these 3 lines and read the photoresistor?
regards Brendy
Beta Was this translation helpful? Give feedback.
All reactions