he is using this
https://github.com/PetteriAimonen/ED060 ... c#L79-L105
and I don't like to mix it with timers/delays (not reliable) so trying right way
STM32F103C8T6 delay not precise
Moderator: RoccoMarco
- InvalidException
- Posts: 13
- Joined: Tue Nov 15, 2016 2:33 pm
- Been thanked: 3 times
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Has thanked: 83 times
- Been thanked: 67 times
Re: STM32F103C8T6 delay not precise
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.
- InvalidException
- Posts: 13
- Joined: Tue Nov 15, 2016 2:33 pm
- Been thanked: 3 times
Re: STM32F103C8T6 delay not precise
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
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
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
- InvalidException
- Posts: 13
- Joined: Tue Nov 15, 2016 2:33 pm
- Been thanked: 3 times
Re: STM32F103C8T6 delay not precise
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...
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...
- 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
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
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
- InvalidException
- Posts: 13
- Joined: Tue Nov 15, 2016 2:33 pm
- Been thanked: 3 times
Re: STM32F103C8T6 delay not precise
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
and in main.c
so my delay_us would be
this is only theory didn't try yet as not sure if this is right path? Anything I missed or this is OK?
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
Code: Select all
gptStart(&GPTD1, &gpt1cfg);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?
- 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
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
It is not magic, it is an HW timer, you need to read the STM32 reference manual.
Giovanni