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

comp or lpcomp for 2 analog inputs with different v-- (ref)

i am working with nrf52832

i need to check 2 analog inputs and set my own v- (ref) 

i can have value read every few seconds so no fast readings needs to be done 

if i understand correctly i better use lpcomp if no fast readings is needed?

also,  is it possible, and if there are some code examples, to be reading 2 analog inputs with 2 different v-- (references) (one for each input pin) ?

best regards

Ziv

Parents
  • Hello, 

    if i understand correctly i better use lpcomp if no fast readings is needed?

    Yes, Lpcomp is good for low-power readings of pin state changes. Have you seen the documentation for the LPCOMP peripheral, and the lpcomp example in the SDK?

    also,  is it possible, and if there are some code examples, to be reading 2 analog inputs with 2 different v-- (references) (one for each input pin) ?

    We have no examples demonstrating this directly, but you may modify the lpcomp example to use the external references on pins AIN0 and AIN1.
    Since the LPCOMP is only made to monitor one pin at the time, you will have to switch between the two pins and their references, to check the levels.

    Have you considered using the SAADC with differential ended input instead of the LPCOMP?
    Depending on your application, this might be both easier to implement and more precise.

    Best regards,
    Karl

Reply
  • Hello, 

    if i understand correctly i better use lpcomp if no fast readings is needed?

    Yes, Lpcomp is good for low-power readings of pin state changes. Have you seen the documentation for the LPCOMP peripheral, and the lpcomp example in the SDK?

    also,  is it possible, and if there are some code examples, to be reading 2 analog inputs with 2 different v-- (references) (one for each input pin) ?

    We have no examples demonstrating this directly, but you may modify the lpcomp example to use the external references on pins AIN0 and AIN1.
    Since the LPCOMP is only made to monitor one pin at the time, you will have to switch between the two pins and their references, to check the levels.

    Have you considered using the SAADC with differential ended input instead of the LPCOMP?
    Depending on your application, this might be both easier to implement and more precise.

    Best regards,
    Karl

Children
  • thanks Karl

    since i can comp (or lpcomp) only one input pin each time and to switch between them i have to go through the handler and CPU anyway the COMP option in my case doesn't really helps

    i have started working on configuring and reading the 3 inputs pin with saadc driver, it is also not so easy, for example it is not possible to do OVERSAMPLING with multiple pins (aka SCAN MODE) (i did made a small change to the NRFX_SAADC.C file to achieve just that) but actually it is still not so clear to me how to manage the 3 inputs if i want to read each one of the in a different timing and is less CPU intervention as possible (i saw the saadc example with the timer and ppi but i am not sure how to manage that with 3 inputs, i have tried to look for a way to change the configured pin with in the saadc event handler but it fail) 

    if the saadc is kind of a new topic it is possible to close this post (i am not sure how to do that)

    best regards

    Ziv

  • Hello Ziv,

    I understand. I saw your other ticket, and your workaround for using oversampling with scan mode - in order to get the correct results then you should also make sure that burst is enabled on every channel.
    As for how to manage the three inputs in the least CPU intensive way, I would have to suggest setting up three timers and connecting them to the sample task through PPI. I have not tried this myself, but I recall reading that you may have multiple events connected to the same task just fine - you could try this and see if it fits your requirements.
    In this case, you would need to discard the measurements on the channels you are not interested in at that particular time - since the SAADC in scan mode will sample every enabled channel each time.

    ziv123 said:
    if the saadc is kind of a new topic it is possible to close this post (i am not sure how to do that)

    Yes, you are right. I will close the ticket, no worries.
    Please do not hesitate to open a new ticket if you should encounter any other issues or questions in the future.

    Good luck with you development!

    Best regards,
    Karl

  • thanks

    i will check , i have been looking through the saadc driver and HAL API, i didn't find the way to configur some of the pins to HIGH or LOW values to use the event type:

    NRF_SAADC_EVENT_CH1_LIMITH 

    NRF_SAADC_EVENT_CH1_LIMITL

    if i am to use one saadc periferial with 3 channels (for 3 input pins), i wish to use 2 of them as high/low interrupts for the analog input and one that reads the values.. can you help with giving me direction or a close example?

    also, if i use the 'app_timer' , does it changes the way i work with the ppi in the "least CPU intensive wat" asspect ?

    best regards

    Ziv

  • also i wonder what if i have 3 instances of timer that activates the saadc sample and at one point both timer call the saadc sample (read values ->oversample = time consuming) task, wouldn't that cause a problem ?

  • Hello,

    You will need to make sure that the sampling criterias in the SAADC documentation is satisfied, to ensure proper function of the SAADC. Mainly, this would be the continuous mode criteria:

     fSAMPLE < 1/[tACQ + tconv]

    and the scan mode criteria: 

    Total time < Sum(CH[x].tACQ+tCONV), x=0..enabled channels

    As for the event that multiple triggers for the SAMPLE task happens at the same time, or in close succession I do not know what the output will be, since this is undefined behavior. My guess is that one of the triggers is ignored, which will cause you to loose a sample if you are going to only extract 1 of the samples each trigger.

    ziv123 said:
    also, if i use the 'app_timer' , does it changes the way i work with the ppi in the "least CPU intensive wat" asspect ?

    I am not sure I understand what you are asking? The app timer module sets up the timer peripheral, which does not require CPU interaction after it is started. However, if it is operating in single_shot_mode, then you will need to have the CPU restart the timer every so often, for example.

    ziv123 said:
    if i am to use one saadc periferial with 3 channels (for 3 input pins), i wish to use 2 of them as high/low interrupts for the analog input and one that reads the values.. can you help with giving me direction or a close example?

    Please see the "Limits event monitoring" section of the SAADC documentation.
    As it is described there, you must set each channels limits, which will then trigger the events you mention when they are exceeded. You could use the set_limits function for this. 
    Be advised that when having limits enabled and using scan mode, the limit event will trigger every time the channel is sampled and the limits are exceeded.

    Best regards,
    Karl

Related