This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52820 COMP issue

Hello everyone!

I have some issue with the comparator module on the nrf52820 chip.

We need to compare one of external analog signal the 1.8V internal reference source. (But other variants – 1.2V / 2.4V don’t work either)

When I set 0 Volt on the measurement contact – the result of comparison is correct (0).

But as soon as I increase voltage, even on 0.1V - the result immediately becomes incorrect (1).

 

Moreover, I tried to use differential mode (just for an experiment).

In that mode comparison is performed relative to the reference signal on the external pin.

So, in that mode comparisons are performed perfect.  

 

It seems for me there are some problems with internal reference source.

We develop the software for the nrf52820  mcu but at this moment we haven't received our boards and use the nrf52833 development kit for  debug.

Could the problem be caused by that?

Also I thought that the problem might be with my board and tried to use others. But unfortunetely  the result is the same. 

Could you please help me with it?

Many thanks in advance!

All the best!

Ernst

Parents
  • Hello Ernst,

    It seems for me there are some problems with internal reference source.

    We develop the software for the nrf52820  mcu but at this moment we haven't received our boards and use the nrf52833 development kit for  debug.

    Good work debugging it with differential mode, this is very helpful! I have never heard of this being an issue before - the emulation of the nRF52820 on the nRF52833 is very straight forward, since the nRF52820 is a subset of the nRF52833.

    Are there any errors being generated when your program is running?
    Could you ensure that DEBUG is defined in your preprocessor defines, like shown in the included image?

    Enabling DEBUG in the preprocessor defines will output a detailed error message to your logger backend, in the case that a non-NRF_SUCCESS error is passed to an APP_ERROR_CHECK.

    Could you also tell me how you are measuring / monitoring the voltage you are applying to the chosen compare pin, so that you know that it is exactly 0.1 V?

    It would also be very helpful to see the your code here, particularly for the initiation and configuration of the comp peripheral.
    Please use the "Insert->Code" option when sharing code here on DevZone.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

  • Hello, Karl!

    Many thanks for the answer!

    Are there any errors being generated when your program is running?
    Could you ensure that DEBUG is defined in your preprocessor defines, like shown in the included image?

    I've tried to do that, but I still don't see any errors.

    Could you also tell me how you are measuring / monitoring the voltage you are applying to the chosen compare pin, so that you know that it is exactly 0.1 V?

    I use an oscilloscope connected to the measurement pin and a laboratory power supply's voltmeter.

    It would also be very helpful to see the your code here, particularly for the initiation and configuration of the comp peripheral.
    Please use the "Insert->Code" option when sharing code here on DevZone.

    Yes, sure.

    I've attached that code bellow.

    //--------------------------------------------------------------------------------------------------
    void COINCELL_vInit(void)
    {
      nrf_comp_ref_set(NRF_COMP_REF_Int1V8);
      nrf_comp_main_mode_set(NRF_COMP_MAIN_MODE_SE);
      nrf_comp_speed_mode_set(NRF_COMP_SP_MODE_High);
      nrf_comp_hysteresis_set(NRF_COMP_HYST_NoHyst);
      nrf_comp_input_select(NRF_COMP_INPUT_0);
      nrf_comp_enable();
      
      nrf_comp_task_trigger(NRF_COMP_TASK_START);
      while(!nrf_comp_event_check(NRF_COMP_EVENT_READY));
    }
    
    //--------------------------------------------------------------------------------------------------
    void COINCELL_vUpdate(void)
    {
      nrf_comp_task_trigger(NRF_COMP_TASK_SAMPLE);
      //sCoincell.bCellAboveTresshold = (nrf_comp_result_get() > 0) ? bTRUE : bFALSE;
    
      // Debug only section 
      uint32_t a = nrf_comp_result_get();
      if (a)
      {
        a = 1;
      }
      else 
      {
        a = 1;
      }
      // ------------
    }

    Many thanks for helping!

    Have a nice day!

    Best regards,

    Ernst

  • Hello again Ernst,

    Ernst Smirnov said:
    Many thanks for the answer!

    No problem at all, I am happy to help! :) 

    Ernst Smirnov said:
    I've tried to do that, but I still don't see any errors.
    Ernst Smirnov said:
    I use an oscilloscope connected to the measurement pin and a laboratory power supply's voltmeter.
    Ernst Smirnov said:

    Yes, sure.

    I've attached that code bellow.

    Thank you for clarifying, this is very helpful.

    Are you using the UP, DOWN, and CROSS events in your testing, or are you only checking the value of the result register through the nrf_comp_result_get function?

    Could you explain the intent behind the debug section of your COINCELL_vUpdate function? I am not sure I understand its purpose / what you might be using this for.
    How did you verify/check that the output of the comparison always was 1 when the voltage of the input was higher than 0V?

    Ernst Smirnov said:
    Have a nice day!

    Thank you for saying that - I hope you have a nice day as well! 

    Looking forward to resolving this issue together.

    Best regards,
    Karl

  • No problem at all, I am happy to help! :) 

    I'm glad to see it, thank you)

    Are you using the UP, DOWN, and CROSS events in your testing, or are you only checking the value of the result register through the nrf_comp_result_get function?

    Yes, I just checking the value of the result register after starting the NRF_COMP_TASK_SAMPLE task.

    Is it incorrect?

    Could you explain the intent behind the debug section of your COINCELL_vUpdate function? I am not sure I understand its purpose / what you might be using this for.

    Sure! I start a debug session and put a break point to one of these lines. After that I adjust of a power source and so I can see comparison result has changed.

    How did you verify/check that the output of the comparison always was 1 when the voltage of the input was higher than 0V?

    I see it on the debug session. If the voltage of the input is higher than 0V I get the first branch of the debug condition only. However, as soon as I decrease that to zero - I get the second branch immediately.

    Looking forward to resolving this issue together.

    Many thanks for your concern, Karl!

    With kind regards

    Ernst

  • Hello again Ernst,

    Ernst Smirnov said:

    Yes, I just checking the value of the result register after starting the NRF_COMP_TASK_SAMPLE task.

    Is it incorrect?

    No, this is fine. I was just wondering whether you were using the events as well.

    Ernst Smirnov said:
    Sure! I start a debug session and put a break point to one of these lines. After that I adjust of a power source and so I can see comparison result has changed.
    Ernst Smirnov said:
    I see it on the debug session. If the voltage of the input is higher than 0V I get the first branch of the debug condition only. However, as soon as I decrease that to zero - I get the second branch immediately.

    Thank you for clarifying, this makes it a lot clearer, and I now understand how you are using this for debugging with breakpoints only, and not as a way to monitor the value of 'a' - I just had to make sure. 

    I see now that you do never set your TH registers - I'm sorry that I missed this the first time I looked through your code. You are currently not setting the TH register, which the VUP and VDOWN is derived from. Their default value is 0, which means your thresholds place at 1.8V/64 = 0.028 V. This could be why you are seeing the change immediately after manually increasing the voltage. If you want the reference level to be at exactly 1.8V with no hysteresis, please change them both to the value 63, so that the threshold is placed at 1.8V.
    You can set your TH register by using the nrf_comp_th_set function.
    Please try this, and let me know if it resolves your issue! :) 

    If this does not resolve your issue, could you possibly send me a stripped down version of the project, so I may test this on my end, and see if I am able to reproduce the issue?

    Best regards,
    Karl

  • Hello Karl!

    f you want the reference level to be at exactly 1.8V with no hysteresis, please change them both to the value 63

    Yes!

    Thank you very very much!!  Now it works like a charm!

    Could you please explain a bit why definitely 63 if it's possible?

    I tried to find it in the documentation, but I couldn't do that.

    Many thanks Karl, for your time. It's really helpful for us!

    Best Regards,

    Ernst

  • Ernst Smirnov said:
    Thank you very very much!!  Now it works like a charm!

    No problem at all, Ernst! I am glad to hear that it is now working as intended :) 

    Ernst Smirnov said:

    Could you please explain a bit why definitely 63 if it's possible?

    I tried to find it in the documentation, but I couldn't do that.

    The VDOWN and VUP values are the thresholds the COMP peripheral uses as reference, which is set by configuring the THDOWN and THUP in the TH register. Each of them hold the value of 0-63, as indicated in the documentation. So, unless these are set to 63, you are not comparing it against the full chosen reference voltage, which is 1.8V.

    Ernst Smirnov said:
    Many thanks Karl, for your time. It's really helpful for us!

    I am happy to help, Ernst!

    Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Reply
  • Ernst Smirnov said:
    Thank you very very much!!  Now it works like a charm!

    No problem at all, Ernst! I am glad to hear that it is now working as intended :) 

    Ernst Smirnov said:

    Could you please explain a bit why definitely 63 if it's possible?

    I tried to find it in the documentation, but I couldn't do that.

    The VDOWN and VUP values are the thresholds the COMP peripheral uses as reference, which is set by configuring the THDOWN and THUP in the TH register. Each of them hold the value of 0-63, as indicated in the documentation. So, unless these are set to 63, you are not comparing it against the full chosen reference voltage, which is 1.8V.

    Ernst Smirnov said:
    Many thanks Karl, for your time. It's really helpful for us!

    I am happy to help, Ernst!

    Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Children
No Data
Related