add exercise sheets

This commit is contained in:
Akbar Rahman 2023-12-28 19:49:08 +00:00
parent 557bad8387
commit a84913e3f5
Signed by: alvierahman90
GPG Key ID: 6217899F07CA2BDF
22 changed files with 58653 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

View File

@ -0,0 +1,19 @@
#include <avr/io.h>
void setup()
{
DDRB |= (1<<7); // Set pin 13 as output
TCCR1A = (1<<WGM11) | (1<<COM1C1);
TCCR1B = (1<<WGM12) | (1<<WGM13) | (1<<CS10);
TCCR1C = 0; // No force output compare
ICR1 = 799; // Set PWM frequency noting prescale if any
OCR1C = 79; // Set PWM duty cycle as a fraction of ICR1
}
void loop()
{
}

View File

@ -0,0 +1,53 @@
// Program to generate and count pulses using hardware only.
// Also uses interrupt to handle register overflow.
// For Arduino Mega only, as T/C 1 Compare Output Channel C is linked to pin 13.
// Frequency generation loosely based on code within "Newbie's Guide to AVR Timers".
// The code is revised by Abdelkhalick Mohammad for MMME3085 Module.
#include <avr/io.h>
unsigned long bigLaps; // To record how many times T/C5 overflows
void setup()
{
Serial.begin(9600);
// ===Timer/Counter 5 settings to count input pulses ====
//set pin T5 as input (external); this is pin 47 (Arduino Mega pin mapping)
pinMode(47, INPUT);// set pin to input
TCCR5A=0;// No waveform generation needed (T/C is counting only)
TCCR5B=(1<<CS50)|(1<<CS51)|(1<<CS52);// Normal mode, external clock on rising edge
TCCR5C=0;//No force output compare (we will not study about this in the module)
TCNT5=0;//Initialise counter register to zero
TIMSK5=(1<<TOIE5);//When the T/C reach its maximum, an interrupt will be activated
bigLaps=0;//When an overflow happens, we will increase this bigLaps by 1
sei();// Enable all active interrupts
// === Timer/Counter 1 settings to generate pulses with different frequencies ===
DDRB|=(1 << 7);//T/C1 channel C is connected to pin 13, set it as output
TCCR1B=(1 << WGM12 );//Configure T/C1 for CTC mode
TCCR1A=(1 << COM1C0 );//Enable T/C1 Compare Output channel C in toggle mode
// OCR1A= 7;//Set CTC compare value to 2 MHz at 16MHz AVR clock with no prescaling
// TCCR1B|= (1 << CS10 ) ;//Start T/C1 at Fcpu with no prescaling (i.e., 16MHz)
OCR1A=1249;//Set CTC compare value to 200 Hz at 16MHz AVR clock with 1/64 prescaling
TCCR1B|= (1 << CS10 )|(1 << CS11 );// Start T/C1 at Fcpu (i.e., 16MHz)
}
// === This is a routine which will be called if an overflow happens in T/C5 ===
ISR(TIMER5_OVF_vect )
{
bigLaps++; //when this runs, you had 65365 pulses counted
}
unsigned long Current_Count=0;//A variable to store the total number of pulses
void loop() {
Current_Count = TCNT5 + bigLaps*65536;
Serial.println(Current_Count); // Print the current number of pulses
delay(1000); // Intervals between each two consecutive prints
}