normal arduino boards has 10 bit ADC
but lgt8f328 has 12bit ADC so how to use 12bit ADC with emonlib to measure current?
is there any parameter need to set in the code?
If you look at the file, it will tell you in the comment very near the top.
// to enable 12-bit ADC resolution on Arduino Due,
// include the following line in main sketch inside setup() function:
// analogReadResolution(ADC_BITS);
// otherwise will default to 10 bits, as in regular Arduino-based boards.
#if defined(__arm__)
#define ADC_BITS 12
#else
#define ADC_BITS 10
#endif
The Due uses a SAM3X8E micorocontroller.
The lgt8f328 is an ATMEGA 328 knockoff with very different internals.
it is just engineered to be (somewhat) compatible with ATmega328p but their difference are substantial if you deep dive.
It has a RISC core and its core instructions are quite different from ATmega328p. Most multi-cycle instructions are replaced by single-cycle instructions or less cycle instructions. And the core runs at 32Mhz from 1.8V-5.5V.
The peripheral registers are largely (backward) compatible with ATmega328. However, LGT has more or advanced peripherals.
- 2 16-bit timers, with capture and compare output
- ADC has 12 bits instead of 10.
- DAC, so you don’t need PWM to emulate DAC.
- 9 high current PWM. 3 complementary PWM with dead band control.
- PGA 1x-32x differential amp. Which saved me 1 op-amp.
- 16 bit computing accelerator/Co-processor.
- High and adjustable current GPIO (so you can light up LEDs without current limiting resistors). These peripherals provide lots of additional registers for control and status reporting that don’t exist on ATmega.