Monday 5 June 2017

Micro controller basics

A microcontroller is a self-contained system with peripherals, memory and a processor that can be used as an embedded system.
Most programmable microcontrollers that are used today are embedded in other consumer products or machinery including phones, peripherals, automobiles and household appliances for computer systems.
Due to that, another name for a microcontroller is "embedded controller.".

BLOCKS OF A MICROCONTROLLER
  A microcontroller basically contains one or more following components:
Central processing unit(CPU)
Random Access Memory(RAM)
Read Only Memory(ROM)
Input/output ports
Timers and Counters
Interrupt Controls
Analog to digital converters
Digital  analog converters
Serial interfacing ports
Oscillatory circuits

Difference between BEGIN and BEGIN IMMEDIATE in sqlite

Begin stmt
syntax diagram begin-stmt

syntax diagram commit-stmt

syntax diagram rollback-stmt
No changes can be made to the database except within a transaction. Any command that changes the database (basically, any SQL command other than SELECT) will automatically start a transaction if one is not already in effect. Automatically started transactions are committed when the last query finishes.

Transactions can be started manually using the BEGIN command. Such transactions usually persist until the next COMMIT or ROLLBACK command. But a transaction will also ROLLBACK if the database is closed or if an error occurs and the ROLLBACK conflict resolution algorithm is specified. See the documentation on the ON CONFLICT clause for additional information about the ROLLBACK conflict resolution algorithm.
END TRANSACTION is an alias for COMMIT.

Transactions created using BEGIN...COMMIT do not nest. For nested transactions, use the SAVEPOINT and RELEASE commands. The "TO SAVEPOINT name" clause of the ROLLBACK command shown in the syntax diagram above is only applicable to SAVEPOINT transactions. An attempt to invoke the BEGIN command within a transaction will fail with an error, regardless of whether the transaction was started by SAVEPOINT or a prior BEGIN. The COMMIT command and the ROLLBACK command without the TO clause work the same on SAVEPOINT transactions as they do with transactions started by BEGIN.
Transactions can be deferred, immediate, or exclusive. The default transaction behavior is deferred. Deferred means that no locks are acquired on the database until the database is first accessed. Thus with a deferred transaction, the BEGIN statement itself does nothing to the filesystem. Locks are not acquired until the first read or write operation. The first read operation against a database creates a SHARED lock and the first write operation creates a RESERVED lock. Because the acquisition of locks is deferred until they are needed, it is possible that another thread or process could create a separate transaction and write to the database after the BEGIN on the current thread has executed. If the transaction is immediate, then RESERVED locks are acquired on all databases as soon as the BEGIN command is executed, without waiting for the database to be used. After a BEGIN IMMEDIATE, no other database connection will be able to write to the database or do a BEGIN IMMEDIATE or BEGIN EXCLUSIVE. Other processes can continue to read from the database, however. An exclusive transaction causes EXCLUSIVE locks to be acquired on all databases. After a BEGIN EXCLUSIVE, no other database connectionexcept for read_uncommitted connections will be able to read the database and no other connection without exception will be able to write the database until the transaction is complete.

An implicit transaction (a transaction that is started automatically, not a transaction started by BEGIN) is committed automatically when the last active statement finishes. A statement finishes when its prepared statement is reset or finalized. An open sqlite3_blob used for incremental BLOB I/O counts as an unfinished statement. The sqlite3_blobfinishes when it is closed.

The explicit COMMIT command runs immediately, even if there are pending SELECT statements. However, if there are pending write operations, the COMMIT command will fail with an error code SQLITE_BUSY.
An attempt to execute COMMIT might also result in an SQLITE_BUSY return code if an another thread or process has a shared lock on the database that prevented the database from being updated. When COMMIT fails in this way, the transaction remains active and the COMMIT can be retried later after the reader has had a chance to clear.

In very old versions of SQLite (before version 3.7.11 - 2012-03-20) the ROLLBACK will fail with an error code SQLITE_BUSY if there are any pending queries. In more recent versions of SQLite, the ROLLBACK will proceed and pending statements will often be aborted, causing them to return an SQLITE_ABORT or SQLITE_ABORT_ROLLBACK error. In SQLite version 3.8.8 (2015-01-16) and later, a pending read will continue functioning after the ROLLBACK as long as the ROLLBACK does not modify the database schema.


