7 Replies Latest reply on Jun 28, 2018 5:25 PM by sravanthi.simhadri_3347331

    systick race conditions

    sravanthi.simhadri_3347331

      I am using a systick timer interrupt that looks something like this:

       

      static volatile uint16_t timer = 0;

      static int set_count = 0;

      void USR_Tick(void)   //ISR for systick

      {

         timer++;

      }

      void main(void)

      {

           while(1)

          {

               if (timer==100u )

                {

                     //hardware code (take ~700 micro seconds to execute)

                     set_count++;

                }

                if (timer==200u )

                {

                     //hardware code (take ~700 micro seconds to execute)

                     set_count++;

                }

                if (timer == 300)

                {

                    timer =0;

                }

          }

      }

       

       

      Within my 300 ms reset, I am getting a very high value of set_count, I expect it to be 2. Is that right or am I missing something?