Comments (22)
Huh. That should definitely work, so either the workaround is not implemented correctly there, or the workaround doesn't work there. Either way, it needs to be fixed for 1.3.0.
from dxcore.
PD0 only works as an input if I do:
analogRead(7);
or disable the ADC with;
ADC0.CTRLA &= ~(ADC_ENABLE_bm);
from dxcore.
By the way, I'm on DxCore version 1.2.0. I assume that's more recent than 1.2.0-a.
from dxcore.
1.2.0 and 1.2.0-a are the same version. -a pulls in a new compiler toolchain to give support for the smaller AVRxDA parts and AVR128DB, but only works on windows and maybe mac, not linux because of some stupid problem i don't understand....
from dxcore.
What value do you see for ADC0.PORTMUX after startup? The workaround should be setting it to 0x7F (127), and that worked in my testing; if it is set to that, it sounds like the ADC on some parts doesn't like the fact that I was setting it to a "reserved" value and is treating it as 0... If it isn't set to 0x7F, it sounds like the workaround just isn't being used. though that in and of itself is strange; I don't see how that could be the case.
from dxcore.
Do you mean ADC0.MUXPOS and ADC0.MUXNEG?
from dxcore.
In my tests, only MUXPOS mattered - actually, we know MUXNEG doesn't matter, since analogRead() doesn't touch it.
from dxcore.
Argh, yes. ADC0.MUXPOS
from dxcore.
ADC0.MUXPOS = 127
ADC0.MUXNEG = 0
So perhaps MUXNEG is doing it?
Anyway, I think setting to a reserved value is dangerous. It may have an effect, such as shadowing another value, or it may be used in the future. Why not set both to GND?
from dxcore.
Interesting. Try setting ADC0.MUXPOS=0x40 (ground, which was what I was going to suggest). I think the reason I didn't do that was that I wanted something floating, but it turns out that it doesn't get connected to the sampling cap unless you do a reading with it anyway.
No need to touch MUXNEG - analogRead(7); wouldn't modify MUXNEG either (in fact, we never touch that anywhere in the core); setting that just wastes 3 instruction words.
from dxcore.
And.... waaaaitaminute.... analogRead(), with the workaround enabled, sets it back to 0x7F... so something doesn't add up here....
from dxcore.
ADC0.MUXPOS = 0x40;
doesn't fix the problem, nor does:
ADC0.MUXPOS = 0x40; ADC0.MUXNEG = 0x40;
from dxcore.
What about disabling the ADC with:
ADC0.CTRLA &= ~(ADC_ENABLE_bm);
until the user calls analogRead(...).
from dxcore.
That's possible. I wonder what the key is - if we can avoid it, I'd rather not add more to analogRead() than we have to....
I wonder if either of these would do the trick in setup()?
ADC0.COMMAND=0x02;
ADC0.COMMAND=0x03;
ADC0.COMMAND=0x01;
ADC0.COMMAND=0x02;
from dxcore.
ADC0.COMMAND=0x01;
seems to do the trick. So this whole test works:
void setup() {
ADC0.COMMAND=0x01;
pinMode(12, INPUT_PULLUP); // PD0
pinMode(7, OUTPUT); // PA7
}
void loop() {
if (digitalRead(12) == HIGH) digitalWrite(7, HIGH); else digitalWrite(7, LOW);
delay(1000);
}
from dxcore.
Full list:
ADC0.COMMAND=0x01; // Works
ADC0.COMMAND=0x01; ADC0.COMMAND=0x02; // Works
ADC0.COMMAND=0x02; // Doesn't work
ADC0.COMMAND=0x03; // Doesn't work
I'm going to stop for the night now, but will be around tomorrow if you need more tests!
from dxcore.
Sounds like
ADC0.COMMAND=0x01;
ADC0.COMMAND=0x02;
it is.
(just setting it to 0x01 and forgetting about it is no good - that will make the first ADC reading you take come out wrong).
from dxcore.
Actually, huh... it would make every analogRead() wrong, wouldn't it (setting one pin high, another one low, and alternately reading them should demonstrate this if my understanding is correct)... that's actually kinda nasty isn't it.... On second thought, if someone does anything that generates an analog result, and doesn't clean up after themselves before calling analogRead, they deserve what they get; manually manipulating a peripheral voids any promise of the relevant API functions returning correct results.
from dxcore.
I'm confused - according to the Silicon Errata, calling analogRead(12) should stop subsequent digital input from working on that pin, whatever fix you've done in setup. However, this works OK (on 1.2.0):
void setup() {
pinMode(7, OUTPUT); // PA7
pinMode(12, INPUT_PULLUP); // PD0
analogRead(12);
}
void loop() {
if (digitalRead(12) == HIGH) digitalWrite(7, HIGH); else digitalWrite(7, LOW);
delay(1000);
}
ie the LED on pin 7 follows the state of pin 12.
from dxcore.
That's because the workaround already moves ADC0.POSMUX away after every analogRead().
The only current bug is that the workaround does not get applied until a conversion is started - even if we then immediately stop it!
With
ADC0.COMMAND=0x01;
ADC0.COMMAND=0x02;
in setup
can you verify that after a delay(10); ADC0.INTFLAGS is 0?
If it is, then i'll check in that fix - all without actually getting out any of my own hardware. Which I'm not allowed to do until I finish a bunch of other action items!
from dxcore.
Er, rather, that the workaround doesn't actually successfully work around the errata until a conversion has been started, even if we immediately stop it.
from dxcore.
With
ADC0.COMMAND=0x01;
ADC0.COMMAND=0x02;
in setup
can you verify that after a delay(10); ADC0.INTFLAGS is 0?
Confirmed.
from dxcore.
Related Issues (20)
- Optiboot_dx build fails on various alternative baud rates HOT 4
- TWI name classification not perfect. (Information Request) HOT 22
- DD series: Error in digitalPinToAnalogInput macro in pins_arduino.h HOT 3
- 10bit DAC with analogWrite give have only 8bit resolution (DD series and other?) HOT 1
- Add DXCORE AVR128DB64 to Library HOT 2
- Menu with optimization level. HOT 1
- D7 LED not blinking after burning bootloader into 32DD14 configured for Serial on D4/D5 (Serial0, Swap3) HOT 11
- On AVR-DD Parts can't configure MVIO for Single Supply via Tools MVIO Option in Arduino IDE HOT 1
- EVENT AND COMPARATOR ISSUES WITH EA and EB parts HOT 5
- How to do OTA? AVR128DB64 HOT 2
- Wrong timer for millis() on 14-pin DD part HOT 2
- HV programmer for DD series (and newer)
- Board Manager SSH Certificate Expired HOT 2
- AVR128DB48 unexpected behaviour HOT 5
- linking error: section .bss' is not within region data' HOT 1
- program avr128da28 chip using arduino uno as a programmer HOT 4
- error when burning the bootloader for avr128DA28 and arduino uno as updi HOT 4
- Is there a -r option hidden in the DxCore settings? HOT 3
- AVR64DU32 Curiosity Nano Board
- GPIOR registers used by core contrary to the documentation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dxcore.