[ULP] How to read with adc ULP assembler instruction
Posted: Mon May 15, 2017 7:30 pm
Hi!
I’m working on a ULP program that reads from ADC and wakes up the main cores if the result is greater than a threshold.
The analog signal modulated with a potentiometer is connected to the pin (ADC2:3, GPIO15), but I’m not sure how I should use the ADC assembler instruction. Besides, the documentation is quite confusing.
I ‘m using the following code:
The output is something like this:
It doesn’t make sense at all. I tried different operand values on the ADC assembler instruction, but all of them returned different constant numbers, or a low range of numbers without any type of connection with my input.
I’m working on a ULP program that reads from ADC and wakes up the main cores if the result is greater than a threshold.
The analog signal modulated with a potentiometer is connected to the pin (ADC2:3, GPIO15), but I’m not sure how I should use the ADC assembler instruction. Besides, the documentation is quite confusing.
I ‘m using the following code:
Code: Select all
.bss
.global adc_value
adc_value:
.long 0
.global adc_threshold
adc_threshold:
.long 0
.text
// ULP code starts here
.global entry
entry:
move r3, adc_threshold // R3 <- @adc_threshold
ld r3, r3, 0 // R3 <- adc_threshold
move r2, adc_value // R2 <- @adc_value
/* Measure value using ADC1 pad 2 for 100 cycles and move result to R0 */
adc r1, 1, 2, 1 // R0 <- ADC1
st r1, r2, 0 // @adc_value <- R0 (ADC READ VALUE)
sub r1, r3, r1 // R0 <- R3 - R0 (Threshold - ADC)
jump wake_up, ov // Jump if last ALU has set overflow flag (ADC > Threshold)
halt
.global wake_up
wake_up:
/* Wake up the SoC, end program */
wake
halt
Code: Select all
ULP wakeup
ADC read value: 4095, overpass the threshold: 100.
Entering deep sleep
ULP wakeup
ADC read value: 4095, overpass the threshold: 100.
Entering deep sleep
ULP wakeup
ADC read value: 4095, overpass the threshold: 100.
Entering deep sleep