Skip to main content
Visitor II
November 19, 2014
Question

Clock x ports doubts

  • November 19, 2014
  • 14 replies
  • 3144 views
Posted on November 19, 2014 at 12:13

Hello

i�m new in STM8s105 microcontroller and cosmic c compiler.

i wrote a small program:

i set the clock with internall clock with prescaler 8:

CLK_CKDIVR= 0b00011000;

it means that my uc will operate at 2 MHz, right?

i set the port D3 as output pin, push pull fast:

PD_DDR=0B00001000;

PD_CR1=0B00001000;

PD_CR2=0B00001000;

PD_ODR=0B00000000;

in the main, i wrote this code:

main()

{

PD_ODR=0B00000000;

PD_ODR=0B00001000;

PD_ODR=0B00000000;

PD_ODR=0B00001000;

PD_ODR=0B00000000;

PD_ODR=0B00001000;

PD_ODR=0B00000000;

PD_ODR=0B00001000;

for (;;) {}

}

in my mind, if i set the port, it will in high level for 500ns, turn off for 500ms and so on... but in the scope i see times of 1us.

what i do wrong?

thanks a o lot!

#stm8s105-ports-clock
    This topic has been closed for replies.

    14 replies

    Visitor II
    January 13, 2015
    Posted on January 13, 2015 at 18:27

    ok, but this kind of alignment should not be done by the compiler??

    Visitor II
    January 18, 2015
    Posted on January 18, 2015 at 18:08

    It's compiler specific, some compilers can have an option to enable loop alignment.

    But generally, using CPU to generate pulses with single cycle accuracy is tricky.

    You can try timers to avoid such problems with CPU.

    Visitor II
    March 9, 2015
    Posted on March 09, 2015 at 21:02

    Hi, ok, but i think this very strange... in the PIC of microchip this problem doesn't exist..

    Visitor II
    March 10, 2015
    Posted on March 10, 2015 at 09:15

    Hi Marcelo,

    A PIC in general is quite a simple device, i.e it has no pipeline and most instructions take one CPU cycle, where as the STM8 has a pipeline and instructions can take up to 3 bytes.

    For cycle accurate results a timer is the way to go as suggested by another poster.

    Thanks,

    Ian