Example of an IMMEDIATE transaction: 

- BEGIN IMMEDIATE TRANSACTION 
- SELECT 
- UPDATE 
- SELECT 
- UPDATE 
- INSERT 
- SELECT 
- COMMIT 


Here the reserved lock is obtained as soon as the BEGIN statement executes.

For the DEFERRED transaction: 

- BEGIN DEFERRED TRANSACTION 
- SELECT 
- UPDATE 
- SELECT 
- UPDATE 
- INSERT 
- SELECT 
- COMMIT 

Here the shared lock is obtained after the begin statement till the update statement. The reserved lock is obtained when the update statement executes.

Friday 23 December 2016

Intellectual disability

Intellectual Disability (ID), also called intellectual developmental disability (IDD), general learning disability, or mental retardation (MR), is a generalized neurodevelopment disorder characterized by significantly impaired intellectual and adaptive functioning. It is defined by an IQ score under 70 in addition to deficits in two or more adaptive behaviours that affect every day, general living. Once focused almost entirely on cognition, the definition now includes both a component relating to mental functioning and one relating to individuals' functional skills in their environments. As a result of this focus on the person's abilities in practice, a person with an unusually low IQ may not be considered intellectually disabled. Intellectual disability is subdivided into syndrome intellectual disability, in which intellectual deficits associated with other medical and behavioural signs and symptoms are present, and non-syndromic intellectual disability, in which intellectual deficits appear without other abnormalities. Down syndrome and fragile X syndrome are examples of syndromic intellectual disabilities.
Intellectual disability affects about 2–3% of the general population. 75–90% of the affected people have mild intellectual disability. Non-syndromic or idiopathic cases account for 30–50% of cases. About a quarter of cases are caused by a genetic disorder. Cases of unknown cause affect about 95 million people as of 2013.
The signs and symptoms of intellectual disability are all behavioural. Most people with intellectual disability do not look like they are afflicted with such, especially if the disability is caused by environmental factors such as malnutrition or lead poisoning. The so-called typical appearance ascribed to people with intellectual disability is only present in a minority of cases, all of which are syndromic.
Children with intellectual disability may learn to sit up, to crawl, or to walk later than other children, or they may learn to talk later. Both adults and children with intellectual disability may also exhibit some or all of the following characteristics:
1. Delays in oral language development
2. Deficits in memory skills
3. Difficulty learning social rules
4. Difficulty with problem solving skills
5. Delays in the development of adaptive behaviors such as self-help or self-care skills
6. Lack of social inhibitors
Children with intellectual disability learn more slowly than a typical child. Children may take longer to learn language, develop social skills, and take care of their personal needs, such as dressing or eating. Learning will take them longer, require more repetition, and skills may need to be adapted to their learning levels. Nevertheless, virtually every child is able to learn, develop and become a participating member of the community.
Among children, the cause is unknown for one-third to one-half of cases. Down syndrome, velocariofacial syndrome, and fetal alcohol spectrum disorders are the three most common inborn causes. However, doctors have found many other causes. The most common are:
1. Genetic conditions. Sometimes disability is caused by abnormal genes inherited from parents, errors when genes combine, or other reasons. The most prevalent genetic conditions include Down syndrome, Klinefelter's syndrome, Fragile X syndrome (common among boys), neurofibromatosis, congenital hypothyroidism, Williams’s syndrome, phenylketonuria (PKU), and Prader-Willi syndrome. Other genetic conditions include Phelan-McDermid syndrome (22q13del), Mowat-Wilson syndrome, genetic ciliopathy, and Siderius typeX-linked intellectual disability (OMIM 300263) as caused by mutations in the PHF8 gene (OMIM 300560). In the rarest of cases, abnormalities with the X or Y chromosome may also cause disability. 48, XXXX and 49, XXXXX syndrome affects a small number of girls worldwide, while boys may be affected by 47, XYY, 49, XXXXY, or 49, XYYYY.
2. Problems during pregnancy. Intellectual disability can result when the fetus does not develop properly. For example, there may be a problem with the way the fetus' cells divide as it grows. A pregnant person who drinks alcohol (see fetal alcohol spectrum disorder) or gets an infection like rubella during pregnancy may also have a baby with intellectual disability.
3. Problems at birth. If a baby has problems during labor and birth, such as not getting enough oxygen, he or she may have developmental disability due to brain damage.
4. Exposure to certain types of disease or toxins. Diseases like whooping cough, measles, or meningitis can cause intellectual disability if medical care is delayed or inadequate. Exposure to poisons like lead or mercury may also affect mental ability.

