From 0821767672ec903a62edfe3b3db1587518631b32 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Mon, 6 Nov 2023 14:15:46 +0530 Subject: [PATCH] tests/psoc6/dut: Adding func tests for adc and pwm. Signed-off-by: NikhitaR-IFX --- tests/psoc6/dut/adc.py | 33 ++++++++------- tests/psoc6/dut/adc.py.exp | 10 ++--- tests/psoc6/dut/pwm.py | 83 ++++++++++++++------------------------ tests/psoc6/dut/pwm.py.exp | 27 +------------ 4 files changed, 51 insertions(+), 102 deletions(-) diff --git a/tests/psoc6/dut/adc.py b/tests/psoc6/dut/adc.py index ee16b6d55d90..6e70e267a09f 100644 --- a/tests/psoc6/dut/adc.py +++ b/tests/psoc6/dut/adc.py @@ -1,4 +1,9 @@ -### ADC +### 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. +""" import os import time from machine import PWM, ADC @@ -6,22 +11,16 @@ # Allocate pin based on board machine = os.uname().machine if "CY8CPROTO-062-4343W" in machine: - pin_name = "P12_0" - adc_pin = "P10_0" + adc_pin0 = "P10_0" + adc_pin1 = "P10_1" elif "CY8CPROTO-063-BLE" in machine: - pin_name = "P6_2" - adc_pin = "P10_0" + adc_pin0 = "P10_0" + adc_pin1 = "P10_1" -adc = ADC(adc_pin, sample_ns=1000) -pwm = PWM(pin_name, freq=1000, duty_u16=65535, invert =0) +adc0 = ADC(adc_pin0, sample_ns=1000) +adc1 = ADC(adc_pin1, sample_ns=1000) -print("Initial Voltage (microvolts) is max: ",adc.read_uv()>1500) -print("Initial Voltage (raw data) is max: ",adc.read_u16()>50) -pwm.duty_u16(0) -time.sleep_ms(100) -print("Off signal Voltage (microvolts) is ~0 : ",adc.read_uv()<1500) -print("Off signal Voltage (raw data) is ~0 : ",adc.read_u16()<50) -pwm.duty_u16(65535) -time.sleep_ms(100) -print("On signal Voltage (microvolts) is max: ",adc.read_uv()>1500) -print("On signal Voltage (raw data) is max: ",adc.read_u16()>50) +print("Volatge (in microvolts) on pin", adc_pin0, "is max: ", adc0.read_uv() > 1000000) +print("Volatge (raw count) on pin", adc_pin0, "is max: ", adc0.read_u16() > 500) +print("Volatge (in microvolts) on pin", adc_pin1, "is max: ", adc1.read_uv() < 1000000) +print("Volatge (raw count) on pin", adc_pin1, "is max: ", adc1.read_u16() < 500) diff --git a/tests/psoc6/dut/adc.py.exp b/tests/psoc6/dut/adc.py.exp index 9766a10ff761..476dbee62dd2 100644 --- a/tests/psoc6/dut/adc.py.exp +++ b/tests/psoc6/dut/adc.py.exp @@ -1,6 +1,4 @@ -Initial Voltage (microvolts) is max: True -Initial Voltage (raw data) is max: True -Off signal Voltage (microvolts) is ~0 : True -Off signal Voltage (raw data) is ~0 : True -On signal Voltage (microvolts) is max: True -On signal Voltage (raw data) is max: True +Volatge (in microvolts) on pin P10_0 is max: True +Volatge (raw count) on pin P10_0 is max: True +Volatge (in microvolts) on pin P10_1 is max: True +Volatge (raw count) on pin P10_1 is max: True diff --git a/tests/psoc6/dut/pwm.py b/tests/psoc6/dut/pwm.py index 1d6bd854cc37..23ec0830b123 100644 --- a/tests/psoc6/dut/pwm.py +++ b/tests/psoc6/dut/pwm.py @@ -1,68 +1,45 @@ -### PWM +### PWM - WIP +""" Setup description: + Connect pwm_pin to gpio_pin. PWM signal is generated at 50% duty cycle currently. Every time the level changes, the gpio_pin + is triggered and elapsed tick is calculated. Based on values ton and toff, experimental duty cycle is calculated. + + *Known issue: This test will not work for any duty cycle except for 65535 or 0 values since there are fixes required in module. +""" import os import time -from machine import PWM +from machine import PWM, Pin +import time # Allocate pin based on board machine = os.uname().machine if "CY8CPROTO-062-4343W" in machine: - pin_name = "P12_0" -elif "CY8CPROTO-063-BLE" in machine: - pin_name = "P6_2" + pwm_pin = "P12_0" + gpio_pin = "P13_6" -def generate_new_signal(pwm_obj, freq, duty_cycle_u16): - pwm_obj.freq(freq) - pwm_obj.duty_u16(duty_cycle_u16) - -pwm = PWM(pin_name, freq=50, duty_u16=32768, invert =0) - -print("Initial freq: ", pwm.freq()) -print("Initial duty cycle: ", pwm.duty_u16()) +elif "CY8CPROTO-063-BLE" in machine: + pwm_pin = "P6_2" + gpio_pin = "P5_2" -# Generate signal with freq = 1Hz and Duty cycle of 25% -generate_new_signal(pwm, 1, 16384) -print("Signal with freq = 1Hz and Duty cycle of 25%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +gpio_flag = 0 -# Generate signal with freq = 1Hz and Duty cycle of 50% -generate_new_signal(pwm, 1, 32768) -print("Signal with freq = 1Hz and Duty cycle of 50%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +input_pin = Pin(gpio_pin, Pin.IN) -# Generate signal with freq = 1Hz and Duty cycle of 75% -generate_new_signal(pwm, 1, 49151) -print("Signal with freq = 1Hz and Duty cycle of 75%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +t0 = time.ticks_cpu() -# Generate signal with freq = 1Hz and Duty cycle of 100% -generate_new_signal(pwm, 1, 65535) -print("Signal with freq = 1Hz and Duty cycle of 100%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +pwm = PWM(pwm_pin, freq=10, duty_u16=32768, invert=0) -# Generate signal with freq = 25Hz and Duty cycle of 25% -generate_new_signal(pwm, 25, 16384) -print("Signal with freq = 25Hz and Duty cycle of 250%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +while gpio_flag != 1: + if input_pin.value() == 1: + gpio_flag = 1 + t1 = time.ticks_cpu() + toff = t1 - t0 -# Generate signal with freq = 50Hz and Duty cycle of 50% -generate_new_signal(pwm, 50, 32768) -print("Signal with freq = 50Hz and Duty cycle of 50%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +while gpio_flag != 0: + if input_pin.value() == 0: + gpio_flag = 0 + t2 = time.ticks_cpu() + ton = t2 - t1 -# Generate signal with freq = 75Hz and Duty cycle of 75% -generate_new_signal(pwm, 75, 49151) -print("Signal with freq = 75Hz and Duty cycle of 75%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +duty_cycle = (ton / (ton + toff)) * 100 -# Generate signal with freq = 100Hz and Duty cycle of 100% -generate_new_signal(pwm, 100, 65535) -print("Signal with freq = 100Hz and Duty cycle of 100%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) \ No newline at end of file +print("Experimental duty cycle(%) = ", duty_cycle) diff --git a/tests/psoc6/dut/pwm.py.exp b/tests/psoc6/dut/pwm.py.exp index 9743a701cec2..0ca95142bb71 100644 --- a/tests/psoc6/dut/pwm.py.exp +++ b/tests/psoc6/dut/pwm.py.exp @@ -1,26 +1 @@ -Initial freq: 50 -Initial duty cycle: 32768.0 -Signal with freq = 1Hz and Duty cycle of 25% -Current freq: 1 -Current duty cycle: 16384.0 -Signal with freq = 1Hz and Duty cycle of 50% -Current freq: 1 -Current duty cycle: 32768.0 -Signal with freq = 1Hz and Duty cycle of 75% -Current freq: 1 -Current duty cycle: 49151.0 -Signal with freq = 1Hz and Duty cycle of 100% -Current freq: 1 -Current duty cycle: 65535.0 -Signal with freq = 25Hz and Duty cycle of 250% -Current freq: 25 -Current duty cycle: 16384.0 -Signal with freq = 50Hz and Duty cycle of 50% -Current freq: 50 -Current duty cycle: 32768.0 -Signal with freq = 75Hz and Duty cycle of 75% -Current freq: 75 -Current duty cycle: 49151.0 -Signal with freq = 100Hz and Duty cycle of 100% -Current freq: 100 -Current duty cycle: 65535.0 +True