I understand how, but not the why

Discussion in 'Embedded Systems and Microcontrollers' started by prophoss, Apr 4, 2019.

  1. prophoss

    Thread Starter New Member

    Feb 26, 2019
    13
    0
    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.
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    3,768
    1,980
    Last edited: Apr 4, 2019
  3. Papabravo

    Expert

    Feb 24, 2006
    12,283
    2,723
    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"
     
  4. BR-549

    AAC Fanatic!

    Sep 22, 2013
    4,936
    1,348
    The programming manual for the chip series/family helps a lot too.
     
  5. DNA Robotics

    Active Member

    Jun 13, 2014
    493
    187
    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.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    19,117
    6,146
    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.
     
  7. prophoss

    Thread Starter New Member

    Feb 26, 2019
    13
    0
    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.
     
Loading...