2017-03-01 03:09 AM
Hello,
I am trying to make a 200us pulse,using simple time dealy. I am using TIMER4 to create delay. But the problem is whatever prescalar I use or What ever Autoreload value I have timer always gives 12us pulse. I am using stm8s003f3p6 controller.
Code is below:
#include 'STM8S003F3P.h'
void InitialiseSystemClock(void);
void InitialiseSystemClock(void)
{ CLK_ICKR = 0; // Reset the Internal Clock Register. CLK_ICKR = (1<<0);; // Enable the HSI. CLK_ECKR = 0; // Disable the external clock. while (!(CLK_ICKR & (1<<1))); // Wait for the HSI to be ready for use. CLK_CKDIVR = 0; // Ensure the clocks are running at full speed. CLK_PCKENR1 = 0xff; // Enable all peripheral clocks. CLK_PCKENR2 = 0xff; // Ditto. CLK_CCOR = 0; // Turn off CCO. CLK_HSITRIMR = 0; // Turn off any HSIU trimming. CLK_SWIMCCR = 0; // Set SWIM to run at clock / 2. CLK_SWR = 0xe1; // Use HSI as the clock source. CLK_SWCR = 0; // Reset the clock switch control register. CLK_SWCR = (1<<1); // Enable switching. while (CLK_SWCR & (1<<0)); // Pause while the clock switch is busy. }void main(void){InitialiseSystemClock();
PD_DDR |=(1<<1); PD_CR1 |=(1<<1); PD_CR2 |=(1<<1); TIM4_PSCR=16; TIM4_ARR=255; TIM4_IER=(1<<0); TIM4_CR1=(1<<0); _asm('rim'); while(1){}}
@far @interrupt void TIMER4_INTERRUPT (void){
PD_ODR^=(1<<1); TIM4_SR &=~(1<<0); return;}