ULP ADC read help
Posted: Wed Nov 18, 2020 6:28 pm
Hello
I have a running app reading the ADC channel while sleeping and the channel is set fixed in the code
This code works, but now I need to pass the channel dynamically
I comment the .set and created a variable called ulp_adc_channel and set it on the c code but this does not work.
What would be the correct way to set the channel dynamically?
I tried the following code too but did not worked
This is the full code
Thanks
I have a running app reading the ADC channel while sleeping and the channel is set fixed in the code
Code: Select all
.set adc_channel, 5
adc r1, 0, adc_channel + 1
Code: Select all
;.set adc_channel, 5
.global adc_channel
adc_channel:
.long 0
adc r1, 0, adc_channel + 1
What would be the correct way to set the channel dynamically?
I tried the following code too but did not worked
Code: Select all
.global adc_channel
adc_channel:
.long 0
move r2, adc_channel
adc r1, 0, r2
This is the full code
Code: Select all
#include "soc/rtc_cntl_reg.h"
#include "soc/soc_ulp.h"
/* ADC1 channel 6, GPIO34 */
; .set adc_channel, 4
/* Configure the number of ADC samples to average on each measurement.
For convenience, make it a power of 2. */
.set adc_oversampling_factor_log, 2
.set adc_oversampling_factor, (1 << adc_oversampling_factor_log)
/* Define variables, which go into .bss section (zero-initialized data) */
.bss
.global adc_channel
adc_channel:
.long 0
.global last_result
last_result:
.long 0
/* Code goes into .text section */
.text
.global entry
entry:
/* do measurements using ADC */
/* r0 will be used as accumulator */
move r0, 0
/* initialize the loop counter */
stage_rst
measure:
/* measure and add value to accumulator */
; adc r1, 0, adc_channel + 1
move r2, adc_channel
adc r1, 0, r2
add r0, r0, r1
/* increment loop counter and check exit condition */
stage_inc 1
jumps measure, adc_oversampling_factor, lt
/* divide accumulator by adc_oversampling_factor.
Since it is chosen as a power of two, use right shift */
rsh r0, r0, adc_oversampling_factor_log
/* averaged value is now in r0; store it into last_result */
move r3, last_result
st r0, r3, 0
halt
Thanks