Page 2 of 2
Re: STM32F103C8T6 delay not precise
Posted: Tue Nov 22, 2016 12:53 pm
by InvalidException
he is using this
https://github.com/PetteriAimonen/ED060 ... c#L79-L105and I don't like to mix it with timers/delays (not reliable) so trying right way
Re: STM32F103C8T6 delay not precise
Posted: Tue Nov 22, 2016 1:14 pm
by RoccoMarco
It seems another repository. it is uGFX. BTW a specific driver which uses timer is the best solution I thinks. On that driver you can built a small graphic library and thus a complex application.
Re: STM32F103C8T6 delay not precise
Posted: Tue Nov 22, 2016 11:05 pm
by InvalidException
I have tried with timers but no success
Not at that level yet that I can easily develop with ChibiOS (yet

)
But here is solution I have got working and tested with Logic Analyzer
Got times
for turning ON 1us
for turning OFF 1.125us (without palSetPadModetime is 1.35us just for reference)
Question
Is possible to get direct access to registers for bit changing (Instead palSetPad/palClearPad)???
Maybe this small delay is related to that
Code: Select all
#include "hal.h"
#include "ch.h"
void clockdelay(int us);
int main(void) {
halInit();
chSysInit();
palSetPadMode(GPIOC, GPIOC_LED, PAL_MODE_OUTPUT_PUSHPULL);
while(1) {
palSetPad(GPIOC, GPIOC_LED);
clockdelay(1);
palClearPad(GPIOC, GPIOC_LED);
clockdelay(1);
}
return 0;
}
void clockdelay(int us)
{
for(int i = 0; i<12*us;i++) {
__asm__(" nop;");
}
}
Re: STM32F103C8T6 delay not precise
Posted: Tue Nov 22, 2016 11:36 pm
by steved
InvalidException wrote:Question
Is possible to get direct access to registers for bit changing (Instead palSetPad/palClearPad)???
They are macros which implement direct register access in the most efficient manner supported by the processor. (For example, the ST family have instructions allowing you to set and clear specific bits in a register without affecting the others).
So coding it in a processor-specific way shouldn't make any difference
Re: STM32F103C8T6 delay not precise
Posted: Wed Nov 23, 2016 3:45 am
by InvalidException
I check a bit implementation and it is OK have no impact
But would like to sort this micro delay, can someone help me with timers and how I can get it working for delay in us???
I'm new to this and would use some help, I have enable GPT and not sure which timer should I use?
Can be any of timers or need to be special ones? as in docs only timer 2 is 32bit rest are 16bit
And I saw in few examples TIM6 is used for general purposes so can I use it also?
My biggest confusion with timers is how to use them for delay...
Re: STM32F103C8T6 delay not precise
Posted: Wed Nov 23, 2016 8:45 am
by Giovanni
Hi,
An accurate way to have delays is to use gptPolledDelay() however consider that IRQs and higher priority threads preempting your code will add additional delay. Delays should always to be handled as "guaranteed minimum".
What is your use case exactly? there are tricks that can be used to generate accurate signals, using SPI for example or timers.
Giovanni
Re: STM32F103C8T6 delay not precise
Posted: Wed Nov 23, 2016 11:22 am
by InvalidException
Hi Giovanni
I need delays for LCD, they need to be 1, 2, 4, 5, 10, 100 and 200 micro seconds(us)
so some helper method would be nice to make: delay_us(uint32_t utime)
Also I did next:
In halconf.h
#define HAL_USE_GPT TRUE
In mcuconf.h
#define STM32_GPT_USE_TIM1 TRUE
TImer config
Code: Select all
static const GPTConfig gpt1cfg = {
10000,
NULL,
0,
0
};
and in main.c
so my delay_us would be
Code: Select all
void delay_us(int us)
{
gptPolledDelay(&GPTD1, us);
}
this is only theory didn't try yet as not sure if this is right path? Anything I missed or this is OK?
Re: STM32F103C8T6 delay not precise
Posted: Wed Nov 23, 2016 12:26 pm
by Giovanni
You need to set the GPT clock to 1000000 if you want uS resolution.
It is not magic, it is an HW timer, you need to read the STM32 reference manual.
Giovanni