45 switch((select >> 6) & 0x3) {
69 switch(((select >> 6) & 0x3) | ((select >> 2) & 0x4)) {
94 int oldSelect = muxSelect;
95 muxSelect = select & 0xf;
100 if((notifyClient != NULL) && (oldSelect != muxSelect))
101 notifyClient->NotifySignalChanged();
105 Pin *selected = ad[muxSelect];
106 if((notifyClient != NULL) && (selected == p))
107 notifyClient->NotifySignalChanged();
136 int adChannel = select & 0x07;
138 avr_warning(
"adc multiplexer has selected non existent channel %d", adChannel);
191 int adChannel = select & 0x0f;
197 avr_warning(
"adc multiplexer has selected non existent channel %d", adChannel);
204 int adChannel = select & 0x07;
216 HWAdmuxM8(c, _ad0, _ad1, _ad2, _ad3, _ad4, _ad5, _ad6, _ad7) { }
219 int adChannel = select & 0x1f;
226 if(adChannel >= 24) {
230 if(adChannel >= 16) {
234 if((adChannel == 8) || (adChannel == 9) || (adChannel == 12) || (adChannel == 13)) {
235 float neg =
ad[(adChannel > 9) ? 2 : 0]->GetAnalogValue(vcc);
237 return (
ad[0]->GetAnalogValue(vcc) - neg) * 10.0;
239 return (
ad[1]->GetAnalogValue(vcc) - neg) * 10.0;
241 return (
ad[2]->GetAnalogValue(vcc) - neg) * 10.0;
242 return (
ad[3]->GetAnalogValue(vcc) - neg) * 10.0;
244 float neg =
ad[(adChannel > 11) ? 2 : 0]->GetAnalogValue(vcc);
246 return (
ad[0]->GetAnalogValue(vcc) - neg) * 200.0;
248 return (
ad[1]->GetAnalogValue(vcc) - neg) * 200.0;
250 return (
ad[2]->GetAnalogValue(vcc) - neg) * 200.0;
251 return (
ad[3]->GetAnalogValue(vcc) - neg) * 200.0;
255 int adChannel = select & 0x1f;
256 return (adChannel >= 8) && (adChannel < 30);
266 int adChannel = select & 0xf;
269 if(adChannel == 14) {
270 avr_warning(
"adc multiplexer has selected non existent channel %d", adChannel);
281 return (
ad[2]->GetAnalogValue(vcc) -
ad[2]->GetAnalogValue(vcc)) * 1.0;
283 return (
ad[2]->GetAnalogValue(vcc) -
ad[2]->GetAnalogValue(vcc)) * 20.0;
285 return (
ad[2]->GetAnalogValue(vcc) -
ad[3]->GetAnalogValue(vcc)) * 1.0;
287 return (
ad[2]->GetAnalogValue(vcc) -
ad[3]->GetAnalogValue(vcc)) * 20.0;
289 return (
ad[0]->GetAnalogValue(vcc) -
ad[0]->GetAnalogValue(vcc)) * 1.0;
291 return (
ad[0]->GetAnalogValue(vcc) -
ad[0]->GetAnalogValue(vcc)) * 20.0;
293 return (
ad[0]->GetAnalogValue(vcc) -
ad[1]->GetAnalogValue(vcc)) * 1.0;
295 return (
ad[0]->GetAnalogValue(vcc) -
ad[1]->GetAnalogValue(vcc)) * 20.0;
299 int adChannel = select & 0xf;
300 return (adChannel >= 4) && (adChannel < 12);
355 bool high_channel = ((select & 0x20) == 0x20);
356 int adChannel = select & 0x1f;
357 if(adChannel == 31) {
364 if(adChannel == 30) {
372 int sel = adChannel + (high_channel ? 8 : 0);
376 if(adChannel >= 24) {
377 float neg =
ad[2 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc);
378 return ad[adChannel - 24 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg;
380 if(adChannel >= 16) {
381 float neg =
ad[1 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc);
382 return ad[adChannel - 16 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg;
384 if((adChannel == 8) || (adChannel == 9) || (adChannel == 12) || (adChannel == 13)) {
385 float neg =
ad[((adChannel > 9) ? 2 : 0) + (high_channel ? 8 : 0)]->GetAnalogValue(vcc);
387 return (
ad[0 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 10.0;
389 return (
ad[1 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 10.0;
391 return (
ad[2 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 10.0;
392 return (
ad[3 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 10.0;
394 float neg =
ad[((adChannel > 11) ? 2 : 0) + (high_channel ? 8 : 0)]->GetAnalogValue(vcc);
396 return (
ad[0 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 200.0;
398 return (
ad[1 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 200.0;
400 return (
ad[2 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 200.0;
401 return (
ad[3 + (high_channel ? 8 : 0)]->GetAnalogValue(vcc) - neg) * 200.0;
414 adch_reg(this,
"ADCH", this, &
HWAd::GetAdch, 0),
415 adcl_reg(this,
"ADCL", this, &
HWAd::GetAdcl, 0),
416 adcsra_reg(this,
"ADCSRA", this, &
HWAd::GetAdcsrA, &
HWAd::SetAdcsrA),
417 adcsrb_reg(this,
"ADCSRB", this, &
HWAd::GetAdcsrB, &
HWAd::SetAdcsrB),
418 admux_reg(this,
"ADMUX", this, &
HWAd::GetAdmux, &
HWAd::SetAdmux) {
579 int adcmax = (1 << 9) - 1;
580 int adcmin = -(1 << 9);
584 else if(value < -ref)
593 return ((
int)((value * (adcmax + 1)) / ref)) & 0x3ff;
598 int adcmax = (1 << 10) - 1;
608 return (
int)((value * (adcmax + 1)) / ref);
651 fullMux = fullMux | 0x20;
676 traceOut <<
"ADC result lost, adch is locked!" << std::endl;
678 std::cerr <<
"AD-Result lost adch is locked!" << std::endl;
706 HWAd(c, _typ, i, iv, a, r),
713 adts = (nv >> 5) & 0x7;
virtual int GetTriggerSource(void)
Basic AVR device, contains the core functionality.
HWARef4(AvrDevice *_core, int _type)
0:aref, 1:vcc, 2:bg, 3:2.56V
virtual bool IsDifferenceChannel(int select)
void AddToCycleList(Hardware *hw)
virtual float GetRefValue(int select, float vcc)=0
Pin class, handles input and output to external parts.
void SetAdcsrB(unsigned char)
virtual float GetValueAComp(int select, float vcc)
AnalogSignalChange * notifyClient
ADC reference is taken from special ADREF pin (no port pin)
HWAdmuxM8(AvrDevice *c, Pin *_ad0, Pin *_ad1, Pin *_ad2, Pin *_ad3)
virtual float GetValue(int select, float vcc)
void RegisterPin(const std::string &name, Pin *p)
void connectSRegClient(IOSpecialRegClient *c)
Registers a client to this IO register to inform this client on read or write access.
void RegisterNotifyClient(AnalogSignalChange *client)
virtual float GetRefValue(int select, float vcc)
void ClearIrqFlag(unsigned int vec)
virtual float GetRefValue(int select, float vcc)
bool IsPrescalerClock(void)
HWAdmux6(AvrDevice *c, Pin *_ad0, Pin *_ad1, Pin *_ad2, Pin *_ad3, Pin *_ad4, Pin *_ad5)
int ConversionUnipolar(float value, float ref)
virtual float GetValue(int select, float vcc)=0
int numPins
Multiplexer channel, can't be used for ADC sampling because of buffering on conversion start! ...
ADC type M2560: ADC on atmega2560.
Build a register for TraceValue's.
void PinStateHasChanged(Pin *)
ADC type M8: ADC on atmega8.
ADC type M64: ADC on atmega64.
void SetIrqFlag(Hardware *, unsigned int vector_index)
Reference source for ADC (base class)
virtual float GetValue(int select, float vcc)
unsigned char GetAdch(void)
int ConversionBipolar(float value, float ref)
virtual float GetValue(int select, float vcc)
void SetAdcsrA(unsigned char)
void SetAdmux(unsigned char val)
HWAd_SFIOR(AvrDevice *c, int _typ, HWIrqSystem *i, unsigned int iv, HWAdmux *a, HWARef *r, IOSpecialReg *s)
void RegisterCallback(HasPinNotifyFunction *)
ADC type 4433: ADC on at90s/l4433.
void SetMuxSelect(int select)
virtual void NotifySignalChanged(void)=0
Pin v_supply
represents supply voltage level, needed for analog peripherals
ADC type T25: ADC on attiny25/45/85.
bool IsADEnabled(void)
Check, if ADC is enabled.
ADC type M128: ADC on atmega128.
AnalogSignalChange * notifyClient
Pin v_bandgap
represents bandgap (ref) voltage level, needed for analog peripherals
void DebugVerifyInterruptVector(unsigned int vector_index, const Hardware *source)
In datasheets RESET vector is index 1 but we use 0! And not a byte address.
virtual bool IsDifferenceChannel(int select)
virtual float GetValue(int select, float vcc)
HWAdmuxT25(AvrDevice *c, Pin *_ad0, Pin *_ad1, Pin *_ad2, Pin *_ad3)
void NotifySignalChanged(void)
void ClearIrqFlag(unsigned int vector_index)
bool GetFuseBit(int index)
Get fuse bit by bit index, starts with 0 on lfuse bit 0, bit = 0 means true!
unsigned char GetAdcl(void)
HWAdmuxM2560(AvrDevice *c, Pin *_ad0, Pin *_ad1, Pin *_ad2, Pin *_ad3, Pin *_ad4, Pin *_ad5, Pin *_ad6, Pin *_ad7, Pin *_ad8, Pin *_ad9, Pin *_ad10, Pin *_ad11, Pin *_ad12, Pin *_ad13, Pin *_ad14, Pin *_ad15)
float GetRawAnalog(void) const
get back raw analog value (just variable content!)
HWARefPin(AvrDevice *_core)
HWAdmuxM16(AvrDevice *c, Pin *_ad0, Pin *_ad1, Pin *_ad2, Pin *_ad3, Pin *_ad4, Pin *_ad5, Pin *_ad6, Pin *_ad7)
HWAd(AvrDevice *c, int _typ, HWIrqSystem *i, unsigned int iv, HWAdmux *a, HWARef *r)
virtual float GetRefValue(int select, float vcc)
float GetAnalogValue(float vcc)
Returns real analog input value of pin.
virtual bool IsDifferenceChannel(int select)
ADC type M48: ADC on atmega48/88/168/328.
virtual float GetValue(int select, float vcc)
unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv)