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.
ports/psoc6: Fix ADC and enable hw test.
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
- Loading branch information
1 parent
65978eb
commit 75c31de
Showing
6 changed files
with
142 additions
and
39 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
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
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
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
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 |
---|---|---|
@@ -1,32 +1,110 @@ | ||
### ADC Functional test | ||
""" Setup description: | ||
Connect 3.3V input to adc_pin0 and 0V input to adc_pin1. With the setup done, run the test. | ||
*Known issue: The max output voltage currently is ~2.3V for 3.3V input. | ||
Construct a basic voltage divider with 120 ohms each resistor. Supply the ends with 3.3V and GND. | ||
Available voltage values are then - 3.3V, ~1.7V, 0V. | ||
Pin connections: | ||
Voltage Divider circuit On Target Board | ||
3.3V end adc_pin_max | ||
Mid point adc_pin_mid | ||
GND end adc_pin_gnd | ||
*Known issue: When connected to GND, you may not get exact 0V and this may vary board to board. | ||
""" | ||
import os | ||
import time | ||
from machine import PWM, ADC | ||
from machine import ADC, ADCBlock | ||
|
||
# Allocate pin based on board | ||
machine = os.uname().machine | ||
if "CY8CPROTO-062-4343W" in machine: | ||
adc_pin0 = "P10_0" | ||
adc_pin1 = "P10_1" | ||
# TODO: Refactor test for more functionality coverage | ||
print("SKIP") | ||
raise SystemExit | ||
adc_pin_gnd = "P10_1" | ||
adc_pin_mid = "P10_3" | ||
adc_pin_max = "P10_0" | ||
adc_wrong_pin_name = "P13_7" | ||
elif "CY8CPROTO-063-BLE" in machine: | ||
adc_pin0 = "P10_0" | ||
adc_pin1 = "P10_1" | ||
# TODO: Refactor test for more functionality coverage | ||
print("SKIP") | ||
raise SystemExit | ||
|
||
adc0 = ADC(adc_pin0, sample_ns=1000) | ||
adc1 = ADC(adc_pin1, sample_ns=1000) | ||
|
||
print("Voltage (in microvolts) on pin", adc_pin0, "is max: ", adc0.read_uv() > 1000000) | ||
print("Voltage (raw count) on pin", adc_pin0, "is max: ", adc0.read_u16() > 500) | ||
print("Voltage (in microvolts) on pin", adc_pin1, "is max: ", adc1.read_uv() < 1000000) | ||
print("Voltage (raw count) on pin", adc_pin1, "is max: ", adc1.read_u16() < 500) | ||
adc_pin_gnd = "P10_1" | ||
adc_pin_mid = "P10_3" | ||
adc_pin_max = "P10_0" | ||
adc_wrong_pin_name = "P13_7" | ||
|
||
# 0.35V | ||
tolerance_uv = 350000 | ||
|
||
tolerance_raw = 4000 | ||
|
||
block = None | ||
|
||
|
||
def validate_adc_uv_value(adc_pin, exp_volt, act_volt): | ||
print( | ||
"\nExpected voltage - ", | ||
exp_volt, | ||
"(uV) on pin ", | ||
adc_pin, | ||
"is approx same as obtained voltage(uV): ", | ||
(exp_volt - tolerance_uv) < act_volt < (exp_volt + tolerance_uv), | ||
) | ||
|
||
|
||
def validate_adc_raw_value(adc_pin, exp_volt, act_volt): | ||
print( | ||
"\nExpected voltage - ", | ||
exp_volt, | ||
"(raw) on pin ", | ||
adc_pin, | ||
"is approx same as obtained voltage(raw): ", | ||
(exp_volt - tolerance_raw) < act_volt < (exp_volt + tolerance_raw), | ||
) | ||
|
||
|
||
# Exception should be raised | ||
try: | ||
adc = ADC(adc_wrong_pin_name) | ||
except: | ||
print("Invalid ADC Pin\n") | ||
|
||
adc0 = ADC(adc_pin_gnd, sample_ns=1000) | ||
print(adc0) | ||
|
||
block = ADCBlock(0, bits=12) | ||
# ADCBlock.connect(channel) | ||
adc1 = block.connect(3) | ||
print("\nADCBlock.connect(channel): ", adc1) | ||
block.deinit() | ||
print("ADCBlock.deinit(): ", block) | ||
|
||
# ADCBlock.connect(source) | ||
block = ADCBlock(0, bits=12) | ||
adc1 = block.connect(adc_pin_mid) | ||
print("ADCBlock.connect(source): ", adc1) | ||
block.deinit() | ||
print("ADCBlock.deinit(): ", block) | ||
|
||
# ADCBlock.connect(channel,source) | ||
block = ADCBlock(0, bits=12) | ||
adc1 = block.connect(3, adc_pin_mid) | ||
print("ADCBlock.connect(channel,source)", adc1) | ||
|
||
adc2 = ADC(adc_pin_max, sample_ns=1000) | ||
print("\n", adc2) | ||
|
||
adc0_value_uv = adc0.read_uv() | ||
validate_adc_uv_value(adc_pin_gnd, 0, adc0_value_uv) | ||
adc0_value_raw = adc0.read_u16() | ||
validate_adc_raw_value(adc_pin_gnd, 0, adc0_value_raw) | ||
|
||
adc1_value_uv = adc1.read_uv() | ||
validate_adc_uv_value(adc_pin_mid, 1650000, adc1_value_uv) | ||
adc1_value_raw = adc1.read_u16() | ||
validate_adc_raw_value(adc_pin_mid, 16385, adc1_value_raw) | ||
|
||
adc2_value_uv = adc2.read_uv() | ||
validate_adc_uv_value(adc_pin_max, 3300000, adc2_value_uv) | ||
adc2_value_raw = adc2.read_u16() | ||
validate_adc_raw_value(adc_pin_max, 32767, adc2_value_raw) | ||
|
||
adc0.deinit() | ||
print("\n", adc0) | ||
adc1.deinit() | ||
print(adc1) | ||
adc2.deinit() | ||
print(adc2) |
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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
Voltage (in microvolts) on pin P10_0 is max: True | ||
Voltage (raw count) on pin P10_0 is max: True | ||
Voltage (in microvolts) on pin P10_1 is max: True | ||
Voltage (raw count) on pin P10_1 is max: True | ||
Invalid ADC Pin | ||
|
||
<ADC Pin=81, ADCBlock_id=0, sampling_time_ns=1000> | ||
|
||
ADCBlock.connect(channel): <ADC Pin=83, ADCBlock_id=0, sampling_time_ns=1000> | ||
ADCBlock.deinit(): ADCBlock(0, bits=12) | ||
ADCBlock.connect(source): <ADC Pin=83, ADCBlock_id=0, sampling_time_ns=1000> | ||
ADCBlock.deinit(): ADCBlock(0, bits=12) | ||
ADCBlock.connect(channel,source) <ADC Pin=83, ADCBlock_id=0, sampling_time_ns=1000> | ||
|
||
<ADC Pin=80, ADCBlock_id=0, sampling_time_ns=1000> | ||
|
||
Expected voltage - 0 (uV) on pin P10_1 is approx same as obtained voltage(uV): True | ||
|
||
Expected voltage - 0 (raw) on pin P10_1 is approx same as obtained voltage(raw): True | ||
|
||
Expected voltage - 1650000 (uV) on pin P10_3 is approx same as obtained voltage(uV): True | ||
|
||
Expected voltage - 16385 (raw) on pin P10_3 is approx same as obtained voltage(raw): True | ||
|
||
Expected voltage - 3300000 (uV) on pin P10_0 is approx same as obtained voltage(uV): True | ||
|
||
Expected voltage - 32767 (raw) on pin P10_0 is approx same as obtained voltage(raw): True | ||
|
||
<ADC Pin=81, ADCBlock_id=0, sampling_time_ns=1000> | ||
<ADC Pin=83, ADCBlock_id=0, sampling_time_ns=1000> | ||
<ADC Pin=80, ADCBlock_id=0, sampling_time_ns=1000> |