Page 1 of 1

STM32F407 Disc : Using Timer in Compare / Capture mode ?

Posted: Tue May 08, 2018 10:29 am
by nikhiledutech
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)



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

Posted: Wed May 09, 2018 7:38 pm
by dhylands
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.

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

Posted: Thu May 10, 2018 5:03 am
by nikhiledutech
Okay Thanks Sir.