Guten Abend,
ich versuche gerade einen PWM Channel vom STM8S so zu konfigurieren,
dass eine mit dem Pin PD3 (Timer2 Channel 2) verbundene LED aufleuchtet.
Das hier ist meine aktueller Stand:
1 | #include "iostm8s003f3.h"
|
2 | #include "stdint.h"
|
3 |
|
4 | #define PIN 3
|
5 |
|
6 | void initGPIO(){
|
7 | PD_DDR |= (1<<PIN); //Set Pin as Output
|
8 | PD_CR1 |= (1<<PIN); //Set Pin as PushPull
|
9 | PD_ODR |= (1<PIN); //Set to High
|
10 | }
|
11 |
|
12 | void initTimer2(){
|
13 | TIM2_PSCR_PSC = 0x01; //Set Prescaler
|
14 |
|
15 | TIM2_ARRL = 0x87; //Set Auto reload to 4999 [125KHz / (4999+1) = 25Hz]
|
16 | TIM2_ARRH = 0x13;
|
17 |
|
18 | TIM2_CCMR2_OC2M = 0x07; //PWM Mode 2
|
19 | TIM2_CCMR2_CC2S = 0x00; //CC2 channel is configured as output
|
20 | TIM2_CCER1_CC2P = 1; //OC2 active low
|
21 |
|
22 | TIM2_CCR1L = 0xC4; //Set Compare Register to 2500 [Duty Cycle = 50%]
|
23 | TIM2_CCR1H = 0x09;
|
24 |
|
25 | TIM2_CR1_CEN = 1; //Enable Timer
|
26 | }
|
27 |
|
28 | void main()
|
29 | {
|
30 | initGPIO();
|
31 | initTimer2();
|
32 | CLK_CKDIVR = 0x07; //Prescaler 128 (=125KHz)
|
33 | while(1){
|
34 | }
|
35 | }
|
Ich hab versucht, mich an dieses Dokument zu halten:
http://www.st.com/content/ccc/resource/technical/document/application_note/db/ec/7e/c8/57/b2/44/ee/CD00296680.pdf/files/CD00296680.pdf/jcr:content/translations/en.CD00296680.pdf
Allerdings ist da kein Beispielcode gegeben.
Die LED leuchtet nicht, was hab ich übersehen?