Page 1 of 2

STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 2:33 am
by InvalidException
Hi all

I have BluePill and STM32F103C8T6 I need delays 1, 4, 10 and 100 (micro/us) and 1ms and 10ms (for LCD timing)
but I don't have it correct timings on current setup

Here is test project I'm working on: https://github.com/InvalidExcepti0n/BluePill-ChibiOS
And trying to adjust this for test on LED to turn off/on in specific time (1, 2, 4 and 100) us
Measuring with Logic Analazer (and Oscilloscope) getting wrong timings for us (for mili(ms) working fine)
And that part confuses me

@tfAteba
I have looked into CH_CFG_ST_FREQUENCY and if I change it chThdSleepMilliseconds not working anymore
so not sure if that will help me...

I don't know if my clocks settings is OK as ms wouldn't work if they are wrong (is this right)
Or this can be changed so ms archive with us instead?

Maybe there is another way and I'm not familiar as I'm new to ChibiOS :(

EDIT:
CH_CFG_ST_FREQUENCY 100000 //over this value not working right
chThdSleepMicroseconds(1); gives me closest I can get 10us
chThdSleepMilliseconds(1); gives me 1ms

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 7:18 am
by tfAteba
Hi,

I thinks, that your project is well configured. You just reach the limit of the system (scheduler latency), I wasn't also enable to have less than 10us while doing my test whit a NUCLEOF401RE.
But I hope that I'm wrong, if RM or Giovanni can confirm my idea it would be great.

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 9:26 am
by Giovanni
Hi,

The intervals resolution is defined by CH_CFG_ST_FREQUENCY, if your frequency is 10000 then your resolution is 100uS, smaller intervals are rounded up to multiples of 100uS.

Note that you cannot have reliable uS-class intervals using the RTOS, the system jitter is in the order of 10uS. You need an HW timer and fast interrupts for that.

Giovanni

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 9:52 am
by InvalidException
I know I will never have really 100% correct timings :( but can have very close to my need

And how would I archive this with Timers? Any directions?
Which one TImer should I user TIM1 or TIM2?
And how to use them?

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 10:55 am
by Hawhill
Depends on what you want to do with them.
So.... What do you want to do with those "delays"? What function do they solve?


Most probably you don't need the extended stuff TIM1 provides, so you can use one of the others. But this doesn't matter right now, as you need to learn about using timers anyway, nevermind which of them. Have a look at the GPT HAL abstraction and the corresponding examples. The GPT example for the STM32F4x is generic enough to mostly apply for your STM32F1x, too.

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 10:57 am
by InvalidException
True that...I need to learn how to use them with ChibiOS, have general knowledge only
Also I need them only for delay, nothing else...so should be simple (but I guess not so much)

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 11:56 am
by Hawhill
You can of course also use them for delay purposes. The GPT abstraction will give you a callback that is triggered as soon as the timer is done counting up to what you programmed it to count up to (among some other things a timer can do).

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 12:24 pm
by RoccoMarco
What kind of LCD are you using?

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 12:34 pm
by InvalidException
I have 2 of EPD
one is: LB060S01
https://developer.mbed.org/media/upload ... 1-rd02.pdf

and second: ED060SC4
http://essentialscrap.com/eink/ED060SC4V2.pdf

and for drive waveforms http://essentialscrap.com/eink/waveforms.html
you will see there delay needed for 1, 2, 4, 5, 100 and 200 us

And as he was using STM32L series is not as STM32F1 so trying to make port

Re: STM32F103C8T6 delay not precise

Posted: Tue Nov 22, 2016 12:43 pm
by RoccoMarco
Timers are the same on all the STM32. I think you should create a small driver which implement the protocol using a timer. Take a look to uGFX. Maybe it has already been implemented.