summaryrefslogtreecommitdiff
path: root/src/peripherals/avrdx-vref.ts
blob: 009709663d6527fb5757d3431f6e136d05ea7e52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// AVR-Dx VREF peripheral
// Voltage reference selection for DAC0 and ADC0

import { CPU } from 'avr8js/cpu/cpu';

const ADC0REF = 0;
const DAC0REF = 2;

const VREF_VOLTAGES = [1.024, 2.048, 2.500, 4.096] as const;

export class AVRDxVREF {
  constructor(private cpu: CPU, private base: number) {
  }

  /** Get DAC Vref selection (raw register value) */
  get dacRef(): number {
    return this.cpu.data[this.base + DAC0REF] & 0x07;
  }

  get dacRefVolts(): number {
    return VREF_VOLTAGES[this.dacRef] ?? 0;
  }

  /** Get ADC Vref selection (raw register value) */
  get adcRef(): number {
    return this.cpu.data[this.base + ADC0REF] & 0x07;
  }

  get adcRefVolts(): number {
    return VREF_VOLTAGES[this.adcRef] ?? 0;
  }
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.