STM8S Timer1

OP #3342499
Lesenswert?

Hi,

bekomme nun seit Stunden den Timer1 vom STM8S nicht zum laufen wie ich 
es mir vorstelle.

Ich möchte am PC3 !TIM1_CH1 mittels dem Timer1 Channel1 ein Takt 
generieren.
ca 1Mhz. Der STM läuft noch auf dem internen 16Mhz.

Ich mache folgendes:
1
void TIM1_Configuration()
2
{
3
  TIM1_DeInit();
4
  TIM1_InternalClockConfig();
5
  TIM1_TimeBaseInit(100, 
6
                    TIM1_COUNTERMODE_DOWN,
7
                    100,
8
                    0);
9
  //TIM1_SetAutoreload(450);
10
  TIM1_OC1Init(TIM1_OCMODE_TOGGLE,
11
               TIM1_OUTPUTSTATE_DISABLE,
12
               TIM1_OUTPUTNSTATE_ENABLE,
13
               50,
14
               TIM1_OCPOLARITY_LOW,
15
               TIM1_OCPOLARITY_LOW,
16
               TIM1_OCIDLESTATE_RESET,
17
               TIM1_OCNIDLESTATE_RESET);
18
  TIM1_OC1PreloadConfig(ENABLE);
19
  TIM1_Cmd(ENABLE);
20
}

Was mache ich falsch, und was fehlt?
Habe die Zeit noch nicht berechnet, also die 1Mhz sind noch nicht das 
Thema, erstmal möchte ich einen Takt am Ausgang messen...

Danke im Voraus.
#3343246
Lesenswert?

Ne, gibt es nicht.
Ich habe mir mit TIM4 sowas aehnliches zusammengebastelt.
1
//=================================
2
// Init       100usec
3
//=================================
4
void Tim4_Init (void )
5
{
6
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);
7

8
  /* TIM4 configuration:
9
   - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 64 so the TIM4 counts with 250kHz
10
  - With 250 000 Hz we can generate time base:
11
      max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 250000 = 1024 us
12
      min time base is 0.016 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 =    8 us
13
  - In this example we need to generate a time base equal to 100 us
14
   so TIM4_PERIOD = (0.0001 * 250000 - 1) = 24 */
15

16
  TIM4_TimeBaseInit(TIM4_Prescaler_64, 24);
17
  TIM4_ClearFlag(TIM4_FLAG_Update);
18
  TIM4_ITConfig(TIM4_IT_Update, ENABLE);
19

20
  /* Enable TIM4 */
21
  TIM4_Cmd(ENABLE);
22
}

Und dann in der stm8l15x_it.c Datei:
1
(...)
2
//=====================================
3
// TIM4   Update/Overflow/Trigger Interrupt routine.
4
//=====================================
5
INTERRUPT_HANDLER(TIM4_UPD_OVF_TRG_IRQHandler, 25)
6
{
7
  static volatile uint8_t usec_100;
8

9
  usec_100++;
10
  tim4_status.f100us_task_request = true;
11

12
  if (usec_100 == 10)
13
  {
14
    usec_100 = 0;
15
    tim4_status.f1ms_task_request = true;
16
  }
17
  TIM4_ClearITPendingBit(TIM4_IT_Update);
18
}
19
(...)

In der Main-Loop wird dann tim4_status.f100us_task_request und 
tim4_status.f1ms_task_request kontrolliert. Unter anderem werden dann 
verschiede Delay-Funktionen bedient.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren