I understand how, but not the why

Thread Starter

prophoss

Joined Feb 26, 2019
36
I am having an issue with programming my atmega328p in avr c. I have watched all the videos and I understand which bits to turn on, but what I don't get is how you know which ones to turn on and why. I get about timer1, 2, 0 and prescalers and ocra etc, but is there place that tells you which bits to turn on when you use timer1 as opposed to timer2 etc....I have seen no layout that I can follow and they just go to the next bit because they know which one to go to but don't explain why this one is next or right or wrong. I have googled it and still can't find a good explanation either. Any help would be appreciated.
 

Papabravo

Joined Feb 24, 2006
21,228
AFAIK each timer, indeed each peripheral device, has a range of addresses dedicated to that device. Any bit which controls any aspect of a particular device is locates in a narrow range of addresses in the address space. In the datasheet you can find a layout of the entire register space and you can locate the ranges for each peripheral device. I agree "mo' peripherals -- mo' problems"
 

DNA Robotics

Joined Jun 13, 2014
650
On the easy level. If you want to turn on an LED on port B1, you just set that bit to on or send 00000010 to the whole port B.

C language takes care of a lot of the details for you so you don't have to worry about them.

On a deeper level, look at pages 10 & 11 of that data sheet regarding the status register. I think that is a good example to help you understand.

On page 10, A flexible interrupt module has its control registers in the I/O space with an additional global interrupt enable bit in the status register. All interrupts have a separate interrupt vector in the interrupt vector table.

Then

• Bit 7 – I: Global Interrupt Enable The global interrupt enable bit must be set for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the global interrupt enable register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared by the application with the SEI and CLI instructions, as described in the instruction set reference.
 

MrChips

Joined Oct 2, 2009
30,824
It is like this.

Your car radio or windshield wiper stops working, or the toaster-oven in the kitchen trips the circuit breaker.

In both cases there is a fuse box or a circuit breaker panel and you need to find out which fuse or breaker is enabling the circuit.
You need to check the documentation pertaining to the automobile or the service panel in order to determine which fuse or breaker is responsible.
 

Thread Starter

prophoss

Joined Feb 26, 2019
36
I appreciate all the responses. Ok so far I am hearing read the data sheet. fair enough, but is that all you can do?
I should have been a bit more specific about what my problem is. I understand about DDR and PORT even PIN thanks to sparkfun going deeper series. It is when I start attempting to use the internal clock and interrupts that I get lost quickly. I will go back and read a bit closer about the TCCR and OCRA stuff. Thanks again.
 
Top