Skip to content

Commit

Permalink
Let's see how much this broke.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenceKonde committed Sep 30, 2023
1 parent 44e561b commit e67aa6a
Show file tree
Hide file tree
Showing 32 changed files with 1,072 additions and 457 deletions.
1 change: 0 additions & 1 deletion megaavr/boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ atxy7.menu.chip.817.build.board=AVR_ATtiny817
atxy7.menu.chip.817.build.attiny=817
atxy7.menu.chip.817.upload.maximum_size=8192
atxy7.menu.chip.817.build.mrelax=
atxy7.menu.chip.817.build.mrelax=
atxy7.menu.chip.817.upload.maximum_data_size=512
atxy7.menu.chip.817.bootloader.TCD0CFG_avrdude="-Ufuse4:w:0x00:m"
atxy7.menu.chip.817.bootloader.TCD0CFG_serialupdi=4:0x00
Expand Down
18 changes: 12 additions & 6 deletions megaavr/cores/megatinycore/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* ATtiny 0/1/2-series microcontrollers from Microchip.
* megaTinyCore is free software (LGPL 2.1)
* See LICENSE.txt for full legal boilerplate if you must */

/*************************************************************
* This file contains the stuff I think people are most likely
* to need to refer to. The minutia has all been pushed into
* core_devices.h if it's independent of pins_arduino.h or into
* pinswap.h if it relates to PORTMUX, which is a great volume
* of stuff nobody should have to read.=
*/
/*
* of stuff nobody should have to read.
*
* That means functions and macros that may be used by user code
* (except for part-feature ones - those are clearly documented
* in the readme if they are ready for users).
* (except for some part info macros, which are described in
* Ref_Defines.md in the documentation.
* I also try to put detailed comments in where appropriate.
*************************************************************/

Expand Down Expand Up @@ -45,9 +45,15 @@
* analogWrite() on a constant pin that will never support PWM, or digitalWrite() on
* a pin number that is neither a pin nor NOT_A_PIN (which silently does nothing for
* compatibility).
*
* badCall() on the other hand is called if we know that regardless of what arguments
* are passed, that function is nonsensical with current settings, for example, millis()
* when millis timekeeping has been disabled */
* when millis timekeeping has been disabled.
* Closely related in check_constant_pin, which calls badArg to stop compilation if
* the pin number it was passed isn't a foldably constant value known at compile time,
* which is used by the fast digital I/O functions and other things that require than
* you pass them a *constant* pin.
*/

