FSM Lecture 36: Exercise-003 Testing on hardware

  • Post author:
  • Post category:Blog

 

Exercise-003 Testing on hardware

 

 

In this article let’s test the Productivity Timer Exercise.

Let’s test this application on the real hardware. I have the setup as shown in Figure 1.

Exercise 003- Hardware setup TinkerCad
Figure 1. Exercise 003- Hardware setup

 

In figure 1, you can see the hardware setup of Exercise 003. There is a 16×2 LCD, one Buzzer, the potentiometer – to set the contrast, button pad– increment time button, decrement time button, start or pause Button, and the pulldown resistors.

The connections are made exactly like I explained in my tinkercad website( See, Hardware connections article), with no changes. You have to connect exactly like that. 

Now, let’s launch our application. Compile once again. The compilation is OK, then upload.

Look at Figure 2; we see the output. You can use the potentiometer to adjust the contrast.

IDLE state TinkerCad
Figure 2. IDLE state

 

It is in the IDLE state now. It’s behaving exactly like the way we expected. It is showing the Time display(000:00), Set time, and a buzzer is beeping for every 500 milliseconds.  

Let’s test the functionality. First, check increment time. Whenever you press the increment time button, the minute is incremented. And when you press the decrement time button, the minute is decremented. And when you press the start button, it is counting down. And you can pause it. When it is paused, you can decrement it or increment it. And let’s start. After that, you can Abort the countdown if you want; you have to press the increment and decrement time button together. It is Aborted. 

 

And now let’s check STAT. When it is in the IDLE mode, you have to press the Start/Pause button to get into the STAT state. 

Testing on hardware TinkerCad
Figure 3. STAT state

 

When I press the Start/pause button, it goes to the STAT state, shows the STAT, and comes back to the IDLE state automatically after 1 second.

case TIME_TICK:{
     if(((protimer_tick_event_t*)(e))->ss == 10){
       mobj->active_state = IDLE;
       return EVENT_TRANSITION;
     }
      return EVENT_IGNORED;
 }
return EVENT_IGNORED;
}

TIME_TICK code

In the STAT function, comparing the ‘ss’ value to 10, a doesn’t look good(as shown above code snippet). Because, when the application comes to the STAT handler, and it receives the TIME_TICK for the first time, the ‘ss’ value could be anything. It need not be 0. It need not be 1. It could be 10. It could be anything. In that case, it immediately returns to the IDLE state. But we require that the STAT be shown at least for 1 second. That’s why it doesn’t look good. I’m going to change my code. 

 

Let’s modify the TIME_TICK code. Add one variable tick_count, if(++tick_count == 30). Let it stay for 3 seconds in the STAT state. If TIME_TICK events are received 30 times, make a tick_count=0, as shown below.

case TIME_TICK:{
  if(++tick_count == 30){
      tick_count = 0;
      mobj->active_state = IDLE;
      return EVENT_TRANSITION;
   }
   return EVENT_IGNORED;
 }

Modified TIME_TICK code

And you create an extended static variable at the top. static uint8_t tick_count. Same logic you can use wherever you have processed TIME_TICK. 

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1 

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.