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

How to set or configure gain register in SAADC example? So that i can set various gain.

I am trying to configure or set gain in  SAADC example, for various gains it should operate but i am not getting how to set gain register so that i get SAADC output depending on various gain and even i tried to change gain values in nrfx.saadc.h file but getting error. Gain defined in nrfx.saadc.h file are default one but i want it to work as per user defined gain.

But i want to set to  below mentioned Gain values 

1, 2, 4, 5, 8, 10, 16, 32.

When i am changing gain values in below mentioned lines i am getting error. 

Default Gain  in nrf.saadc.h file are 

NRF_SAADC_GAIN1_6 = SAADC_CH_CONFIG_GAIN_Gain1_6, ///< Gain factor 1/6.
NRF_SAADC_GAIN1_5 = SAADC_CH_CONFIG_GAIN_Gain1_5, ///< Gain factor 1/5.
NRF_SAADC_GAIN1_4 = SAADC_CH_CONFIG_GAIN_Gain1_4, ///< Gain factor 1/4.
NRF_SAADC_GAIN1_3 = SAADC_CH_CONFIG_GAIN_Gain1_3, ///< Gain factor 1/3.
NRF_SAADC_GAIN1_2 = SAADC_CH_CONFIG_GAIN_Gain1_2, ///< Gain factor 1/2.
NRF_SAADC_GAIN1 = SAADC_CH_CONFIG_GAIN_Gain1, ///< Gain factor 1.
NRF_SAADC_GAIN2 = SAADC_CH_CONFIG_GAIN_Gain2, ///< Gain factor 2.
NRF_SAADC_GAIN4 = SAADC_CH_CONFIG_GAIN_Gain4, ///< Gain factor 4.

Gain defined in nrfx.saadc.h file is

.gain       = NRF_SAADC_GAIN1_4,         

So how can i define gains and make it work properly. Im using only 1channel AIN0 with SDK15.3 nrf52832.

Presently its working properly with default gain values.

.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is the output what i am getting for default gain. 

Please suggest.