Monday, October 28, 2013

Atmega32ua Board


  Micro-controller Reset

As soon as power is given to micro-controller, the reset should be kept activated until all the internal peripheral of the micro-controller comes into working state.

During reset, all I/O Registers are set to their initial values, and the program starts execution
from the Reset Vector. The instruction placed at the Reset Vector must be a JMP

Types of Reset in Atmega32ua

Power-on-Reset (POR) - Power-on Reset (POR) pulse is generated by an On-chip detection circuit. A Power-on Reset circuit ensures that the device is reset from Power-on.

External Reset - An External Reset is generated by a low level on the RESET pin. Reset pulses longer than the minimum pulse width (400ns) will generate a reset, even if the clock is not running.

USB End of Reset - The MCU is reset (excluding the USB controller that remains enabled and
attached) on the detection of a USB End of Reset condition on the bus, if this feature is
enabled by the user.

Reset Circuitry

The capacitor should be kept as close to reset pin as possible. Try to avoid having other capacitor in the RESET-Ground pin. Ideal choice is 10K and 100nF. Atmel recommend a diode but is not required. Higher the capacitor, slower the speed of programing will be.

Reset switch - A switch across capacitor. This will pull the RESET pin to ground, the   capacitor will make sure to avoid any glitches in switch.


Power

VCC (pin34 and pin14) - Digital supply voltage
Multiple VCC pins are to improve dynamic current distribution inside the chip. Connect all VDD and VSS to circuit power supply. Decouple individual VCC pin by connecting 0.1uF capacitor as close as possible to VDD/VSS paire.

UVCC - USB Pads Internal Regulator Input supply voltage.

AVCC - AVCC is the supply voltage pin (input) for all the A/D Converter channels. If the ADC is not used,
it should be externally connected to VCC. If the ADC is used, it should be connected to VCC
through a low-pass filter. AVCC must not differ more than ±0.3V from VCC. The circuit to power AVCC is shown below





AVCC1 is connected to VCC through a low pass filter (ferrite bead and capacitor circuit).  Ferrite bead [3] is used to eliminate high frequency EMI noise. The same circuitry should be used for AVCC filtering on the ADC8-ADC13 side. (Ferrite bead digikey part number - MH2029-300YDKR-ND)

Reset pull-up resistor value ~ 30-60kohm (ref - 378, datasheet). Stronger external pull-up resistor might be required in noisy environment to avoid accidental reset. However, it should not be too strong if using RESET pin for programing. Typical value is to use ~10K
I/O Pin Pull-up resistors ~ 20-50kohm

Connection to USB

49ohm (or 100ohm) resistors should be used to limit the current.
3.3V diodes should be used across D+/D- and ground to limit the voltage in the line to 3.3V

* polarized capacitors (aka electrolytic capacitor)uses ionic conduction electrolytes as one of its plate to achieve high capacitance per unit area and hence have polarity. Usually aluminum is one  electron and thin layer of aluminum oxide acts as dielectric, its this very small thickness which is responsible for higher capacitance. They are usually use to eliminate AC noise from DC power source. Most electrolytic capacitors are polarized and require one of the electrodes to be positive relative to the other; they may catastrophically fail if voltage is reversed.

UCAP - USB pads internal regulator output supply voltage. Should be connected to external 1uF capacitor

used crystal - 16MHz
The device is shipped with Low Power Crystal Oscillator (8.0MHz-16MHz) enabled


ADC Power supply





ADC Reference Voltage -
ADC reference voltage can be selected as AVcc (voltage to ADC) or internal 2.56V or external voltage. If connected to fixed external voltage, the user may not use other reference voltage option in the application, as this will short the external voltage. ADC reference voltage can be made more immune to noise by connecting a capacitor (0.1uF) between AREF pin and ground.


Local decoupling Capacitors - 0.1uF as close as possible to VCC/GND pair in IC. C5 and C6

Using 100mA mas regulator to protect USB port. However, not using remaining 400mA. Other way to protect usb port from overcurrent is to use PPTC

Extra parts
16MHz resonator 


Circuit Detail

R1 (10K) and C1(0.1uF) for Reset pin. R2 (330R) to avoid high voltage at reset pin during pressing switch

L1 and C4(0.1uF) for power supply of ADC.

C3(0.1uF) to avoid high frequency noise at Vref of ADC.

