why the range of the output is from 0 - 4088 for analogSetWidth(9)?

CZSCZHX
Posts: 2
Joined: Wed Jun 22, 2022 4:46 am

why the range of the output is from 0 - 4088 for analogSetWidth(9)?

Postby CZSCZHX » Wed Jun 22, 2022 5:13 am

in the official docs, it shows:
analogSetWidth¶
This function is used to set the hardware sample bits and read resolution. Default is 12bit (0 - 4095). Range is 9 - 12.
anyhow, it seems to me that the range of the output doesn't change, no matter what the parameter is, 9,10,11,12. why?
anything wrong to my code?
  1. #include <Arduino.h>
  2.  
  3. void setup() {
  4.   Serial.begin(9600);
  5.   pinMode(A3, INPUT);
  6.   analogSetWidth(9);
  7. }
  8.  
  9. void loop() {
  10.   Serial.println(analogRead(A3));
  11. }

[Codebox]
4088
4088
4088
4088
4088
4088
4088
4088
4088
4088
4088
4088
4088
2696
2688
2688
2680
2688
2688
2680
2672
2680
2672
2672
2672
2672
2672
2672
2664
2664
2664
2656
2656
728
728
720
728
728
728
728
720
720
720
720
712
712
712
712
704
704
704
704
696
696
696
696
696
688
[/Codebox]

lbernstone
Posts: 666
Joined: Mon Jul 22, 2019 3:20 pm

Re: why the range of the output is from 0 - 4088 for analogSetWidth(9)?

Postby lbernstone » Wed Jun 22, 2022 7:37 am

I think setWidth is being deprecated. In v2.0.3, there is analogReadResolution(uint8_t bits). Can you try that and see if it works?

CZSCZHX
Posts: 2
Joined: Wed Jun 22, 2022 4:46 am

Re: why the range of the output is from 0 - 4088 for analogSetWidth(9)?

Postby CZSCZHX » Wed Jun 22, 2022 7:56 am

many thanks!

I tried, just like what you said. it seems that you are right.

in fact, this CMD just misfunctions, which means that the range is incorrect, but it does change the sampling pattern. for example, one bit of every 8 bits is sampled, for the parameter (9). And, the sample will change correspondingly when the parameter is changed from 9 to another one, e.g. 10,11, or 12.

when the parameter is 12, you will see all the bits, the output will be 0,1,2,3,4,5,...,4093,4094,4095.

May I know from when it was deprecated?

Who is online

Users browsing this forum: No registered users and 59 guests