Skip to content

Commit c717e0f

Browse files
committed
These changes have no reason not to go in
1 parent a2a3331 commit c717e0f

10 files changed

Lines changed: 4244 additions & 3491 deletions

File tree

ChangeLog.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ This page documents (nearly) all bugfixes and enhancements that produce visible
33

44
## Planned changes not yet implemented
55
These items are in addition to what was listed under changes already in release.
6-
76
* Enhancement: Fix pinout diagrams for DD-series.
87
* Enhancement: We need pinout diagrams for EA-series too! Considering how bad I am at getting pinout diagrams, I guess I should start asking about DU-series diagrams too!
9-
* Enhancement: AVRdude 7.2 should be out soon. That will be used in the first release after it is available.
10-
* Bugfix: Make serialupdi work with EA.
8+
* Enhancement: AVRdude 7.2 out.
9+
* Bugfix: Make serialupdi work with EA, EB **CRITICAL**
1110
* Enhancement: Implement sleep library
1211
* Re-add SPI attach and detach.
1312
* Ensure libraries in sync with megaTinyCore.
1413

15-
## Planned changes implemented in github
14+
## 1.6.0
1615
These are typically planned for release in a future version (usually the next one) as noted.
17-
* Update - was not gods of C, it was a gang of rogue peripherals. After being held captive and tortured by WEX Luther and his cronies, core developer has escaped said malicious preipherals. While held captive, my computer and equipment were sabotaged by their henchmen. Particular care in restraining WEX Luther to be taken to ensure that end users do not face such attacks.
1816
* Add support for not-yet-announced S class DA-series parts, which are identical but for having the new EB-series lockdown thingie. There are no changes needed.
1917
* Support for the PTC peripheral on DA parts
2018