C5(0.1uF) and C6(0.1uF) are local decoupling capacitors.

C7(10uF) is power supply decoupling capacitor.


LED connection: LED lights when pin is ground.


Debugging Board

1) Switch can bring the RESET pin to ground

2) Programmer can't bring the RESET pin to ground and hence get the error "Unable to enter programming mode".

Actually I set the wrong device it should be ATmega32U4


CPU clock source
The device is shipped with Low Power Crystal Oscillator (8.0MHz-16MHz) enabled and with the
fuse CKDIV8 programmed, resulting in 2.0MHz system clock with an 16 MHz crystal. So for ISP setting the maximum ISP clock frequency which is 1/4th of system clock frequency is 500Hz.


To do in next version

1) Change to microB USB connector type H11574CT-ND
2) Might not need switch for RESET pin as it can be reset from Arduino IDE
3) Change rout below USB connector
4) Order resonator(535-10008-1-ND), ferrite bead (30ohm@100MHz MH2029-300YTR-ND and 60ohm@100MHz-MH2029-600YCT-ND )and Atmega32u4
5) Update eagle 16MHz resonator part
6) Add potentiomete to one of the ADC pin.
Digikey part number - 987-1004-1-ND and SM-3TW103CT-ND
7) In the board few tracks are very thin fix it.
8) Add a SMD buzzer , 3V - 668-1207-1-ND and 668-1060-1-ND, 5V - 668-1066-1-ND
9) You can also have extra header for LCD
Diode for reset pin - CD1206-S01575CT-ND
For EDS protection - CG0603MLC-05EDKR-ND
PTC resettable fuses to protect USB port - MF-MSMF050-2CT-ND
22ohm resistors - device package - 1206, 1/4W, 1% tolurrance 311-22.0FRCT-ND
To Arduino

Install arduino IDE (and driver it will ask to install)

Connect board to PC

With avrstudio install **.hex bootloader file (usually found in arduino folder)

After burn is complete, windows should install driver for the connected arduino board.

How IDE programs the board

When you first reset the board (ie by switch or through serial port) "Arduino micro bootloader" mode kicks in stays there for 10seconds and then the sketch starts to run. Now every sketch as a "Arduino micro" USB driver as part of it. So when you reset first windows recognize it as "Arduini micro bootloader" until bootloader drivier is running after that hardware list refresh and you see "Arduino Micro" when sketch start to run.

11/21/13 11PM
Initially, I was unable to program the board from Arduino IDE. The problem was that after reset the uC was not going into the bootloader mode (some time it did, some time didn't). The reason was that there is a HWB pin in micro-controller (page 335 datasheet) when it is connected to ground, after reset first bootloader is executed followed by program execution. Fortunately, in my board this pin was close to ground wire so I just connected it without changing the board. Now, although I can not upload with USB reset done by the Arduino IDE but I can keep the reset button pressed, hit upload and when upload message appear, I release the reset button, in device manager I can see the board is now detected as "Arduino micro bootloader" and the upload completes successfully.

I burned Caterina bootloader on my chip and just found out that with this bootloader the board enters the bootloader mode only if doubled tapped. That explains why sometime I was able to enter the bootloader mode by resetting. However, when I press and hold the button during the sketch upload there was no tap so I could not upload my sketch as it was not entering bootloader mode.


Pins

Total 25pins are useful in atmega32u4 for I/O, interrupt and ADC. 

I have 19pin for general purpose use, 3 pins for ISP, 2 pin for LED + Switch and 1 pin is not currently used (I will add SMD buzzer to it).

Side area will have pins for general I/O and center area will be saved for further components

Board desing, track coming from the pins are 15mil and others are 16mil. In some critical situation 10mil tracks are used.























Reference - Datasheet
http://www.kanda.com/files/isp_circuits.pdf
http://www.atmel.com/Images/doc4284.pdf
[3] http://www.murata.com/products/emc/knowhow/pdf/23to25e.pdf

Friday, October 25, 2013

Content Managment: Mercurial Tutorial

Mercurial on Windows Using Cygwin

1) Download and Install Cygwin

Download cygwin setup file setup-x86.exe (or setup-x86_64.exe) from http://cygwin.com/install.html and run it. You should see a windows similar to the one below


follow the guideline in installation wizard until you reach the package selection window as shown below


