ME405: Mechatronics
Project Documentation and Portfolio by Neil Patel
lab2b.py File Reference

This file contains a program which uses built in timer features of the STM32 MCU to testa a user's reaction time. More...

Namespaces

 Lab0x02
 This package contains lab2a.py, lab2b.py.
 

Functions

def lab2b.cb1 (timer)
 First Callback Function. More...
 
def lab2b.cb2 (timer)
 Second Callback Function. More...
 

Variables

 lab2b.count = None
 The timer count used to keep track of the IC.
 
int lab2b.comp = 0
 The timer count used to keep track of the OC.
 
 lab2b.timmy = pyb.Timer(2, prescaler = 8000, period = 0xffff)
 Initialization of Timer2 as a free running counter.
 
 lab2b.pina5 = pyb.Pin (pyb.Pin.board.PA5, pyb.Pin.OUT_PP)
 Initialization of pin A5.
 
 lab2b.pinb3 = pyb.Pin (pyb.Pin.board.PB3, pyb.Pin.IN)
 Initialization of pin B3.
 
 lab2b.pinc13 = pyb.Pin (pyb.Pin.board.PC13, pyb.Pin.IN)
 Initialization of pin C13.
 
 lab2b.ch1
 Initialization of timer channel 1. More...
 
 lab2b.ch2 = timmy.channel(2, pyb.Timer.IC, pin = pinb3, polarity = pyb.Timer.FALLING)
 Initialization of timer channel 2.
 
list lab2b.tries = []
 Runs the program to test a user's reaction time. More...
 
tuple lab2b.rTime = (comp - count) % 65535
 Computes the reaction time.
 

Detailed Description

This file contains a program which uses built in timer features of the STM32 MCU to testa a user's reaction time.

Function Documentation

◆ cb1()

def lab2b.cb1 (   timer)

First Callback Function.

Triggered by an Output Compare (OC) compare match on PA5 using Channel 1 of Timer 2. PA5 goes high when interrupt occurs and toggles otherwise.

Parameters
timerTimer the timer being used.
Returns
Returns nothing.

◆ cb2()

def lab2b.cb2 (   timer)

Second Callback Function.

Triggered by an Input Capture (IC) on PB3 using Channel 2 of Timer 2. When IC interrupt is triggered, the timer value is automatically stored in the capture value.

Parameters
timerTimer the timer being used.
Returns
Returns nothing.

Variable Documentation

◆ ch1

lab2b.ch1
Initial value:
1 = timmy.channel(1, pyb.Timer.OC_TOGGLE, pin = pina5,
2  polarity = pyb.Timer.HIGH)

Initialization of timer channel 1.

◆ tries

list lab2b.tries = []

Runs the program to test a user's reaction time.

@ brief Keeps track of all the attempts.