Skip to content

Commit f39f785

Browse files
committed
maybe fix problems I added earlier
1 parent e3ebd25 commit f39f785

4 files changed

Lines changed: 95 additions & 40 deletions

File tree

megaavr/cores/megatinycore/timers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define DISABLE_MILLIS
1515
#endif
1616
#if (defined(MILLIS_USE_TIMERRTC_XTAL) || defined(MILLIS_USE_TIMERRTC_XOSC))
17+
#error Ping
1718
#define MILLIS_USE_TIMERRTC
1819
#endif
1920
#if !defined(TCA_PORTMUX)

megaavr/extras/Ref_Analog.md

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The differential ADC on the Dx-series is disappointing.
3636

3737

3838
## Reference Voltages
39-
Analog reference voltage can be selected as usual using analogReference(). Supported reference voltages are listed below:
39+
Analog reference voltage can be selected as usual using analogReference(). Supported reference voltages are listed below. The references available on the Dx and Ex parts are chosen from the same list as the tiny2's got to pick from, but somehow they wound up in a different order on these parts. You should never have to use the numbers (though that's all those constants are), unless your code loses track of what reference it has selected
4040
In some cases the voltage determines the maximum ADC clock speed. Call analogReference() before analogClockSpeed() to ensure that the analog clock speed is appropriate when any of these apply:
4141
* You are switching between internal and external/VDD reference on an Ex/2-series
4242
* You are using the half volt reference on the 0/1-series, or switching from that to another reference
@@ -51,28 +51,20 @@ In some cases the voltage determines the maximum ADC clock speed. Call analogRef
5151
| `INTERNAL2V5` | 2.50 V | - | 2 |
5252
| `INTERNAL4V3` | 4.30 V | - | 3 |
5353
| `INTERNAL1V5` | 1.50 V | - | 4 |
54-
| `EXTERNAL` | - | - | 32 | 1+series only
54+
| `EXTERNAL` | < VDD | - | 32 | 1+series only
55+
56+
| tinyAVR (2-series) or anything else | Voltage | Minimum Vdd | # tiny2| # Dx | Notes
57+
|-----------------------------------------|---------|-------------|--------|---------|-------
58+
| `VDD` (default) | Vcc/Vdd | | 0 | 5 | Good to 6 MHz ADC clock on 2-series and Ex
59+
| `INTERNAL1V024` | 1.024 V | 2.5* V | 4 | 0 | 10-bit reading with 1.025 ref gives apx. 1 mv/ADC count
60+
| `INTERNAL2V048` | 2.048 V | 2.5 V | 5 | 1 | 12-bit reading with 2.048 ref gives apx. 0.5 mv/ADC count
61+
| `INTERNAL4V096` | 4.096 V | 4.55 V | 7 | 2 | 12-bit reading with 4.096 ref gives apx. 1 mv/ADC count
62+
| `INTERNAL2V500` | 2.500 V | 2.7 V | 6 | 3 |
63+
| `INTERNAL4V1` (alias of INTERNAL4V096) | 4.096 V | 4.55 V | 7 | 2 |
64+
| `EXTERNAL` (tiny2/Ex version) | < VDD | VREF +0.5V | 2 | - | External ref good to 6 MHz ADC clock on 2-series and Ex
65+
| `EXTERNAL` (Dx-series) | 1.0-1.8 | VREF +0.5V | - | 6 | Dx: CLK_ADC =< 500 kHz
66+
| `EXTERNAL` (Dx-series) | 1.8-VDD | VREF +0.5V | - | 6 | Dx: Normal limits apply (see this document for DxCore for details)
5567

56-
| tinyAVR (2-series) or Ex-series | Voltage | Minimum Vdd | Number | Notes
57-
|-----------------------------------------|---------|-------------|--------|-------
58-
| `VDD` (default) | Vcc/Vdd | | 0 | VDD Ref works at 6 MHz CLK ADC!
59-
| `INTERNAL1V024` | 1.024 V | 2.5* V | 4 | 10-bit reading with 1.025 ref gives apx. 1 mv/ADC count
60-
| `INTERNAL2V048` | 2.048 V | 2.5 V | 5 | 12-bit reading with 2.048 ref gives apx. 0.5 mv/ADC count
61-
| `INTERNAL4V096` | 4.096 V | 4.55 V | 7 | 12-bit reading with 4.096 ref gives apx. 1 mv/ADC count
62-
| `INTERNAL2V500` | 2.500 V | 2.7 V | 6 |
63-
| `INTERNAL4V1` (alias of INTERNAL4V096) | 4.096 V | 4.55 V | 7 |
64-
| `EXTERNAL` | - | Vdd | 2 | External ref works at 6 MHz CLK ADC!
65-
66-
| AVR Dx/Ex-series | Voltage | Minimum Vdd | Number | Notes
67-
|-----------------------------------------|---------|-------------|--------|---------
68-
| `VDD` (default) | Vcc/Vdd | | 5 |
69-
| `INTERNAL1V024` | 1.024 V | 2.5* V | 0 | 10-bit reading with 1.025 ref gives apx. 1 mv/ADC count
70-
| `INTERNAL2V048` | 2.048 V | 2.5 V | 1 | 12-bit reading with 2.048 ref gives apx. 0.5 mv/ADC count
71-
| `INTERNAL4V096` | 4.096 V | 4.55 V | 2 | 12-bit reading with 4.096 ref gives apx. 1 mv/ADC count
72-
| `INTERNAL2V500` | 2.500 V | 2.7 V | 3 |
73-
| `INTERNAL4V1` (alias of INTERNAL4V096) | 4.096 V | 4.55 V | 2 |
74-
| `EXTERNAL` | >=1.0 V | Vdd | 6 | Dx: CLK_ADC =< 500 kHz
75-
| `EXTERNAL` | >=1.8 V | Vdd | 6 | Dx: No CLK_ADC restriction
7668