ARDUINO MEGA 2560 R3 DEVELOPMENT BOARD


Features:

Microcontroller ATmega2560
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 54 (of which 15 provide PWM output)
Analog Input Pins 16
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 256 KB of which 8 KB used by boot loader
SRAM 8 KB
EEPROM 4 KB
Clock Speed 16 MHz
                                      Table 2.1 features of arduino mega board
       
The Arduino Mega 2560 is a microcontroller board based on the ATmega2560. It has 54 digital input/output pins (of which 14 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with an AC-to-DC adapter or battery to get started. The Mega is compatible with most shields designed for the Arduino Duemilanove or Diecimila.

The Arduino Mega2560 can be powered via the USB connection or with an external power supply. The power source is selected automatically. External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and VIN pin headers of the POWER connector.

The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.


The power pins are as follows:
1. VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
2. 5V. the regulated power supply used to power the microcontroller and other components on the board. This can come either from VIN via an on-board regulator, or be supplied by USB or another regulated 5V supply.
3. 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.  GND. Ground pins.

The ATmega2560 has 256 KB of flash memory for storing code (of which 8 KB is used for the boot loader), 8 KB of SRAM and 4 KB of EEPROM.

Each of the 54 digital pins on the Mega can be used as an input or output, using pin Mode (), digitalWrite (), and digitalRead () functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 ohms. The Mega2560 has 16 analog inputs, each of which provides 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and analog Reference () function.

Thursday 22 December 2016

Arduino compatible audio playback board

 AUDIO PLAYBACK BOARD - aPR33A3


                         

FEATURES

1. Operating Voltage Range: 3V ~ 6.5V
2. Single Chip, High Quality Audio/Voice Recording & Playback Solution
3. No External ICs Required
4. Minimum External Components
5. User Friendly, Easy to Use Operation
6. Programming & Development Systems Not Required
7. 170/ 340/ 680 sec. Voice Recording Length in aPR33A1/aPR33A2/aPR33A3
8. Powerful 16-Bits Digital Audio Processor.
9. Non-volatile Flash Memory Technology
10. No Battery Backup Required
11. External Reset pin.
12. Powerful Power Management Unit
13. Very Low Standby Current: 1uA
14. Low Power-Down Current: 15uA
15. Supports Power-Down Mode for Power Saving
16. Built-in Audio-Recording Microphone Amplifier
17. No External OPAMP or BJT Required
18. Easy to PCB layout
19. Configurable analog interface
20. Differential-ended MIC pre-amp for Low Noise
21. High Quality Line Receiver
22. High Quality Analog to Digital and PWM module
23. Resolution up to 16-bits
24. Simple And Direct User Interface

The aPR33A series are powerful audio processor along with high performance audio analog-to-digital converters (ADCs) and digital-to-analog converters (DACs). The aPR33A series are a fully integrated solution offering high performance and unparalleled integration with analog input, digital processing and analog output functionality. The aPR33A series incorporates all the functionality required to perform demanding audio/voice applications. High quality audio/voice systems with lower bill-of-material costs can be implemented with the aPR33A series because of its integrated analog data converters and full suite of quality-enhancing features such as sample-rate convertor.

The aPR33A series C2.0 is specially designed for simple key trigger, user can record and playback the message averagely for 1, 2, 4 or 8 voice message(s) by switch, It is suitable in simple interface or need to limit the length of single message, e.g. toys, leave messages system, answering machine etc. Meanwhile, this mode provides the power-management system. Users can let the chip enter power-down mode when unused. It can effectively reduce electric current consuming to 15uA and increase the using time in any projects powered by batteries.

Arduino and its features

ARDUINO – AN INTRODUCTION
Arduino is an open-source prototyping platform based on easy-to-use hardware and software.

Arduino boards are able to read inputs in the form of
1.Sensor data
2.Push buttons
3. Twitter message etc …
And can output in the form of
1.Twitter notification
2.Glow an LED
3.Turn on a motor


WHY ARDUINO?
Inexpensive
Cross-platform
Simple, clear programming environment
Open source and extensible software
Open source and extensible hardware

Coding languages for arduino
C
C++
C#
Java
Arduino using frameworks
.net


Digital pins-- Use these pins with digitalRead(), digitalWrite(), and     analogWrite(). analogWrite() works only on the pins with the PWM symbol.

Pin 13 LED --The only actuator built-in to your board. Besides being a handy target for your first blink sketch, this LED is very useful for debugging.

Power LED Indicates that your Genuino is receiving power. Useful for debugging.

ATmega microcontroller-- The heart of your board.

Analog input- Use these pins with analogRead().
GND and 5V pins-- Use these pins to provide +5V power and ground to your circuits.

Power connector-- This is how you power your Genuino when it’s not plugged into a USB port for power. Can accept voltages between 7-12V.

TX and RX LEDs --These LEDs indicate communication between your Genuino and your computer. Expect them to flicker rapidly during sketch upload as well as during serial communication. Useful for debugging.

USB port-- Used for powering your Genuino Uno, uploading your sketches to your Genuino, and for communicating with your Genuino sketch (via Serial. println() etc.).

Reset button --Resets the ATmega microcontroller

Tuesday 20 December 2016

Steps to use gdb

This document explains how to use gdb, a debugger for the unix environment. To use gdb, you first need compiled source code. If you have questions on how to do this in the unix environment, look at the quickstarts forcompiling code or using make. Remember, when you use make you must use the -g flag for gdb to perform correctly.
  1. Print out this document. 
    This is so you can have the instructions next to you without trying to flip between the web page and the IDE.
  2. Start gdb. 
    Type "gdb [filename]" where [filename] is the name of the compiled file you wish to debug (the name you type to run your program).
  3. Set the arguments. 
    If your program runs with any command line arguments, you should input them with "set args". For example, if you would normally run your program "test" with the command line "test -paramater1 -parameter2" you would type "set args -parameter1 -parameter2".
  4. Debugging your program
    To debug your program in gdb, you have to run it by typing "run". However, if you just type "run" gdb will run your program to completion without debugging it at all. If your program crashes, gdb will stop it and allow you to debug it. However, you will sometimes want to stop your program at other positions. To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program. To specify other places where gdb should stop, see the section on breakpoints below.
  5. Controlling program execution Once your program has stopped, you can move through your code one step at a time, or execute multiple lines at once. To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n". This is equivalent to the "step over" command of most debuggers.

    If you want gdb to resume normal execution, type "continue" or "c". gdb will run until your program ends, your program crashes, or gdb encounters a breakpoint.

    Since all of gdb is all in one window, when you are debugging you cannot see the source code for your program. To view the source code, type "list" or "l". gdb will print out the source code for the lines around the current line to be executed. To view other lines, just type "list [linenumber]", and gdb will print out the 20 or so lines around that line. gdb remembers what lines you have seen, so if you type "list" again it will print out the next bunch of lines.
  6. Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.cpp, you would type "break main.cpp:55".

    You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.
  7. Working with breakpoints
    • To list current breakpoints: "info break"
    • To delete a breakpoint: "del [breakpointnumber]"
    • To temporarily disable a breakpoint: "dis [breakpointnumber]"
    • To enable a breakpoint: "en [breakpointnumber]"
    • To ignore a breakpoint until it has been crossed x times:"ignore [breakpointnumber] [x]"
  8. Examining data When your program is stopped you can examine or set the value of any variable. To examine a variable, type "print [variablename]". To set the value of a variable, type "set [variablename]=[valuetoset]".
  9. General Tips
    • gdb has very good help files. Type "help [commandname]" while in gdb.
    • gdb also keeps lots of information about your program while it's running. Type "info" to see this information while you're in gdb.
    • if you change and recompile your program in another window, you don't need to restart gdb. Just type "run" again, and gdb will notice the changes and load the new copy of your program.
    • pressing enter executes the last command again. This makes it easily to step through your program line by line.
  10. Focus your inquiry. 
    When you debug, you can't look at everything all of the time. Be clever and focus your inquiry based on the currently incorrect behavior of your program. If a variable is being output but has the wrong value, study that variable. If a function is not being called, step through the code, study the flow of control, figure out the conditions that must be met for the function to be called, and figure out why they are not being met. If your program seems to enter an infinite loop, study the exit conditions for that loop and figure out why they are not being met. Use breakpoints to skip past parts of the code that you are not investigating.