8051 timer counter
Introduction
TMOD Register
TCON Register
Modes of Operation
Counters
The microcontroller 8051 has two 16 bit Timer/ Counter registers namely Timer 0 (T0) and Timer 1 (T1) .
When used as a “Timer” the microcontroller is programmed to count the internal clock pulse.
When used as a “Counter” the microcontroller is programmed to count external pulses.
Maximum count rate is 1/24 of the oscillator frequency.
8051 timer counter
Introduction
TMOD Register
TCON Register
Modes of Operation
Counters
The microcontroller 8051 has two 16 bit Timer/ Counter registers namely Timer 0 (T0) and Timer 1 (T1) .
When used as a “Timer” the microcontroller is programmed to count the internal clock pulse.
When used as a “Counter” the microcontroller is programmed to count external pulses.
Maximum count rate is 1/24 of the oscillator frequency.
This presentation gives an overview of the PIC micro-controllers. Additionally, it describes the advantages, disadvantages and applications of these micro-controllers. It also explains real-world projects that are possible using the PIC micro-controllers.
In this presentation we can learn about basic concept of interrupts, steps of interrupts, data processing during interrupts, and interrupt logic diagram clearly.
This presentation discusses the Serial Communication features in 8051, the support for UART. It also discusses serial vs parallel communication, simplex, duplex and full-duplex modes, MAX232, RS232 standards
This presentation gives an overview of the PIC micro-controllers. Additionally, it describes the advantages, disadvantages and applications of these micro-controllers. It also explains real-world projects that are possible using the PIC micro-controllers.
In this presentation we can learn about basic concept of interrupts, steps of interrupts, data processing during interrupts, and interrupt logic diagram clearly.
This presentation discusses the Serial Communication features in 8051, the support for UART. It also discusses serial vs parallel communication, simplex, duplex and full-duplex modes, MAX232, RS232 standards
Design and development of programmable controller for air sampling machineeSAT Journals
Abstract A programmable Controller is designed and developed for time pedestal controlling of Air Sampling Machine. The major purpose of the designed system is to reduce filter damage of Air Sampling Machine. The main function of the controller is to automatically switching the Air Sampling Machine with predefined On-Off time interval for 24 hours operation. This is a low cost system which is designed using locally available components and user friendly. The controlling operation is maintained by ATMEL AT89C52 microcontroller. A programmable real time clock PCF8583 is used to produce timing control signal for automatic switching of the Air Sampling Machine. Control signals generated by real time clock operate opto-isolator and an electromechanical relay for switching the Air Sampling Machine. EEPROM (M24C64) is used to store necessary data. The instruction firmware for the designed controller has been developed in BASIC platform using BASCOM-8051 software. The designed system is functioning properly and serving the purpose of the design. Keywords: Programmable Controller, AT89C52 microcontroller, RTC, EEPROM, I2C Protocol, BASCOM-8051 IDE
1 Microcontroller overview
1.1 Industrial automation systems overview
1.2 Microcontroller architecture
1.3 The pedagogical robot
1.4 Digital Inputs/Outputs
1.5 Embedded C Language
It is obvious that vehicle weight has a linear relationship
with the energy to be dissipated (stored) and the change
in velocity required has a exponential relationship.
• Deceleration times and stopping distances vary
somewhat for all vehicles on a given road surface.
• It should then be obvious that sizing the brake system
components has critical importance with respect to the
potential vehicle velocity and the mass of the vehicle.
• Note that heavy trucks generally have greater stopping
distances as compared to typical passenger cars.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
GridMate - End to end testing is a critical piece to ensure quality and avoid...ThomasParaiso2
End to end testing is a critical piece to ensure quality and avoid regressions. In this session, we share our journey building an E2E testing pipeline for GridMate components (LWC and Aura) using Cypress, JSForce, FakerJS…
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!SOFTTECHHUB
As the digital landscape continually evolves, operating systems play a critical role in shaping user experiences and productivity. The launch of Nitrux Linux 3.5.0 marks a significant milestone, offering a robust alternative to traditional systems such as Windows 11. This article delves into the essence of Nitrux Linux 3.5.0, exploring its unique features, advantages, and how it stands as a compelling choice for both casual users and tech enthusiasts.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Maruthi Prithivirajan, Head of ASEAN & IN Solution Architecture, Neo4j
Get an inside look at the latest Neo4j innovations that enable relationship-driven intelligence at scale. Learn more about the newest cloud integrations and product enhancements that make Neo4j an essential choice for developers building apps with interconnected data and generative AI.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Dr. Sean Tan, Head of Data Science, Changi Airport Group
Discover how Changi Airport Group (CAG) leverages graph technologies and generative AI to revolutionize their search capabilities. This session delves into the unique search needs of CAG’s diverse passengers and customers, showcasing how graph data structures enhance the accuracy and relevance of AI-generated search results, mitigating the risk of “hallucinations” and improving the overall customer journey.
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
2. Timers and PWM
Bibliography
Microcontroller PIC18F4550 Data Sheet
39632c.pdf - Chapters 11 to 15
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 2
MPLAB_C18 libraries documentation
MPLAB_C18_Libraries_51297f.pdf - Chapters 2.7 and 2.9
MPLAB_C18 header files
timers.h and pwm.h
MPLAB_C18 C source files
mcc18srctraditionnalpmc
3. Introduction
• In this course, we will talk about :
– Timers
– DC motor speed control (shortly)
– Pulse width modulation
– Basic state machine diagrams
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 3
– Basic state machine diagrams
4. Timers
• 4 timers are available :
– Timer0
– Timer1
– Timer2
– Timer3
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 4
• Each of them has general and special features.
• We will study general features.
• Then we’ll use special features with Timer2.
• It is necessary to understand the microcontroller
data sheet to be able to use the C hardware libraries.
5. Basic timer block diagram
8 or 16-bit counterClock
TMRxON bit
TMRxIF bit
set on
overflow
---
cleared by
software
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 5
Clock selection
Multiplexer
Programmable Prescaler
Sync with internal clock
Internal
or
external
clock
sources
software
Microcontroller internal data bus
read or write
the counter
register
.
.
.
6. Timers configuration and use
• C18 timers libraries allow :
– to access configuration registers and start the timer
(OpenTimerx functions).
– to read the value of the counter register
(ReadTimerx functions).
– to write a new value to the counter register
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 6
– to write a new value to the counter register
(WriteTimerx functions).
– to stop the timer (CloseTimerx functions).
• To test overflow, we need to read TMRxIF bit directly
in its own register.
• The Microcontroller Data Sheet gives information
about the concerned registers.
7. Rotation measurement
signal
LEFT_ENCODER
R1 R2
VCC
4
31
2
U3
H21A1
VCC
Simplified schematic
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 7
time
Each edge corresponds to a rotation of a known angle of the axis of the motor.
We know the reducer rate and the diameter of the wheel, so it is possible to calculate
the distance accomplished by the robot.
We have to count edges : we ‘ll use a timer with an external clock.
8. Example : use of Timer1 to count events
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 8
9. Configure and start Timer1
OpenTimer1(
TIMER_INT_OFF &
T1_16BIT_RW &
T1_SOURCE_EXT &
T1_PS_1_1 &
T1_OSC1EN_OFF &
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 9
T1_OSC1EN_OFF &
T1_SYNC_EXT_OFF
);
Disable the interrupt generation from
Timer1. We will see this later.
Use Timer1 as a 16-bit counter.
Select an external clock.
Choose the prescale value.
Disable the internal Timer1 oscillator.
Disable the synchronization with the
processor clock.
Then, clear the counter register, clear TMR1IF and start the timer.
10. Read and write the Timer1 value
• Read the value :
– prototype
unsigned int ReadTimer1( void );
– code example
unsigned int result;
result = ReadTimer1();
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 10
• Write a new value :
– prototype
void WriteTimer1( unsigned int timer );
– code example
WriteTimer1(0);
11. Test the Timer1 overflow
• TMR1IF is the bit 0 of PIR1 register.
• Code example :
if (PIR1bits.TMR1IF != 0) {
// timer1 overflow detected
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 11
// timer1 overflow detected
PIR1bits.TMR1IF = 0; // reset flag
}
12. Timer2 special features
• Timer2 is an 8-bit counter.
• The values of TMR2 and PR2 are compared on each clock cycle.
• When the two values are equal, the comparator generates an output
signal.
• This signal also resets the value of TMR2 to 00h on the next cycle
and drives the output counter/postscaler.
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 12
13. DC motor speed control
• First, we assume the motor speed depends on the average voltage. Thus,
we need to change the average voltage on the motor.
• The power electronics block contains a H-Bridge designed for motion
Power electronics
DC
motor
sign
pwm
POWER
Vmotor
from
microcontroller
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 13
• The power electronics block contains a H-Bridge designed for motion
control applications.
• The signal sign controls the direction of the rotation.
• The signal pwm controls the average voltage on the motor.
0
1
t
T
α.T
(1 - α).T
pwm
– T is the period.
– The duty cycle (α) is generally given in percent.
– The average value is α.
– For a power supply of U volts, Vmotor = α.U.
14. Capture/Compare/PWM (CCP) Modules
• Two CCP modules are available (CCP1 and CCP2).
• In PWM mode, the two modules use Timer2 as a time base.
Thus PWM frequency is the same for CCP1 and CCP2.
• Each module has its own duty cycle.
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 14
15. PWM period and duty cycle
• The main trap is that the PWM period is set by a 8-bit
value and the duty cycle is controlled by a 10-bit
value.
• Example :
– let’s assume the period value is 99, thus the TMR2
value (8-bit value) should grow from 0 to (99+1) = 100
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 15
value (8-bit value) should grow from 0 to (99+1) = 100
(reset value)
– so the TMR2 extended value (10-bit value) should
grow from 0 to (99+1) * 4 = 400
– and then the duty cycle value should vary from 0 (0%
duty cycle) to 400 (100% duty cycle).
16. PWM configuration and use
• C18 timers libraries allow :
– to configure Timer2 (OpenTimer2 function).
– to configure CCPx (OpenPWMx functions).
– to set the duty cycle (SetDCPWMx functions).
– to stop the PWM (ClosePWMx functions).
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 16
• The pins concerned must be configured as outputs
– by setting the appropriate TRIS register bit
– or by using SetOutputPWMx functions.
17. Example
• Let’s assume that we need a 20kHz PWM period.
– On our board, Fosc = 48MHz thus Fosc/4 = 12MHz.
– To have a full resolution (10-bit) we must choose the
biggest value for the 8-bit period register.
– If we choose 0xFF, the clock frequency will be divided
by 256 to obtain the Timer2 frequency.
– Now, we are able to calculate the prescaler :
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 17
– Now, we are able to calculate the prescaler :
(12.106 / 256) / 20000 = 2.34 < 4
– We have to reverse the calculus with a prescale value
of 4 and we’ll find the period register value :
PR2 = (12.106 / 4) / 20000 – 1 = 149
– Thus the duty cycle should be between 0 and 600.
18. Code example
#include <timers.h>
#include <pwm.h>
…
OpenTimer2( // Timer2 configuration
TIMER_INT_OFF & // No interrupt
T2_PS_1_4 & // Prescale 1:4
T2_POST_1_1 // Don’t use postscaler actually
);
OpenPWM1(149); // Use of CCP1 as PWM module
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 18
OpenPWM1(149); // Use of CCP1 as PWM module
OpenPWM2(149); // Use of CCP2 as PWM module
SetDCPWM1(0); // Set 0% duty cycle to PWM1
SetDCPWM2(0); // Set 0% duty cycle to PWM2
TRISCbits.TRISC2 = 0; // Make RC2 (PWM1) an output
TRISCbits.TRISC1 = 0; // Make RC1 (PWM2) an output
…
SetDCPWM1(150); // Set 25% duty cycle to PWM1
SetDCPWM2(450); // Set 75% duty cycle to PWM2
…
19. State machine
• We will use state machine diagram to program
sequential comportment of the robot.
• We will translate the diagram into C language by
using switch/case statements.
• We will study an example to understand clearly the
principles.
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 19
principles.
• We would like the two wheels to cover the same
distance.
• The simplest way to do it is exposed on the next
slide.
20. Example of state machine diagram
0
1
set the distance to cover
BP0 pushed
two motors on
left
distance
done
right
distance
done
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 20
32 left motor onright motor on
right
distance
done
left
distance
done
21. Code example
…
void main(void)
{
//local variables definition and initialization
unsigned char State = 0; // Store the actual state
char Bp0; // Store 1 if BP0 is pushed
unsigned int LeftEncoder, // Store Timer1 value
RightEncoder, // Store Timer0 value
Distance; // Store "distance" to cover
//peripheral configuration
…
while(1) { // main loop
Bp0 = !(PORTBbits.RB3); // Read BP0 status
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 21
Bp0 = !(PORTBbits.RB3); // Read BP0 status
RightEncoder = ReadTimer0(); // Read right encoder value
LeftEncoder = ReadTimer1(); // Read left encoder value
switch (State) { // State machine
case 0 : // State 0
SetDCPWM1(0); // Set 0% duty cycle to left pwm
SetDCPWM2(0); // Set 0% duty cycle to right pwm
if (Bp0) { // BP0 is pushed
State = 1; // Go to State 1
WriteTimer0(0); // Reset encoders
WriteTimer1(0);
Distance = 1000; // Set distance to cover
}
break; // end case 0
22. case 1 :
SetDCPWM1(150); // Set 25% duty cycle to left pwm
SetDCPWM2(150); // Set 25% duty cycle to right pwm
if (LeftEncoder >= Distance) {
// Left wheel covers the distance
State = 2; // Go to State 2
} else if (RightEncoder >= Distance) {
// Right wheel covers the distance
State = 3; // Go to State 3
}
break; // end case 1
case 2 :
SetDCPWM1(0); // Set 0% duty cycle to left pwm
SetDCPWM2(150); // Set 25% duty cycle to right pwm
if (RightEncoder >= Distance) {
// Right wheel covers the distance
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 22
// Right wheel covers the distance
State = 0; // Go to State 0
}
break; // end case 2
case 3 :
SetDCPWM1(150); // Set 25% duty cycle to left pwm
SetDCPWM2(0); // Set 0% duty cycle to right pwm
if (LeftEncoder >= Distance) {
// Left wheel covers the distance
State = 0; // Go to State 0
}
break; // end case 3
} // end switch
} // end while
} // end main
23. Conclusion
• We have learnt
– how to use Timers
– how to control the speed of a DC motor
– how to generate PWM signals
– how to program a simple state machine
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 23
• We’ll use this knowledge
– to manage with distance measurement
– to control the speed of the robot
– to run a special trajectory
24. Now, practice
• Use timer1 to count events on left encoder
• Use timer0 to count events on right encoder
• Change speed of motors using PWM
• The robot covers a circle shaped trajectory
• The robot covers a house shaped trajectory
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 24