WEEK9: EMBEDDED PROGRAMMING
UNDERSTANDING DATASHEET
- I have gone through datasheet once to understand general overview and its functionality.
- For my board I have used ATtiny45 microcontroller, so I am describing my learning from datasheet of tiny45 microcontroller.
- Before explaining detailed functionality I have used for this MCU, I am describing general features of tiny45 and its terms.
- Very good tutorial by sparkfun is here how to read datasheet
ASSIGNMENTS:
Individual assignment
- Read a microcontroller data sheet.
- Program your board to do something, with as many different programming languages and programming environments as possible.
Group assignment
- Experiment with other architectures
General terms to understand ATtiny45 microcontroller
- Microcontroller: Its small computer in single integrated circuit, which mainly contains memory, input/output pins and CPUs/processor.
- RISC: Reduced instruction set computer, which means computer/chip has small (cycle per instruction) and simple set of instructions rather than large and complex set of instructions.
- Peripheral: Which stats input/output pins consists by microcontroller, which one can use to program that microcontroller to execute certain function
- Pin configuration: It gives information of peripherial i/o pins, which pin has what capabilities/functions, and communication feature with external programmer
- Port B (PB0:PB5): Its bi-directional i/o port with internal pull up resistor. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated.
- RESET: It basically reset the input. A low level of this pin with longer than minimum pulse length generates reset.
- CLK and CLR: CLK is Clock and CLR is Clear.
- VCC and GND: VCC is voltage supply and GND is ground.
Understanding pin-outs of ATtiny45
- For my board I have used ATtiny45 so, after reading and going through the documentation of the datasheet of ATtiny 45, the most important data to understand carefully is pinout and its functionality.
- Attinty45 consists 8 I/O pins, which can be used for programming.
I/O pins I have used for my board
- With 8 pin of tiny45 microcontroller following pins I have used for particular functionality. Also the connections I have made accordingly in Eagle circuit design of my board.
- VCC and GND- goes to respective power supply and ground connection
- RST (pin 1)- goes to reset pin of ISP header
- MISO (pin 5)- goes to ective MISO (multi input single output pin) of ISP header
- MOSI (pin 6)- goes to respective MOSI (multi output single input) of header pin
- SCK (pin 7)- SCK is connected with SCK pin of header
- CLk (pin 3)- is connected with button switch
- CLK(pin 4)- is connected with LED
PROGRAMMING T-BOARD WITH FABISP
- I have used Arduino board to program my T-board in week-7 where I have explained step by step guide and requirement for programming. This time I want to program T-board with FabISP which I made in week-3.
- I have decided to run two types of program in T-board, one is simple LED blink and second is LED blink with button
- I am also aiming to program my board with LDR sensor, by writing code which blinks LED with light or vice versa.
STEP01: CONNECT FABISP WITH T-BOARD
- Now to connect FabISP and my board I have to identify pin configuration and respective connections by female to female jumper wire.
- The method I have used here is to connect reset to reset pin first and accordingly connect all respective pins such as SCK, MISO, MOSI, VCC and GND of ISP header.
STEP02: USE ARDUINO IDE TO USE FABISP AS PROGRAMMER
- Ardiuno IDE (Integrated development environment) is programming platform used to load program into microcontroller.
- The Arduino IDE supports the languages C and C++ using special rules of code structuring. It has text editor feature with syntax highlighting, text cutting and replacing.
- Now, to work on my baord, I have to select programmer as TinyISP from Tools.
- Board as ATtiny 25/45/85
- Processor: ATtiny 45
- Clock: External 20MHz
STEP03: WRITE A PROGRAM TO BLINK LED WHILE PRESSING SWITCH
- I have already wrote this program in week 7, so I have loaded the same program and make changes in pin number.
- I have wrote program with basics of C language I knew and by referring some of example codes. Kishan Chavda helped me many times to understand codes and syntax for the same.
- I have used if and else condition to execute blink LED instructions with delay.
- Complete code can be seen here in below image, and program files can be downloaded at the end of this page.
- I have also tried reversing the code, so LED blinking gets stop once I press button switch.
- Once code uploaded in board it was working fine with button [switch, which can be seen here below.
- Reversing the if else condition, so that when I press button it stops blinking.
- Reversing the effect in LED and switch.
STEP04: ADDING LDR SENSOR TO MY BOARD
- To move one step further I wanted to program my board with some kind of sensor.
- So, I have decided to add sensor in my board, I had one extra T-board which I have made in week 7. So I used same board and replaced switch with LDR sensor.
- It should work because micro-controller pin which is connected with switch pad is analogue I/O pin.
- So I collect my board, components with LDR sensor and soldered it.
STEP04: Connect LDR sensor board with FabISP
STEP04: PROGRAM BOARD TO SENSE LIGHT WITH LDR AND OUTPUT BY LED
- Now I opened Ardiuno IDE and selected same programmer, board, processor and clock value to program the board again with FabISP
- To write program for LDR I used reference from Instructable, and it was good help for me to understand program.
- I have defined pin number 4 (LED) as output and pin number 3 (LDR) as input, as per my design of connections in board.
- Secondly I have took "a" as integer and defined its value as less than or equal to 300 to start with. AnalogRead is sintax used to take value from LDR.or
- Once it comes under value it goes to if loop with LED blink code of high and low with delay.
- After some trial and error, 800 is right value for LDR sensor to sense the light and give output as LED blink.
- With different values of LDR sensor limit.
LEARNING CONCLUSION
- After going through this weeks assignments and exercise now I am able to understand what is embedded programming and its requirement for functionality.
- Completing this week I got clear idea and link between electronics design, production and programming. How these three depends upon each other and consideration need to be made right from design part.
- I am looking forward to apply these learning to design my final project's board.
ORIGINAL FILES
- This weeks original programming files I am attaching below as a single folder. It can be accessed from here
INDIVIDUAL CONTRIBUTION TO GROUP WORK
- This week's group assignment is to study different types of architecture of micro controller.
- I have studied Harvard type architecture, and took comparative overview of von nuemann type design.
- Basically in harvard type design CPU and processors are being kept in parallel, so when data is being given to controller, CPU acts as central part between memory units
- Harvard architecture performs better when there is need of image processing and graphics, so most of the today's advanced devices follows this design.
For detailed documentation on comparison of different types of microcontroller architecture is done on lab website
Go to Week 10
Go to Weekly work page