# STM32H7 32-Bit Counter with Reset, C Language Function

Need help a simple a 32-Bit counter with reset.

Pseudo code:

int x, value;
int count = 0;

while(count == 0)
{
x = x + ?;
osDelay(1000);
if(x == 2^31 This Also? )
{
x = 0;
break;
}
}


I want x to count up to 32 bits and then reset with 1 s intervals.

• If you want an exact time you should use a timer not a delay loop. – Mike Apr 28 at 6:04
• Did you mean you need a timer counting from 0 to 2^31 with 1s period? You'll need 2.147 GHz clock to feed it which I don't think any STM32H7s can generate. – Long Pham Apr 28 at 6:07
• Is this a question related to your coursework (homework, exam, lab)? It looks like it would be, and we don't give out solutions to such questions here. You need to show us that you have done a substantial amount of work yourself, then as a specific question. – Elliot Alderson Apr 28 at 11:29

The proper way to do this is to use the on-chip hardware peripheral timers of your MCU. That being said, if you for some reason needs a counter like this you should not use signed types. In fact the default primitive data types of C (int, long etc) should never be used in embedded systems - you should be using uintn_t types from stdint.h.
for(uint32_t i=0; ; i++) // 2nd clause intentionally empty, loop forever