STM32F103C8T6 delay not precise

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

User avatar
InvalidException
Posts: 13
Joined: Tue Nov 15, 2016 2:33 pm
Been thanked: 3 times

STM32F103C8T6 delay not precise

Post 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
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: STM32F103C8T6 delay not precise

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F103C8T6 delay not precise

Post 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
User avatar
InvalidException
Posts: 13
Joined: Tue Nov 15, 2016 2:33 pm
Been thanked: 3 times

Re: STM32F103C8T6 delay not precise

Post 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?
Hawhill
Posts: 7
Joined: Tue Oct 18, 2016 1:28 pm
Been thanked: 1 time

Re: STM32F103C8T6 delay not precise

Post 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.
User avatar
InvalidException
Posts: 13
Joined: Tue Nov 15, 2016 2:33 pm
Been thanked: 3 times

Re: STM32F103C8T6 delay not precise

Post 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)
Hawhill
Posts: 7
Joined: Tue Oct 18, 2016 1:28 pm
Been thanked: 1 time

Re: STM32F103C8T6 delay not precise

Post 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).
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: STM32F103C8T6 delay not precise

Post by RoccoMarco »

What kind of LCD are you using?
User avatar
InvalidException
Posts: 13
Joined: Tue Nov 15, 2016 2:33 pm
Been thanked: 3 times

Re: STM32F103C8T6 delay not precise

Post 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
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: STM32F103C8T6 delay not precise

Post 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.
Post Reply