#if !defined(LTODISABLED)
void badArg(const char*) __attribute__((error("")));
Expand Down
12 changes: 7 additions & 5 deletions megaavr/libraries/Comparator/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Comparator
A library for interfacing with the analog comparator peripheral in the modern AVR parts - tinyAVR 0/1/2-series, megaAVR 0-series, and the latest iterations, the DA, DB, DD, and EA-series.
Developed by [MCUdude](https://github.com/MCUdude/) with some porting effort by [Spence Konde](https://github.com/SpenceKonde/). This is the readme distributed with megaTinyCore.
Developed by [MCUdude](https://github.com/MCUdude/) with some porting effort by [Spence Konde](https://github.com/SpenceKonde/). This is the readme distributed with DxCore.

The tinyAVR 0-series, 2-series, and 1-series parts with less than 16k of flash have a single analog comparator, with either 1 or 2 options each for the positive and negative input pins. The "golden" 1-series parts, those with 16k or 32k flash (and other goodies) instead have three comparators, which have up to 4 options for the positive input, and 2 for the negative. The internal voltage reference can also be used as the negative side; on the 1-series and 2-series parts, that reference can be scaled by an internal 8-bit DAC, and on 0-series and 1-series parts, the reference itself can be used directly. This library provides a wrapper class, `Comparator` that exposes the full functionality of these peripherals without having to manually manipulate registers.

Expand Down Expand Up @@ -41,14 +41,14 @@ Like the other basic wrappers around modern avr peripherals (logic, ZCD, event),
### The POWER and LPMODE options are not supported currently
On Dx-series parts, each analog comparator can be configured for one of three power profiles. The higher the number, the lower the power consumption and the slower the response. Currently the Comparator library always uses the highest power, fastest response option. This may be changed in a future release if there is call for such a feature.

Early versions of the header specified a fourth value, but this was removed from both the datasheet and the io header before release. It may or may not secretly still be present (my guess would be that it is, just like the 4x PLL multiplier), but there was likely a reason that it was struck from the documentation (likely, that it didn't work, was inaccurate, or didn't save power).
Early versions of the header specified a fourth value, but this was removed from both the datasheet and the io header before release. It may or may not secretly still be present (my guess would be that it is, just like the 4x PLL multiplier), but there was likely a reason that it was struck from the documentation (likely, that it didn't work, was inaccurate, or didn't save power). It would appear that by the time the DD was released, they'd gotten the issue sorted out, because power profile 3 is present there.

On the tinyAVR and megaAVR parts, there is instead an LPMODE (Low Power Mode) which can be either on or off. Comparator always sets it to 0. An option to configure this may be made available in the future if there is user demand.

### Window Mode is not supported
Thus far all modern AVR parts with more than 1 comparator have had a "windowed mode" that can be selected to group 2 comparators into a single "windowed" comparator, where both comparators must use the same positive input, while the negative inputs define the upper and lower bounds of the "window", and interrupts can be generated when the state rises above, or falls below the input, or when it enters or leaves the window.

The Comparator library does not support this odd option. There are no plans to add support for this odd feature. Note also that this is entirely separate from the ADC "window comparator" mode, where a similar effect is achieved with the ADC set in free-running mode.
The Comparator library does not support this odd option. There are no plans to add support for this feature - it's an awkward amount of synchronization for this library to provide. Note also that this is entirely separate from the ADC "window comparator" mode, where a similar effect is achieved with the ADC set in free-running mode!

## Properties of the Comparator class

Expand Down Expand Up @@ -92,7 +92,9 @@ Comparator.input_n = comparator::in_n::vref; // Connect voltage reference to th


### reference
On the 0-series and 1-series, this sets the voltage reference that will be used if VREF is selected as the negative input. On 1-series and 2-series, this also sets the voltage that DACREF is derived from. On 1-series parts with multiple comparators, these reference voltages can be set independently (unlike on the Dx-series). On the tinyAVR 1-series, AC0 and the DAC that can be output on PA6 share the same reference. The 0/1-series uses a rather strange set of voltages, while the 2-series uses the same voltages that most modern AVRs do
On the 0-series and 1-series, this sets the voltage reference that will be used if VREF is selected as the negative input. On non-0-series, this also sets the voltage that DACREF is derived from.

On 1-series parts with multiple comparators, these reference voltages can be set independently for each comparator. On the Dx and Ex parts, parts with multiple comparators have to share just one reference voltage.. On the tinyAVR 1-series, AC0 and the DAC that can be output on PA6 share the same reference. The 0/1-series uses a rather strange set of voltages, while the 2-series uses the same voltages that most modern AVRs do.

Accepted values (0/1-series):
``` c++
Expand All @@ -105,7 +107,7 @@ comparator::ref::vref_4v34; // 4.34V internal reference
comparator::ref::vref_2v500; // 2.5V internal reference (compatibility)
```

Accepted values (2-series):
Accepted values (Everything else):
``` c++
comparator::ref::disable; // Do not use any reference
comparator::ref::vref_1v024; // 1.02V internal reference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***********************************************************************|
/***********************************************************************|
| Modern AVR Comparator library for tinyAVR 0/1/2, megaAVR0, Dx, and Ex|
| |
| Developed in 2019 by MCUdude https://github.com/MCUdude/ |
Expand Down Expand Up @@ -33,7 +33,7 @@

void setup() {
// Configure relevant comparator parameters
#if MEGATINYCORE_SERIES > 0
#if defined(MEGATINYCORE) && MEGATINYCORE_SERIES > 0
Comparator.input_p = comparator::in_p::in0; // Use positive input 0 (PD2)
Comparator.input_n = comparator::in_n::dacref; // Connect the negative pin to the DACREF voltage
Comparator.reference = comparator::ref::vref_2v5; // Set the DACREF voltage to 2.5V
Expand Down
8 changes: 5 additions & 3 deletions megaavr/libraries/Comparator/examples/Interrupt/Interrupt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
| Modern AVR Comparator library for tinyAVR 0/1/2, megaAVR0, Dx, and Ex|
| |
| Developed in 2019 by MCUdude https://github.com/MCUdude/ |
| Ported to tinyAVR & Dx-series by Spence Konde for megaTinyCore and |
| DxCore 2021-2022: https://github.com/SpenceKonde/ |
| Ported to tinyAVR 2021 by Spence Konde for megaTinyCore |
| https://github.com/SpenceKonde/megaTinyCore |
| Ported to tinyAVR 2022 by Spence Konde for DxCore |
| https://github.com/SpenceKonde/DxCore |
| |
| In this example we use an internal reference voltage instead of an |
| external one on the negative pin. This makes it possible to give a |
Expand Down Expand Up @@ -49,7 +51,7 @@ void setup() {

// Configure relevant comparator parameters
Comparator.input_p = comparator::in_p::in0; // Use positive input 0 (PA7)
#if MEGATINYCORE_SERIES == 0
#if (defined(MEGATINYCORE) && MEGATINYCORE_SERIES == 0)
Comparator.input_n = comparator::in_n::vref; // 0-series has no DACREF, so use vref directly.
#else
Comparator.input_n = comparator::in_n::dacref; // Connect the negative pin to the DACREF voltage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
| Developed in 2019-2022 by MCUdude |
| https://github.com/MCUdude/ |
| |
| Ported to tinyAVR 2020-2021 by Spence Konde. |
| Ported 2021-2022 to DxCore, megaTinyCore by Spence Konde. | |
| |
| In this example we use the negative and positive input 0 of the |
| comparator. The output goes high if the positive input is higher than |
| the negative input, and low otherwise. |
| This is much like tranplanting an 'lm339" only with better specs into |
| your AVR. Pin used are: |
| | Dx/Ex/Mega0 | TinyAVR | DD14 | |
| In_p | PD2 | PA7 | AINP3 PB |
| in_N | PD3 | PA6 | | |
| Out | PA7 | PA5 | Todo: evsys| | |
| |
|Note that the evetn library can by used to redirect the outputt |
|
| In effect this turns the three pins into the inputs and outputs of a |
| LM339-like chip, except that these are rail to rail
|***********************************************************************/

#include <Comparator.h>

void setup() {
// Configure relevant comparator parameters
Comparator.input_p = comparator::in_p::in0; // Use positive input 0 (PA7)
Comparator.input_n = comparator::in_n::in0; // Use negative input 0 (PA6)
Comparator.output = comparator::out::enable; // Enable output on PIN_PA5 (digital pin 1)
// // or PIN_PA3 (digital pin 4) on ATtiny402/202)
Comparator.input_p = comparator::in_p::in0; // Use positive input 0 (PD2/PA7)
Comparator.input_n = comparator::in_n::in0; // Use negative input 0 (PD3/PA6)
Comparator.output = comparator::out::enable; // Enable output - (PA7/PA5)

// Initialize comparator
Comparator.init();
Expand Down
Loading

0 comments on commit e67aa6a

Please sign in to comment.