2010-03-14 03:01 PM
PWM capture with TIM1?
2011-05-17 06:07 AM
hi,
thanks for the fast response! I have now copied the very procedure described in the STM8 reference manual - still without success. Guess I have to contact technical support..
Regards, Georg
2011-05-17 06:07 AM
Hi,
I remember that I used this config and it worked fine. Perhaps you missed this step ''Select the valid trigger input: write the TS bits to ‘101’ in the TIM1_SMCR register (TI1FP1 selected).'' It is indicated in the reference manual ! regards, mcu fan2011-05-17 06:07 AM
Hi georg,
you can send me your code perhaps I can help you.Mit besten Grüßen,
low power fan2011-05-17 06:07 AM
hi,
thanks a lot in advance! Of course I can provide you with a demo project for the Discovery Board (see attachments to this post). For your help and effort thanks a lot in advance! Regards, Georg2011-05-17 06:07 AM
Hi georg,
After a first look. I suggest to change while (!TIM1_SR1_UIF); by while (!TIM1_SR1_CC1IF); because it is at capture event the counter value will be loaded in capture register. Hope this helps. Tell if it is OK Mit besten grüssen, MCU Lüfter2011-05-17 06:07 AM
hi Lüfter,
funny discussing in english when both our native language most likely is german...? Anyway, I've tried your proposal but I still get a funny result (see attachment). The columns are (from left to right): input frequency and duty cycle (both asserted using an oscilloscope), TIM1_CC1 and TIM1_CC2 capture values, and the calculated frequency (24MHz/2/CC11) and duty cycle (CC2/CC1).
To me this seems like CC1 & CC2 do capture the edges, but for some reason the timer doesn't start correctly...? This is also supported by the observation that the 1st measurement is only slightly off (starts immediately after start of PWM generation), whereas all the other measurements are more off (+ some ms delay). Any idea??? And again, thanks in advance for any help!
Regards, Georg
2011-05-17 06:07 AM
Hi georg,
You put 1KHz and you find in CCR1 12000. Das kommt nicht ! If your timer is clocked by 16 MHz so you should have 16000 in CCR1 register +/- error. What is your clock divider, timer clock 16 MHz, 8MHz or ...? I suuggest to make an update event after each config of timer so the new one (prescaler, ARR...) are taken into account immediately (you can conclude from the reference manual that the timer needs update event to take into consideration the new config) the update is done as following: TIM1->EGR |= 0x01; Mit besten grüssen, MCU Lüfter2011-05-17 06:07 AM
Hallo Lüfter,
der Einfachheit halber antworte ich mal in Deutsch (alternativ könntest Du mir mal Deine e-Mail an ''georg - at - cream-tea.de'' schicken, dann machen wir per PM weiter). Aber hier zunächst der Versuch bzw. mein Problem:
Speziell die letzten 4 Punkte liessen sich einfach erklären, wenn TIM1 noch vor der ersten steigenden Flanke losläuft, obwohl ich dachte, ich habe ihn so konfiguriert, dass er genau das macht (TIM1_SMCR). Aber offenbar mache ich da was falsch, aber ich komme einfach nicht dahinter... :( Anbei noch ein vereinfachtes Projekt. Die interessante Routine ist in ''hw_layer.c'' Z.124ff.
Für jedwede Hilfe bin ich dankbar und für Deine Mühe vielen Dank im voraus! Gruss, Georg PS: Anbei ein Screenshot der PWM sowie das Projekt2011-05-17 06:07 AM
Hi georg,
Entshuldigung, aber ich verstehe ein bischen Deutschdeshalb schlage ich vor, um Ihre Nachricht auf Englisch übersetzen
. Danke shön, MCU Lüfter