You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: megaavr/extras/Ref_Analog.md
+14-22Lines changed: 14 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ The differential ADC on the Dx-series is disappointing.
36
36
37
37
38
38
## 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
40
40
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:
41
41
* You are switching between internal and external/VDD reference on an Ex/2-series
42
42
* 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
51
51
|`INTERNAL2V5`| 2.50 V | - | 2 |
52
52
|`INTERNAL4V3`| 4.30 V | - | 3 |
53
53
|`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
| `EXTERNAL` | >=1.8 V | Vdd | 6 | Dx: No CLK_ADC restriction
76
68
77
69
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.
Copy file name to clipboardExpand all lines: megaavr/libraries/Logic/Tricks_and_Tips.md
+53-18Lines changed: 53 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,20 +39,19 @@ There are some simple patterns that you can use with the CCL/Logic library to ge
39
39
*[Appendix I: The giant table of clock division via CCL](Tricks_and_Tips.md#appendix-I-the-giant-table-of-clock-division-via-ccl)
40
40
*[An alternate approach to generating clock signals](Tricks_and_Tips.md#an-alternate-approach-to-generating-clock-signals)
41
41
## 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.**
44
43
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.
45
45
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)
46
46
47
-
TRUTH = 0bHGFEDCBA when IN0 is α, IN1 is β and IN2 is γ
48
-
49
47
To get identical behavior:
50
48
49
+
TRUTH = 0bHGFEDCBA when IN0 is α, IN1 is β and IN2 is γ
51
50
TRUTH = 0bHDFBGCEA when IN0 is γ, IN1 is β and IN2 is α - D and G, B and E swap
52
51
TRUTH = 0bHFGEDBCA when IN0 is α, IN1 is γ and IN2 is β - G and F, B and C swap
53
52
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.
55
53
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.
56
55
57
56
the highest and lowest bits do not change when reordering the inputs.
58
57
@@ -69,7 +68,8 @@ These are cases that treat all inputs equally (the logic formulas are hideous or
69
68
| 0x68 | 3/6 | HIGH if exactly two inputs are HIGH
70
69
| 0x7E | 6/6 | HIGH in all cases except (potentially) when all three inputs are HIGH or all three inputs are LOW.
71
70
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] ())
73
73
74
74
| TRUTH & 0x7E | Bits set | Rationalization | Logic
// 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
+
99
128
100
129
## Examples
101
130
@@ -310,20 +339,24 @@ Enable the synchronizer to get the analogous flip-flop.
310
339
### S-R latch
311
340
312
341
INSEL:
313
-
* X: Feedback
342
+
* X: Clear (any input source)
314
343
* Y: Set (any input source)
315
-
* Z: Clear (any input source)
344
+
* Z: Feedback
316
345
317
346
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.
327
360
328
361
Clock: N/A for latch, anything except IN2 as clock as demanded by application for flipflop.
329
362
@@ -345,7 +378,9 @@ LUT:
345
378
* 101: 0
346
379
* 110: 1
347
380
* 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
349
384
350
385
Clock: N/A for latch, anything except IN2 as clock as demanded by application for flipflop.
0 commit comments