Revision Lecture Flashcards
How do you create binary numbers?
0b
0B
B
How do you create Hexadecimal numbers?
0x
0X
For the DDRx, what is an input and what is an output?
0 = Input
1 = Output
How can I make all pins on port A into input pins?
DDRA = 0b00000000
How can I make the 4 lower bits of port B an output and the 4 higher bits into inputs?
DDRB = 0b00001111
DDRA = 0x00; //Set port A as input x = PINA;
What does the second line do?
//Read contents of port A
What can PORTx - Port x Data Register do?
- Output data
- Activate / Deactive Pull Up Resistors
How can I output 0xFF on Port B?
DDRB = 0b11111111; //Set all pins of port B as outputs PORTB = 0xFF; //Write data on port
How can I output data in variable x on port A?
DDRA = 0xFF; //Make port A an output PORTA = x; //Output variable on port
What is Aliasing?
Two or more signals have the same sampled representation
What is the ADC resolution of an analog signal with a maximum value of 3.3V with a 10-bit ADC?
2^10 = 1024
3.3/1024 = 3.22mV
What is the ADC frequency formula?
Frequency of CPU / Prescaler value
What are the available ADC Prescaler Values?
2, 4, 8, 16, 32, 64, 128
If I have a CPU frequency of 16MHz and use a prescaler of 64, what is the effective frequency?
16MHz / 64 = 250kHz
What is the global interrupt bit?
sei()
cli()
What is an ISR?
Interrupt Service Routine
How do you write code for an ISR?
ISR(INT_vect) { }
What are the rules for writing an Interrupt Service Routine?
- Keep it short
- Don’t use delay(), serial prints
- No input variables or returned variables
- All changes have to be made on global variables
- Shared variables should be declared volatile
How do the ATmega2560 External Interrupts work?
INT7:0
Reset Pin = Pin30
PCINT23:0: Pin Change Interrupt
How many steps are in an 8 bit timer?
256 steps
0 to 255
What are the prescaler values available for a clock?
8, 64, 256, 1024
How many timers are in the Atmega2560 and how many bits do they have?
Timer/Counter 0, 2: 8 bit
Timer/Counter 1, 3, 4, 5: 16 bit
ISR(TIMER0_OVF_vect) //TIMER0 overflow interrupt service routine. //This ISR is called automatically whenever TCNT0 overflows {tot_overflow++; //Count the number of... } int main(void) { DDRL |= (1 << PL0); //connect LED to PL0 timer0_init(); //initialise Timer0 while (1) { if (tot_overflow >= 12) // Check if... { if (TCNT0 >= 53) // Check if... { PORTL ^= (1 << PL0); // toggles the led TCNT0 = 0; // Reset the... tot_overflow = 0; // Reset the... } } } }
Finish the comments
ISR(TIMER0_OVF_vect) //TIMER0 overflow interrupt service routine. //This ISR is called automatically whenever TCNT0 overflows {tot_overflow++; // count the number of overflows } int main(void) { DDRL |= (1 << PL0); //connect LED to PL0 timer0_init(); //initialise Timer0 while (1) { if (tot_overflow >= 12) // check if no. of overflows = 12 { if (TCNT0 >= 53) // check if the timer count reaches 53 { PORTL ^= (1 << PL0); // toggles the led TCNT0 = 0; // reset the counter tot_overflow = 0; // reset the overflow counter } } } }