Skip to content

Commit

Permalink
tests/psoc6/dut: Adding func tests for adc and pwm.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Nov 6, 2023
1 parent 33bb9da commit 0821767
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 102 deletions.
33 changes: 16 additions & 17 deletions tests/psoc6/dut/adc.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
### 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

# 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)
10 changes: 4 additions & 6 deletions tests/psoc6/dut/adc.py.exp
Original file line number Diff line number Diff line change
@@ -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
83 changes: 30 additions & 53 deletions tests/psoc6/dut/pwm.py
Original file line number Diff line number Diff line change
@@ -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())
print("Experimental duty cycle(%) = ", duty_cycle)
27 changes: 1 addition & 26 deletions tests/psoc6/dut/pwm.py.exp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0821767

Please sign in to comment.