Select the following packages: 

a) openssh under Net (click on "Default" to change it to "Install") 
b) vim under Editors and 
c) mercurial under Devel.



Follow default options and finish install (this can take a while).

2) Create ssh folder and than create a separate folder to store class archive keys (useful when working with more then one repositories)

Open cygwin terminal (Programs - Cygwin - Cygwin Terminal) and type (refer figure below- key content with classes)

mkdir ~/.ssh

Command description:  mkdir is command to create new directory. "~/' is path for home directory and "." before folder name is used to create hidden directory (to windows explorer)

Navigate to this newly created folder by typing

cd ~/.ssh

Command description:  cd stands for "change drive" and used to navigate to a particular directory.

Create contentkeys folder inside newly created ssh folder

mkdir contentkeys

and navigate to this newly created folder by typing

cd contentkeys

Now, we need to copy the keys to this folder. First download the keys to C:\ and than execute the following command

mv /cygdrive/c/classes ~/.ssh/contentkeys
mv /cygdrive/c/classes.pub ~/.ssh/contentkeys

Command description: mv stands for "move" and used to move file from one location to other. Here we are moving the file from C:\classes (in cygwin windows c drive is accessed through /cygdrive/c/classes) to newly created classkeys folder.


You can check the content of this folder by typing command

ls

Command description:  ls stands for "list" and used to display the content of a directory
 
this will display the newly moved class and class.pub keys


Now, we will change the permission of the class key file by executing the command

chmod 600 ~/.ssh/contentkeys/content




Now we will create the directory were we want to save the mercurial repository. I am first creating directory "CBA" and then directory "content" inside it.

mkdir /cygdrive/c/Users/Prashant\ Patil/CBA
mkdir /cygdrive/c/Users/Prashant\ Patil/CBA/content


 

Now, we will clone the repository from the CBA servier to our local directory by executing the command

hg clone -e "ssh -i ~/.ssh/contentkeys/content"  ssh://hg@fab.cba.mit.edu:846/content /cygdrive/c/Users/Prashant\ Patil/CBA/content


Now, navigate to your arhive folder (in my case C/Users/Prashant\ Patil/CBA/content). You will find a .hg folder in it. Open hgrc file in notepad located inside .hg folder. Copy paste following (of-course edit it with your name and email). Don't remove which is already there in the file, just append this

[ui]
username = Prashant Patil
ssh = ssh -i ~/.ssh/contentkeys/content -C

[hooks]
changegroup = hg update >&2

Save the file and close it.

Now, in terminal cd to archive directory

hg pull

hg update

hg addremove

hg commit -m "message"

hg push

If branches have diverged, you need to merge them

pull

updage

merge

addremove

commit

push

If there are multiple heads then you need to merge them to a single head

hg heads 

hg merge headnumber

hg update -c

hg commit -m message
(repeat for every head you have created)

If two branches have incompatible changes and can not be merged then, save you updated file in location other then archive.

roll your archive back so that you can manually integrate your changes with those of whomever pushed their incompatible changes before you did!... 

hg commit --close-branch -m message 
hg update -c 
hg pull 
hg update 
hg merge 
hg add . 
hg commit -m message 
hg push 
(repeat for however many extra heads you've created) 


Mercurial in Windows using TortoiseHg

TortoiseHg is a version of the Mercurial application for Windows with GUI. 

Step - 1: Download executable from here and Install it.  
Step - 2: Create a folder where you want to keep all your files.
Step - 3: If you key is generated in openSSH then you need to first convert into putty (TortoiseHg) compatible key. For that you can use the software called Puttygen that can be downloaded from here
Step - 4: Now you  need to specify ssh keys. For that we are going to you a software called "Pageant". Navigate to C:\Program Files\TortoiseHg and double click on Pageant.exe . It will start running and you can find it in system tray in task bar.  Right click on system tray and click on "Add key" and add the converted ssh key.
Step - 5: Go to File -> Clone Repository. Enter Source "ssh://hg@fab.xxxx" and destination as one of the local directory in your computer.

 
Note - If you are asked for password then your ssh keys are not properly set. 

Step - 6: Edit configuration file - Go to file File -> Settings and select repository setting tab and click on "Edit File" and append following 

[ui]
username = Prashant Patil

[hooks]
changegroup = hg update >&2