7769
You can test like `if(getAnalogReference()==INTERNAL2V500)`, but if you try to say, print them, you just get a number. That's what is shown in the last column: contains the numerical value of the constants representing these references. Don't use those, then nobody will understand your code - including yourself in two weeks. However, if you are printing the results of `getAnalogReference()` or `getDACReference()`, these are the numbers you will see.
7870

megaavr/libraries/Logic/Tricks_and_Tips.md

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ There are some simple patterns that you can use with the CCL/Logic library to ge
3939
* [Appendix I: The giant table of clock division via CCL](Tricks_and_Tips.md#appendix-I-the-giant-table-of-clock-division-via-ccl)
4040
* [An alternate approach to generating clock signals](Tricks_and_Tips.md#an-alternate-approach-to-generating-clock-signals)
4141
## Reordering inputs
42-
**THIS SECTION IGNORES THE MSB AND LSB OF THE TRUTH TABLE**
43-
There are four trivial variations on each of these with different behavior when all inputs are the same.
42+
**MOST OF THIS DISCUSSION (reordering) NEGLECTS THE MSB AND LSB, as the reordering behavior only effects the non-extremal values.**
4443

44+
There are four variations on each of these with different behavior when all inputs are the same, as the behavior with all 1's or all 0's is independent of what order they are in.
4545
These are not relevant to reordering. Reordering is confusing enough as is (and it really shouldn't be, but our brains aren't wired well for this I don't think)
4646

47-
TRUTH = 0bHGFEDCBA when IN0 is α, IN1 is β and IN2 is γ
48-
4947
To get identical behavior:
5048

49+
TRUTH = 0bHGFEDCBA when IN0 is α, IN1 is β and IN2 is γ
5150
TRUTH = 0bHDFBGCEA when IN0 is γ, IN1 is β and IN2 is α - D and G, B and E swap
5251
TRUTH = 0bHFGEDBCA when IN0 is α, IN1 is γ and IN2 is β - G and F, B and C swap
5352
TRUTH = 0bHGDCFEBA when IN0 is γ, IN1 is α and IN2 is β - F and D, E and C swap
54-
TRUTH = 0bHFDBGECA when IN0 is β, IN1 is γ and IN2 is α - F->G->D->F rotate, and B->E->C->B rotate.
5553
TRUTH = 0bHDGCFBEA when IN0 is β, IN1 is α and IN2 is γ - F->D->G->F rotate, and B->C->E->B rotate.
54+
TRUTH = 0bHFDBGECA when IN0 is β, IN1 is γ and IN2 is α - F->G->D->F rotate, and B->E->C->B rotate.
5655

5756
the highest and lowest bits do not change when reordering the inputs.
5857

@@ -69,7 +68,8 @@ These are cases that treat all inputs equally (the logic formulas are hideous or
6968
| 0x68 | 3/6 | HIGH if exactly two inputs are HIGH
7069
| 0x7E | 6/6 | HIGH in all cases except (potentially) when all three inputs are HIGH or all three inputs are LOW.
7170

72-
A significant number of options come in sets of three. These reflect cases where two inputs are treated the same, while a third is treated differently
71+
A significant number of options come in sets of threes; these indicate:
72+
1. All of these have a logical formula of (α [and|or] ())
7373

7474
| TRUTH & 0x7E | Bits set | Rationalization | Logic
7575
|------------------|----------|---------------------------------------------------------------------------------------------------------------|---------------
@@ -94,8 +94,37 @@ A significant number of options come in sets of three. These reflect cases where
9494
| 0x2C, 0x38, 0x4A, 0x58, 0x62, 0x64 | 3/6 | Opposite of the second | !(A xor B)
9595
| 0x2E, 0x3A, 0x4E, 0x5C, 0x72, 0x74 | 4/6 | Opposite of first | (!A or B)
9696

97+
I am unsure as the hoe
98+
9799
Each of the preceding 64 "middles" corresponds to 4 different truth tables. So 3E, 5E and 76
98100

101+
### Other simple transforms
102+
(Convention of A being in 0, C being in 2)
103+
TRUTH = 0bJKLMNOPQ
104+
Change | Truth change |
105+
--------|--------------|
106+
A -> !A | 0bKJMLONQP |
107+
B -> !B | 0bLMJKPQNO |
108+
C -> !C | 0bNOPQJKLM |
109+
110+
```c++
111+
112+
//A -> !A
113+
uint8_t newtruth = ((oldtruth & 0x55) << 1) | ((oldtruth & 0xAA) >> 1);
114+
115+
//B -> !B
116+
uint8_t newtruth = ((oldtruth & 0x33) << 2) | ((oldtruth & 0xCC) >> 2);
117+
118+
//C -> !C
119+
uint8_t newtruth = ((oldtruth & 0x0F) << 4) | ((oldtruth & 0xF0) >> 4);
120+
// Now this, if the compiler implements it, could end up looking hideous. There's actually a single instruction swap-nybble instruction, which is exposed by _swap()
121+
uint8_t newtruth = oldtruth;
122+
_swap(nettruth);
123+
//(this will not work correctly on 16-byte or 32-byte values; but arguably "swap the two nybbles" of a datatype with 4 or more of them is a malformed statement of intent)
124+
125+
```
126+
127+
99128
100129
## Examples
101130
@@ -310,20 +339,24 @@ Enable the synchronizer to get the analogous flip-flop.
310339
### S-R latch
311340

312341
INSEL:
313-
* X: Feedback
342+
* X: Clear (any input source)
314343
* Y: Set (any input source)
315-
* Z: Clear (any input source)
344+
* Z: Feedback
316345

317346
LUT:
318-
* 000: 0
319-
* 001: 1
320-
* 010: 1
321-
* 011: 1
322-
* 100: 0
323-
* 101: 0
324-
* 110: Per application requirements - logic block is getting contradictroy signals
325-
* 111: Per application requirements - logic block is getting contradictroy signals
326-
Ergo: TRUTH = 0x0b??001110 = 0x07 (go low when told to go both directions), 0xC7 (go high when...) or 0x47 (don't change when...). Avoid 0x87 (Oscillate rapidly at an unpredictable speed when...)
347+
* 000: 0 - feedback is 0 and neither control asserted -> does nothing
348+
* 001: 0 - feedback is 0 and clear asserted -> does nothing
349+
* 010: 1 - feedback is 0 and set asserted. -> 1
350+
* 011: - - Per app requirements. Currently a 0, forbidden state with both lines asserted.
351+
* 100: 1 - feedback is 1 and neither control asserted -> does nothing
352+
* 101: 0 - feedback is 1 but clear asserted -> 0
353+
* 110: 1 - feedback is 1. set asserted, does nothing. -> does nothing
354+
* 111: - - Per app requirements. Currently a 1, forbidden state with both lines asserted.
355+
Ergo: TRUTH = 0x0b?101?100 = 0x54, 0x5C, 0xD4 or 0xDC
356+
357+
It's clear that 0x5C is no good, unless you want it to oscillate at a very high rate when both control signals are high; you probably don't want that. The remaining ones have a simple relationship to eachother
358+
359+
0x54 will always go low in event of both controls being high, 0xDC will always go high, and 0xD4 will not change the output until one of the input signals is removed. Which one makes sense depends on your application and the kind of signals you can get access to easily.
327360

328361
Clock: N/A for latch, anything except IN2 as clock as demanded by application for flipflop.
329362

@@ -345,7 +378,9 @@ LUT:
345378
* 101: 0
346379
* 110: 1
347380
* 111: 1
348-
Ergo: TRUTH = 0xCB
381+
Ergo: TRUTH = 0xCB (corresponding to the 1...1 subtype of 0x4A above)
382+
383+
Unlike the RS case, there is only one coherent
349384

350385
Clock: N/A for latch, anything except IN2 as clock as demanded by application for flipflop.
351386

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* _SFR_MEM32(0x001C) is a dummy value. 0x001C is the first GPIOR.
2+
* but in practice, it doesn't matter since
3+
* #define _SFR_MEM32(mem_addr) _MMIO_DWORD(mem_addr)
4+
* and
5+
* _MMIO_DWORD(mem_addr) (*(volatile uint32_t *)(mem_addr))
6+
*
7+
* any volatile variable should do the trick just as well
8+
* _SFR_MEM32(0x001C) = (some 32-bit value) will store a 32-bit value in the 4 GPIO registers, which under typical circumstances takes
9+
* 4 words instead of 8 words.
10+
*/
11+
12+
void setup() {
13+
/* test manipulation functions */
14+
#ifndef MILLIS_USE_TIMERNONE
15+
stop_millis();
16+
set_millis(_SFR_MEM32(0x001C));
17+
restart_millis();
18+
#endif
19+
}
20+
void loop() {
21+
#ifndef MILLIS_USE_TIMERNONE
22+
_SFR_MEM32(0x001C)=millis();
23+
#ifndef MILLIS_USE_TIMERRTC
24+
_SFR_MEM32(0x001C)=micros();
25+
#endif
26+
#endif
27+
}

0 commit comments

Comments
 (0)