2014-11-19 03:13 AM
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-clock2014-11-27 10:06 AM
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.2015-01-13 09:27 AM
2015-01-18 09:08 AM
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.2015-03-09 01:02 PM
Hi, ok, but i think this very strange... in the PIC of microchip this problem doesn't exist..
2015-03-10 01:15 AM
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