cancel
Showing results for 
Search instead for 
Did you mean: 

Clock x ports doubts

fagundesbr
Associate II
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
14 REPLIES 14
zzdz2
Associate II
Posted on November 27, 2014 at 19:06

I think the most feasible way to do the alignment is to put two NOP asm instructions before the gpio output block. It may work.

I guess I was just lucky when I did the test and I got aligned instructions by chance.

fagundesbr
Associate II
Posted on January 13, 2015 at 18:27

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

zzdz2
Associate II
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.

fagundesbr
Associate II
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..

Ian Legg
Senior
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