STM32F407 Disc : Using Timer in Compare / Capture mode ?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

STM32F407 Disc : Using Timer in Compare / Capture mode ?

Post by nikhiledutech » Tue May 08, 2018 10:29 am

Hey,

I was wondering is there any test example describing how to use Timer in Compare, capture mode. i have tried myself, but I don't understand whats happening ?

Reffered this doc : http://docs.micropython.org/en/v1.9.3/p ... Timer.html

I have created a timer object with freq 1. It will toggle on board LED 4 once every sec using callback. Than created a channel on timer(13), and set its mode to Timer.OC_ACTIVE.

And passed the value to be compared in timer.compare(value). So shouldn't it generate an interrupt on comparison ?


Or is my code wrong ? Or anyone have idea about using Timer in different mode please comment.

Code: Select all


#Include Timer and LED modules
from pyb import Timer, LED, Pin

#PA0 is pin associated with PA1 
x = Pin('PA0')

#Creating a tTimer object on Timer 2 
tim = Timer(13)
tim.init(freq = 1)
tim.callback(lambda t: LED(4).toggle())


#Channel 1 of Timer 13
a = tim.channel(1, tim.OC_ACTIVE)
tim.counter(0)
a.compare(5798)


print(tim.OC_ACTIVE)



User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: STM32F407 Disc : Using Timer in Compare / Capture mode ?

Post by dhylands » Wed May 09, 2018 7:38 pm

Here's an example showing IC mode being used to capture an RC servo pulse: https://github.com/dhylands/upy-example ... ic_test.py

Here's an examples showing OC mode being used: https://github.com/dhylands/upy-example ... oc_test.py

There is also some logic analyzer photos (along with a more detailed description) over here: http://wiki.micropython.org/platforms/b ... r-Examples

I also have an example where I used OC mode to generate a test signal for testing quadrature decoding: https://github.com/dhylands/upy-example ... er/quad.py In this example it used the compare register to allow the relative phase of the 2 signals to be controlled.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407 Disc : Using Timer in Compare / Capture mode ?

Post by nikhiledutech » Thu May 10, 2018 5:03 am

Okay Thanks Sir.

Post Reply