Timer component AVR

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
mnfisher
Valued Contributor
Posts: 1787
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 151 times
Been thanked: 846 times

Timer component AVR

Post by mnfisher »

The timer component generates the following:

Code: Select all

MX_UINT32 FCD_026e1_Timer1__GetCountMilliseconds()
{
  //Local variable definitions
  MX_UINT32 FCL_COUNT;
  MX_FLOAT FCL_FVAR;
  MX_UINT32 FCR_RETVAL;


  #if (0)
  //Code has been optimised out by the pre-processor
  #else
    FCL_COUNT = FCD_026e1_Timer1__GetRawCount();

    FCL_FVAR = flt_mul(0.000000, flt_fromi(FCL_COUNT));
    FCR_RETVAL = flt_toi(FCL_FVAR);

  #endif

  return (FCR_RETVAL);
The flt_mul by 0.00 - means the result is always going to be 0 - and seems to apply to all the GetCount macros.

Martin

mnfisher
Valued Contributor
Posts: 1787
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 151 times
Been thanked: 846 times

Re: Timer component AVR

Post by mnfisher »

No - it's me = the default instruction rate is 0....

mnfisher
Valued Contributor
Posts: 1787
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 151 times
Been thanked: 846 times

Re: Timer component AVR

Post by mnfisher »

There is, however something not quite right... Consider the attached - on an interrupt (on pin d2) - it toggles the LED on pin 13 - and outputs the number of 'ms' since the last (falling edge) interrupt.
I also have a scope attached to d2 - and a signal generator. The time displayed (with an input period of 8s) - not only vary wildly (from about 280ms to 172000ms - despite the reset timer..) - also the times are displayed every 1s (roughly) - so something odd going on - not only is the interrupt occurring at random intervals - but the times displayed bear no real relation to the actual time. Maybe 'noise' for the interrupt - but the time is wrong....

Results are 'better' using timer2 - and better again using timer0 - but still not great. I wonder if UART is using timer1?

Martin
Attachments
pulse_328p.fcfx
(15.62 KiB) Downloaded 6 times

mnfisher
Valued Contributor
Posts: 1787
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 151 times
Been thanked: 846 times

Re: Timer component AVR

Post by mnfisher »

I added a second timer - and had timer 1 use Tmr0 and timer2 use Tmr2 - printing both values gives :
Tmr1 = 48 tmr2 = 383ms
Tmr1 = 48 tmr2 = 383ms
Tmr1 = 48 tmr2 = 383ms
With a 50ms pulse. Something wrong in the calculation for tmr2 - even allowing for the slight delay in getting the value?

Martin
Attachments
pulse_328p.fcfx
(18.13 KiB) Downloaded 7 times

mnfisher
Valued Contributor
Posts: 1787
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 151 times
Been thanked: 846 times

Re: Timer component AVR

Post by mnfisher »

And adding timer1 into the mix:

Tmr1 = 46 tmr1 = 2028 tmr2 = 372ms
Tmr1 = 46 tmr1 = 2061 tmr2 = 372ms
Tmr1 = 46 tmr1 = 2094 tmr2 = 372ms
Tmr1 = 46 tmr1 = 274875840 tmr2 = 372ms
Tmr1 = 38 tmr1 = 274875872 tmr2 = 304ms
Tmr1 = 3 tmr1 = 274875872 tmr2 = 29ms
Tmr1 = 46 tmr1 = 274875936 tmr2 = 369ms
Tmr1 = 45 tmr1 = 274875968 tmr2 = 367ms
T

Post Reply