I have read on one of the electronics forums that "Referring the data sheet is the old school way".Delving right into the very basics of how the microcontroller take in information , process them and give an output, is something than sparked my curiosity, and I was thrilled to do the "ols school way"..:P
ATtiny24/44/84 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATtiny24/44/84 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.
From the pin outs its evident that there are broadly 4 kinds of pinouts,the Vcc (Power Supply),GND (Ground),RESET, PORT A and PORT B.
Port A is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port A pins that are externally pulled low will source current if the pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.
Port B is a 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability
Then I understood from the above flow diagram, that PORT A has Analog to Digital Convertor capability whereas PORT B doesnt have.
Because I am new to the world of ICs and electronics, I have doubts on what are pull up and pull down resitors , also on how ADC's work. On studying the above flow chart, I would like to learn the workings of a watchdog timer, and how interupts are used.
There were lot of options , on which to code the program,I decided to learn from the fundamentals.Therefore, I took up to learning C and also flashing the files onto the bard using terminal command rather than other interfaces like arduino or other Graphical interfaces.
The first program I tried was to Blink the LED at a specific time periods.
This command would convert the file in .c format to .o format
Thias command would convert from.o format to .elf format
This command would convert from .elf format to .hex format.
This command would flash the .hex file onto the attiny44 chip.
By doing this simple program, this is what I learnt:
Now, I wanted to try the same program in Arduino IDE.
To get started with Arduino IDE, we need to first setup the attiny boards in the available set.
For this follow these steps:
Having done this much, would ensure that all the details of the tiny44 chip which we have is there in the IDE now and the parameters are set in the settings.
The logic behind the program is the same from the C program i have written earlier, however, the language used is much more user friendly.
My instructor, told me that , that all this were just a "mask", behind which is a very simple language (assembly).
Once the program has been written, we need to send it to our board, for this :
Having done this much the, file would be compiled and flashed unto the board.
The .c source code for the blink program can be found here.
The .ino arduino code for the blink program can be found here.
Now, that I have tried a very basic program , I wanted to do a program that could use both an input as well as an output.
For this, I wanted the LED to be lit when I pressed the switch.
The .c source code for the switch program can be found here.
The .ino arduino code for the switch program can be found here.
Having done some basic input output and cliched examples in programming, I wanted to try something a bit more advanced
For this I did a Pulse Width Modulation (PWM),based program
I wanted to adjust the brightness of the LED.
To get started on understanding how the PWM works and how to program one I reffered to an excellent tutorial
I have used a Fast PWM mode, for executing this program.
Now, refereeing to the Data Sheet for TCCR0A register we see,that:
Now, referring to the tables from 11-2 to 11-8, we get the values as;
The duty cycle can be calculated by the formula below:
So, in the above formula to address the prescaler (N), we have to define the TTCCR0B
For defining the Clock Select bits refer to the table 11-9 , as shown below:
My LED was connected on PA7, which is a OCR0B (Output Compare Register B)
Having achieved different brightness based on the value of duty cycle, I wanted it t have a continous increase and further decrease in brightness, for this i will be using Arduino IDE.
The .c source code for the PWM program can be found here.
The .ino arduino code for the PWM program can be found here.
As I was completely new to Programming, This was great introduction week.I learnt how to program with C language, and also understand the backgrounf working of flashing a program onto a board.C programming gave me an insight into programming in the very basic level.However, Processing language used in Arduino is somewhat easier to understand, for a first time user.