• ATmega328PB and ADC

    From pozz@pozzugno@gmail.com to comp.arch.embedded on Wed Nov 13 12:36:48 2024
    From Newsgroup: comp.arch.embedded

    I couldn't understand if the first conversion after ADC is enabled (ADEN
    bit) must be discarded or not.

    The datasheet suggests to discard the first conversion result after
    changing the reference signal, but nothing after enabling ADC or
    changing input signal (ADMUX).

    The only note is about the conversion time that is longer for the first conversion after ADC is enabled.

    I'm asking this question because I'm noting a different behaviour if I
    start conversion and enable ADC at the same time for each conversion
    against leaving ADC enabled and starting only the conversion (ADSC bit).

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From pozz@pozzugno@gmail.com to comp.arch.embedded on Wed Nov 20 09:40:43 2024
    From Newsgroup: comp.arch.embedded

    Il 13/11/2024 12:36, pozz ha scritto:
    I couldn't understand if the first conversion after ADC is enabled (ADEN bit) must be discarded or not.

    The datasheet suggests to discard the first conversion result after
    changing the reference signal, but nothing after enabling ADC or
    changing input signal (ADMUX).

    The only note is about the conversion time that is longer for the first conversion after ADC is enabled.

    I'm asking this question because I'm noting a different behaviour if I
    start conversion and enable ADC at the same time for each conversion
    against leaving ADC enabled and starting only the conversion (ADSC bit).

    For the future readers, I found my issue. Occasionally I put the MCU in
    sleep mode after enabling ADC and starting conversion. Even if ADC clock
    still runs in this mode, the result is not good.

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From David Brown@david.brown@hesbynett.no to comp.arch.embedded on Wed Nov 20 17:23:15 2024
    From Newsgroup: comp.arch.embedded

    On 20/11/2024 09:40, pozz wrote:
    Il 13/11/2024 12:36, pozz ha scritto:
    I couldn't understand if the first conversion after ADC is enabled
    (ADEN bit) must be discarded or not.

    The datasheet suggests to discard the first conversion result after
    changing the reference signal, but nothing after enabling ADC or
    changing input signal (ADMUX).

    The only note is about the conversion time that is longer for the
    first conversion after ADC is enabled.

    I'm asking this question because I'm noting a different behaviour if I
    start conversion and enable ADC at the same time for each conversion
    against leaving ADC enabled and starting only the conversion (ADSC bit).

    For the future readers, I found my issue. Occasionally I put the MCU in sleep mode after enabling ADC and starting conversion. Even if ADC clock still runs in this mode, the result is not good.


    It is a while since I have used AVRs, but it sounds to me like you are
    doing something wrong. You should get /better/ results if you put the
    micro to sleep immediately after starting a conversion. This is a well-established technique for getting higher accuracy from small microcontroller ADCs, as you reduce the general digital noise in the
    system. But you might have to pick the right kind of sleep mode.

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From pozz@pozzugno@gmail.com to comp.arch.embedded on Thu Nov 21 08:28:25 2024
    From Newsgroup: comp.arch.embedded

    Il 20/11/2024 17:23, David Brown ha scritto:
    On 20/11/2024 09:40, pozz wrote:
    Il 13/11/2024 12:36, pozz ha scritto:
    I couldn't understand if the first conversion after ADC is enabled
    (ADEN bit) must be discarded or not.

    The datasheet suggests to discard the first conversion result after
    changing the reference signal, but nothing after enabling ADC or
    changing input signal (ADMUX).

    The only note is about the conversion time that is longer for the
    first conversion after ADC is enabled.

    I'm asking this question because I'm noting a different behaviour if
    I start conversion and enable ADC at the same time for each
    conversion against leaving ADC enabled and starting only the
    conversion (ADSC bit).

    For the future readers, I found my issue. Occasionally I put the MCU
    in sleep mode after enabling ADC and starting conversion. Even if ADC
    clock still runs in this mode, the result is not good.


    It is a while since I have used AVRs, but it sounds to me like you are
    doing something wrong.  You should get /better/ results if you put the micro to sleep immediately after starting a conversion.  This is a well-established technique for getting higher accuracy from small microcontroller ADCs, as you reduce the general digital noise in the system.  But you might have to pick the right kind of sleep mode.


    Yes, you're right. However for AVRs the mechanism is different than what
    you described.

    If you want to start a /better/ ADC conversion, you should enable ADC peripheral and ADC interrupt and put the MCU in sleep mode (one specific
    sleep mode). This procedure automatically starts the ADC
    "super-accurate" conversion.

    In my case, I was starting the ADC in my code before entering sleep mode
    and this is not the correct procedure.

    Just for curiosity, I don't need high accuracy, so it's good to make conversion while the MCU is in active mode.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From David Brown@david.brown@hesbynett.no to comp.arch.embedded on Thu Nov 21 09:00:00 2024
    From Newsgroup: comp.arch.embedded

    On 21/11/2024 08:28, pozz wrote:
    Il 20/11/2024 17:23, David Brown ha scritto:
    On 20/11/2024 09:40, pozz wrote:
    Il 13/11/2024 12:36, pozz ha scritto:
    I couldn't understand if the first conversion after ADC is enabled
    (ADEN bit) must be discarded or not.

    The datasheet suggests to discard the first conversion result after
    changing the reference signal, but nothing after enabling ADC or
    changing input signal (ADMUX).

    The only note is about the conversion time that is longer for the
    first conversion after ADC is enabled.

    I'm asking this question because I'm noting a different behaviour if
    I start conversion and enable ADC at the same time for each
    conversion against leaving ADC enabled and starting only the
    conversion (ADSC bit).

    For the future readers, I found my issue. Occasionally I put the MCU
    in sleep mode after enabling ADC and starting conversion. Even if ADC
    clock still runs in this mode, the result is not good.


    It is a while since I have used AVRs, but it sounds to me like you are
    doing something wrong.  You should get /better/ results if you put the
    micro to sleep immediately after starting a conversion.  This is a
    well-established technique for getting higher accuracy from small
    microcontroller ADCs, as you reduce the general digital noise in the
    system.  But you might have to pick the right kind of sleep mode.


    Yes, you're right. However for AVRs the mechanism is different than what
    you described.

    If you want to start a /better/ ADC conversion, you should enable ADC peripheral and ADC interrupt and put the MCU in sleep mode (one specific sleep mode). This procedure automatically starts the ADC
    "super-accurate" conversion.

    In my case, I was starting the ADC in my code before entering sleep mode
    and this is not the correct procedure.

    Just for curiosity, I don't need high accuracy, so it's good to make conversion while the MCU is in active mode.

    It's certainly better to keep the MCU active than use the /wrong/ sleep
    mode or sequence!

    Sleep modes are useful if you need to have low power (for battery use,
    or to avoid heating), but they can complicate things a bit. I usually
    don't bother with sleep modes unless I have a particularly good reason
    for them.

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From pozz@pozzugno@gmail.com to comp.arch.embedded on Thu Nov 21 09:04:33 2024
    From Newsgroup: comp.arch.embedded

    Il 21/11/2024 09:00, David Brown ha scritto:
    On 21/11/2024 08:28, pozz wrote:
    Il 20/11/2024 17:23, David Brown ha scritto:
    On 20/11/2024 09:40, pozz wrote:
    Il 13/11/2024 12:36, pozz ha scritto:
    I couldn't understand if the first conversion after ADC is enabled
    (ADEN bit) must be discarded or not.

    The datasheet suggests to discard the first conversion result after >>>>> changing the reference signal, but nothing after enabling ADC or
    changing input signal (ADMUX).

    The only note is about the conversion time that is longer for the
    first conversion after ADC is enabled.

    I'm asking this question because I'm noting a different behaviour
    if I start conversion and enable ADC at the same time for each
    conversion against leaving ADC enabled and starting only the
    conversion (ADSC bit).

    For the future readers, I found my issue. Occasionally I put the MCU
    in sleep mode after enabling ADC and starting conversion. Even if
    ADC clock still runs in this mode, the result is not good.


    It is a while since I have used AVRs, but it sounds to me like you
    are doing something wrong.  You should get /better/ results if you
    put the micro to sleep immediately after starting a conversion.  This
    is a well-established technique for getting higher accuracy from
    small microcontroller ADCs, as you reduce the general digital noise
    in the system.  But you might have to pick the right kind of sleep mode. >>>

    Yes, you're right. However for AVRs the mechanism is different than
    what you described.

    If you want to start a /better/ ADC conversion, you should enable ADC
    peripheral and ADC interrupt and put the MCU in sleep mode (one
    specific sleep mode). This procedure automatically starts the ADC
    "super-accurate" conversion.

    In my case, I was starting the ADC in my code before entering sleep
    mode and this is not the correct procedure.

    Just for curiosity, I don't need high accuracy, so it's good to make
    conversion while the MCU is in active mode.

    It's certainly better to keep the MCU active than use the /wrong/ sleep
    mode or sequence!

    Sleep modes are useful if you need to have low power (for battery use,
    or to avoid heating), but they can complicate things a bit.  I usually don't bother with sleep modes unless I have a particularly good reason
    for them.

    Yes, absolutely

    --- Synchronet 3.20a-Linux NewsLink 1.114