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