19+
2120
### 1.5.11 (Emergency fix)
2221
* At some point in the recent past, I must have angered the gods of C, and suddenly millis disabled stopped working - the system would hang (actually, with in-depth investigation, it was shown to be bootlooping - before it called init(), it was calling 0x0000 (a dirty reset) instead of eliding a weakly defined function with nothing in the body except a return, or with an empty body. Why was it doing this? And why only when millis was disabled?). millis disabled is a key piece of core functionality, necessitating an urgent fix. Moving the definitions into main.cpp resolved this issue. (#485)
2322
* Critical PWM bug on DA and DB returned and made all TCA and TCD PWM fail to operate. (#473)

megaavr/libraries/Comparator/README.md

Lines changed: 128 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ comparator::ref::vref_2v500; // 2.5V internal reference (compatibility)
141141
comparator::ref::vref_4v34; // This is what we used in the past, but now Microchip calls it 4.3.
142142
```
143143
Note the absence of vref_vdd. The dac/ac reference voltages do not have that option on these parts.
144+
144145
#### Accepted values on tinyAVR 2-series
145146
``` c++
146147
comparator::ref::disable; // Do not use any reference
@@ -149,7 +150,13 @@ comparator::ref::vref_2v048; // 2.048 (2.05) V
149150
comparator::ref::vref_2v500; // 2.5V
150151
comparator::ref::vref_4v096; // 4.096V (4.10) V
151152
comparator::ref::vref_vdd; // VDD as reference
153+
comparator::ref::vref_1v0; // Alias of vref_1v024
154+
comparator::ref::vref_2v0; // Alias of vref_2v048
155+
comparator::ref::vref_2v1; // Alias of vref_2v048
156+
comparator::ref::vref_2v5; // Alias of vref_2v500
157+
comparator::ref::vref_4v1; // Alias of vref_4v096
152158
```
159+
153160
#### Accepted values on Dx/Ex
154161
``` c++
155162
comparator::ref::disable; // Do not use any reference
@@ -159,15 +166,11 @@ comparator::ref::vref_2v500; // 2.5V
159166
comparator::ref::vref_4v096; // 4.096V (4.10) V
160167
comparator::ref::vref_vdd; // VDD as reference
161168
comparator::ref::vref_vrefa; // ExtrernaL voltage reference
162-
```
163-
164-
#### Aliases accepted on both Dx/Ex and Tiny2
165-
```c++
166-
comparator::ref::vref_1v0; // Alias
167-
comparator::ref::vref_2v0; // Alias
168-
comparator::ref::vref_2V1; // Alias
169-
comparator::ref::vref_2v5; // Alias
170-
comparator::ref::vref_4v1; // Alias
169+
comparator::ref::vref_1v0; // Alias of vref_1v024
170+
comparator::ref::vref_2v0; // Alias of vref_2v048
171+
comparator::ref::vref_2v1; // Alias of vref_2v048
172+
comparator::ref::vref_2v5; // Alias of vref_2v500
173+
comparator::ref::vref_4v1; // Alias of vref_4v096
171174
```
172175

173176
#### Usage
@@ -178,13 +181,13 @@ Comparator.reference = comparator::ref::vref_4v096; // Use the internal 4.096V
178181
#### Default state
179182
`Comparator.reference` defaults to `comparator::ref::disable` if not specified in the user program.
180183

181-
### dacref
184+
### dacref (not available on tinyAVR 0-series)
182185
This property configures the DACREF value - this voltage can be selected as the input for the negative side of the comparator. This is essentially an 8-bit DAC that can only be used as the AC negative input. It is calculated as:
183186

184187
<img src="http://latex.codecogs.com/svg.latex?V_{DACREF} = \frac{Comparator.dacref}{256} * Comparator.reference" border="0"/>
185188

186189
Or, in words, the the voltage from ACn.DACREF is that many 256th's of the reference voltage
187-
*(it does not appear to be `ACn.DACREF + 1` 256'ths interestingly enough, which is what one would expect, and would be strictly speaking slightly better) -SK*
190+
*(it does not appear to be `ACn.DACREF + 1` 256'ths, interestingly enough - which is what one would expect, and would be strictly speaking slightly better) -SK*
188191

189192
#### Usage
190193
``` c++
@@ -261,7 +264,7 @@ Comparator.output_swap = comparator::out::no_swap; // No pin swap for output
261264

262265

263266
### output_initval
264-
When the comparator is initialized, the pin is set to this state until the comparator has output available. To prevent a glitch during initialization, set this to what you expect it to initially output.
267+
When the comparator is initialized, the pin is set to this state until the comparator has output available. To prevent a glitch during initialization, set this to what you expect it to initially output. Alternately, this can be
265268
Accepted values:
266269
```c++
267270
comparator::out::init_low; // Output pin low after initialization
@@ -403,6 +406,117 @@ MyComparator.start(); // Enable the comparator
403406
enterStandbySleep(); // enter standby sleep mode until the comparator interrupt fires, waking it up.
404407
```
405408

409+
## Appendix: Pin chart ordered by AC number
410+
411+
PIN | Mega AC0 | DA/DB AC0 | DD AC0 | EA AC0 | EB AC0 | DA/DB AC1 | EA AC1 | EB AC1 | DA/DB AC2 |
412+
-------|----------|-----------|----------|----------|---------|-----------|----------|---------|-----------|
413+
IN P0# | PIN_PD2 | PIN_PD2 | PIN_PD2* | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2 |
414+
IN P1 | PIN_PD4 | PIN_PE0* | n/a | PIN_PE0* | n/a | PIN_PD3 | PIN_PD3 | PIN_PD3 | PIN_PD4 |
415+
IN P2 | PIN_PD6 | PIN_PE2* | n/a | PIN_PE2* | n/a | PIN_PD4 | PIN_PD4 | PIN_PD4 | PIN_PE1* |
416+
IN P3# | n/a | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 |
417+
IN P4= | PIN_PD1 | n/a | PIN_PC3! | PIN_PC3 | PIN_PC3 | n/a | PIN_PC3 | PIN_PC3 | n/a |
418+
IN P5 | n/a | n/a | n/a | n/a | PIN_PD4 | n/a | n/a | PIN_PA6 | n/a |
419+
IN P6 | n/a | n/a | n/a | n/a | PIN_PD5 | n/a | n/a | PIN_PA7 | n/a |
420+
IN N0 | PIN_PD3 | PIN_PD3 | PIN_PD3* | PIN_PD3 | PIN_PD3 | PIN_PD5 | PIN_PD5 | PIN_PD5 | PIN_PD7 |
421+
IN N1# | PIN_PD5 | PIN_PD0* | n/a | PIN_PD0 | PIN_PD0 | PIN_PD0* | PIN_PD0 | PIN_PD0 | PIN_PD0* |
422+
IN N2# | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 |
423+
IN N3= | n/a | n/a | PIN_PC2! | PIN_PC2 | PIN_PC2 | n/a | PIN_PC2 | PIN_PC2 | n/a |
424+
OUT | PIN_PA7 | PIN_PA7 | PIN_PA7* | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 |
425+
AltOUT | n/a | PIN_PC6* | n/a | PIN_PC6* | n/a | PIN_PC6* | PIN_PC6* | n/a | PIN_PC6* |
426+
427+
This highights the consistent pin options for any given comparator across the DA-series and later parts, and shows that the mega0 the clear odd-part-out.
428+
429+
The tinyAVR pinout, of course, has little in common with the full-size parts:
430+
431+
| PIN | 8-pin |0/1-series AC0|2-series AC0|1+series AC0|1+series AC1|1+series AC2|
432+
|-------|---------|--------------|------------|------------|------------|------------|
433+
|IN P0 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA6 |
434+
|IN P1 | n/a | PIN_PB5* | PIN_PB5* | PIN_PB5* | PIN_PB6* | PIN_PB0 |
435+
|IN P2 | n/a | n/a | PIN_PB1 | PIN_PB1 | PIN_PB0 | PIN_PB5* |
436+
|IN P3 | n/a | n/a | PIN_PB6* | PIN_PB6* | PIN_PB4* | PIN_PB7* |
437+
|IN N0 | PIN_PA6 | PIN_PA6 | PIN_PA6 | PIN_PA6 | PIN_PA5 | PIN_PA7 |
438+
|IN N1 | n/a | PIN_PB4* | PIN_PB4* | PIN_PB4* | PIN_PB7* | PIN_PB6* |
439+
|IN N2 | n/a | n/a | PIN_PB0 | n/a | n/a | n/a |
440+
|OUT | PIN_PA3 | PIN_PA5 | PIN_PA5 | PIN_PA5 | PIN_PB3 | PIN_PB2 |
441+
442+
406443
## *Future development*
407-
*shouldn't LP_MODE/PROFILE and RUNSTBY be properties, and treated like everything else? Why **aren't** they? I would imagine that wanting to wake on the AC int would be one of the most common uses of that interrupt.
408-
They certainly **want** to be properties and it would make the library more coherent. But it would come at a 4-8 bytes of flash (unsure if per comparator or total) and 1 or 2 bytes of ram per comparator, depending on implementation details. Probably wouldn't be popular with people on 212's, but that's a pretty small overhead considering the general level of bloat introduced by classy wrappers around peripherals like Logic, Comparator and Opamp). Maybe a new optional argument to start it in low power, low power - run standby, and run standby (correspondingly more options on DxCore of course). Because how often are you going to be changing the mode once you've turned it on? That's an odd use case (and in any case, the intuitive solution of calling start with a different argument to change it would behave as expected. By passing as the argument the value to be written to the CTRLA register it would have almost no overhead, too. -SK
444+
*shouldn't LP_MODE/PROFILE and RUNSTBY be properties, and treated like everything else? Why **aren't** they? I would imagine that wanting to wake on the AC int would be one of the most common uses of that interrupt.*
445+
446+
*They certainly **want** to be properties and it would make the library more coherent. But it would come at a 4-8 bytes of flash (unsure if per comparator or total) and 1 or 2 bytes of ram per comparator, depending on implementation details. Probably wouldn't be popular with people on 212's, but that's a pretty small overhead considering the general level of bloat introduced by classy wrappers around peripherals like Logic, Comparator and Opamp).*
447+
448+
*But - I think Maybe a new optional argument to start it in low power, low power - run standby, and run standby (correspondingly more options on DxCore of course). Because how often are you going to be changing the mode once you've turned it on? That's an odd use case (and in any case, the intuitive solution of calling start with a different argument to change it would behave as expected. By passing as the argument the value to be written to the CTRLA register it would have almost no overhead, too. -SK*
449+
450+
### Constants, tinyAVR (prop.)
451+
| Option | T<sub>resp</sub> | Idd | RUN_STBY | Notes
452+
|---------------------------|---------------------|-----------|----------|------------------------------
453+
| `comparator::pm::unchanged`| as before | as before | as before| The default option when called without argument - does not change the current setting. If not previously set, results in default configurationbelow.
454+
| `comparator::pm::default` | 50 ns | 92 uA | No | Resets it to the default configuration.
455+
| `comparator::pm::lp` | 150 ns | 45 uA | No | tinyAVR 0-series does not support low power mode.
456+
| `comparator::pm::runstby` | 50 ns | 92 uA | Yes | Mind the current if entering standby with this.
457+
| `comparator::pm::lp_stby` | 150 ns | 45 uA | Yes | Likely the most useful option after default. Current still more than an order of magnitude larger larger than expected standby sleep power consumption. tinyAVR 0-series not supported.
458+
459+
On tinyAVR, LP Mode also changes the hysteresis thresholds from 10/30/55 mV to 10/40/80 mV. No such effect is documented for other comparators.
460+
461+
### Constants, Dx
462+
| Option | T<sub>resp</sub> | Idd | RUN_STBY | Notes
463+
|-------------------------------|---------------------|-----------|----------|------------------------------
464+
| `comparator::pm::unchanged` | as before | as before | as before| The default option when called without argument - does not change the current setting. If not previously set, results in default configurationbelow.
465+
| `comparator::pm::default` | 85 ns | 70 uA | No | Resets it to the default configuration.
466+
| `comparator::pm::pmode0` | as above | as above | as above | Alias of to the default power mode.
467+
| `comparator::pm::pmode1` | 235 ns | 17 uA | No | Resets it to the default configuration.
468+
| `comparator::pm::pmode2` | 445 ns | 12 uA | No | Resets it to the default configuration.
469+
| `comparator::pm::lp` | as above | as above | as above | Alias of power mode 2 without runstby
470+
| `comparator::pm::runstby` | 85 ns | 70 uA | Yes | Power mode 1, run standby.
471+
| `comparator::pm::pmode0_stby` | as above | as above | as above | Alias of the default power mode with runstby.
472+
| `comparator::pm::pmode1_stby` | 235 ns | 17 uA | Yes | Power mode 1, run standby.
473+
| `comparator::pm::pmode2_stby` | 445 ns | 12 uA | Yes | Power mode 2, run standby. Likely the most useful.
474+
| `comparator::pm::lp_stby` | as above | as above | as above | Alias of power mode 2 with runstby
475+
476+
## Constants, Ex
477+
478+
| Option | T<sub>resp</sub> | Idd | RUN_STBY | Notes
479+
|-------------------------------|---------------------|-----------|----------|------------------------------
480+
| `comparator::pm::unchanged` | as before | as before | as before| The default option when called without argument - does not change the current setting. If not previously set, results in default configurationbelow.
481+
| `comparator::pm::default` | 50 ns | 150 uA | No | Resets it to the default configuration.
482+
| `comparator::pm::pmode0` | as above | as above | as above | Alias of to the default power mode.
483+
| `comparator::pm::pmode1` | 150 ns | 110 uA | No | Resets it to the default configuration.
484+
| `comparator::pm::lp` | as above | as above | as above | Alias of power mode 1 without runstby
485+
| `comparator::pm::runstby` | 50 ns | 150 uA | Yes | Power mode 1, run standby. Goddamn, what happened to the power consumption?!
486+
| `comparator::pm::pmode0_stby` | as above | as above | as above | Alias of the default power mode with runstby.
487+
| `comparator::pm::pmode1_stby` | 150 ns | 110 uA | Yes | Power mode 1, run standby. Power mode 1 is hardly an improvement. What happened to modes 2 and 3?!
488+
| `comparator::pm::lp_stby` | as above | as above | as above | Alias of power mode 1 with runstby
489+
490+
491+
After a
492+
493+
494+
* AC_PWR_DEFAULT - No low power mode, no run in standby. 85ns response time. 0x00
495+
* AC_PWR_PMODE1 - No run in standby, using low power mode. 235ns`*` response time. Saves 53uA. 0x08
496+
* AC_PWR_PMODE2 - No run in standby, not using low power mode. 445ns`*` response time. Saves 58uA. 0x10
497+
* AC_PWR_RUNSTBY - Run in standby, power mode 0. 0x80.
498+
* AC_PWR_PMODE1STBY - Run in standby, power mode 1 150ns response time. Saves 53uA. 0x88
499+
* AC_PWR_PMODE2STBY - Run in standby, power mode 2 150ns response time. Saves 58uA. 0x90
500+
501+
## Constants, Ex
502+
* AC_PWR_DEFAULT - No low power mode, no run in standby. 50ns response time. 0x00
503+
* AC_PWR_PMODE1 - No run in standby, using low power mode. 150ns response time. Saves 40uA. 0x08
504+
* AC_PWR_RUNSTBY - Run in standby, power mode 0. 0x80.
505+
* AC_PWR_PMODE1STBY - Run in standby, power mode 1 150ns response time. Saves 40uA. 0x88
506+
507+
Uh, yeah, the analog comparators have response times ot 50-445 ns, and use between 12 and 150 uA.
508+
509+
### Peripheral Power Consumption
510+
511+
Figures are as reported by manufacturer in datasheets for analog comparator as "typical" values.
512+
513+
Mode | TinyAVR 2 | AVR Dx | AVR Ex |
514+
-----|-----------|--------|--------|
515+
Base | 92 uA | 70 uA | 150 uA |
516+
LP | 45 uA | - | - |
517+
PM1 | - | 17 uA | 110 uA |
518+
PM2 | - | 12 uA | n/s |
519+
PM3 | - | Rsvd. | n/s |
520+
521+
522+
Note that the overall device power while in power-down sleep is typically on the order of <0.1 uA in power down sleep, and <1 uA in standby sleep with the RTC running. Standby sleep with the RTC and an AC running in RUNSTBY in contrast is ~92 uA, or half that with LP mode. Users considering use of `RUNSTBY` should take heed of the power ramifications of this, and consider if there is a better way to achieve their goal. If that must be done, `LPMODE` is recommended.

0 commit comments

Comments
 (0)