Page 1 of 1
Help with timer
Posted: Fri Apr 17, 2020 6:14 pm
by RLOPES780
I'm working with the dspic33ep512mu 810 and a 48 mhz crystal.
I need a timer with a frequency of 1 hz.
Due to the timer properties in the flowcode, the frequency of at least 1,431 hz ((Fosc / 2) (1: 256) (65536)) can be done. What trick can I do to achieve the timer frequency of 1 hz, without changing the crystal (48 mhz).
Thankful;
Ricardo.
Re: Help with timer
Posted: Fri Apr 17, 2020 7:10 pm
by kersing
You could try to calculate a more frequency interrupt (like 5 a second) and use a counter in the interrupt handler to only execute the code you need to run at 1 hz when the counter reaches 5.
Re: Help with timer
Posted: Fri Apr 17, 2020 7:58 pm
by RLOPES780
Hello kersing;
grateful for the attention.
Can you give me an example in flowcode?
Hugs;
Ricardo.
Re: Help with timer
Posted: Fri Apr 17, 2020 9:39 pm
by kersing
I don’t have a computer with Flowcode handy for the next 48 hours so may-be you can try yourself and post the result here for me to take a look at after the weekend?
Re: Help with timer
Posted: Sat Apr 18, 2020 11:45 pm
by RLOPES780
Hello Kersing;
Sorry, we're over the weekend. Make the most of it.
I didn't even realize it, it was my excitement.
I made a little code. Would it be more or less like this?
See you on Monday.
Thankful;
Ricardo.
Re: Help with timer
Posted: Mon Apr 20, 2020 12:57 am
by RLOPES780
simgle file
Re: Help with timer
Posted: Mon Apr 20, 2020 10:07 am
by Benj
Hello,
Here's an example of what Kersing suggested.
I ramped the timer rate up to 25Hz and then using a variable I count the number of interrupts up to 25 to give the 1Hz interrupt you require.