forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/psoc6: Adding tests for ADC and ADCBlock.
Signed-off-by: NikhitaR-IFX <[email protected]>
- Loading branch information
1 parent
49d615c
commit d2ae382
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
ADC test for the PSoC6 port. | ||
""" | ||
|
||
from machine import ADC, Pin | ||
|
||
adc_pin = Pin("P10_0") | ||
adc_wrong_pin = Pin("P13_7") | ||
|
||
# Exceptions should be raised | ||
try: | ||
adc = ADC(adc_wrong_pin) | ||
except: | ||
print("Invalid ADC Pin") | ||
|
||
adc = ADC(adc_pin, sample_ns=1000) | ||
print(adc) | ||
|
||
print(adc.read_u16() > 0) | ||
print(adc.read_uv() > 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Invalid ADC Pin | ||
<ADC Pin=80, ADCBlock_id=0, sampling_time_ns=1000> | ||
True | ||
True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
ADCBlock test for the PSoC6 port. | ||
""" | ||
from machine import Pin, ADCBlock | ||
|
||
pin = Pin("P10_3") | ||
|
||
# Negative tests | ||
try: | ||
adcBlock = ADCBlock(1) | ||
except: | ||
print("TypeError: Specified ADC id not supported. Currently only block 0 is configured!") | ||
|
||
try: | ||
adcBlock = ADCBlock(0, bits=10) | ||
except: | ||
print("TypeError: Invalid bits. Current ADC configuration supports only 12 bits resolution!") | ||
|
||
adcBlock = ADCBlock(0) | ||
|
||
try: | ||
adcPin = adcBlock.connect(0, pin) | ||
except: | ||
print("TypeError: Wrong pin specified for the mentioned channel") | ||
|
||
|
||
adcPin = adcBlock.connect(3, pin) | ||
|
||
print(adcPin.read_uv() > 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TypeError: Specified ADC id not supported. Currently only block 0 is configured! | ||
TypeError: Invalid bits. Current ADC configuration supports only 12 bits resolution! | ||
TypeError: Wrong pin specified for the mentioned channel | ||
True |