Assembly Programming of Arduino/AVR Microcontrollers (AVRA Assembler)

Use avra assembler from source forge to generate hex file. The avra.exe windows executeable is available for download in reference “rclelectronics.blogspot.com”.

Following is the assembly code for led blink at portb pin 5, digital pin 13 on arduino.

          .device ATmega32
          .equ PORTB = 0x05     ;Port B
          .equ DDRB = 0x04      ;Data Direction Register Port B

          main:

             ldi r16,0x20         ;set port PB5 to output mode (pin5 is set for output, numbering starting at pin0)
             out DDRB,r16

             clr r17
          mainloop:
             eor r17,r16          ;invert output bit, eor=XOR operation
             out PORTB,r17        ;write to port
             call wait            ;wait some time
             rjmp mainloop        ;loop forever

          wait:
             ldi r20,0x10         ;loop 0x400000 times
             ldi r21,0x00         ;~12 million cycles
             ldi r22,0x00         ;~0.7s at 16Mhz
          w0:
             dec r22
             brne w0
             dec r21
             brne w0
             dec r20
             brne w0
             ret
  • Use the following command to upload the hex code using “avrdude.exe”. The avrdude command is installed as part of fthe arduino ide package. In fact the following command has been copied from the arduino ide. The commands being executed in arduino ide can be made visible by selecting file>preferences>”show verbose output during uploading”.

“C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude.exe” -C”C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf” -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:blink.hex:I

 

References:

http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_instruction_list.html

http://rclelectronics.blogspot.com/2014/12/blog-post.html

http://rclelectronics.blogspot.com/2014/12/avra-assembler-under-windows.html

 

Advertisements

Selection of Capacitor and Resistor Values for Twin-T Notch Filter

rc_twin_t

A notch filter, also known as band-stop filter, is used to take away a single frequency out of a signal. In instrumentation and audio circuits it used to filter out the 50/60 Hz hum due to mains power supply frequency. I fount the Twin-T notch filter to be the best. The notch frequency formula is given as 1/ 2\pi R C . Twin-T offers theoretically infinite attenuation at notch frequency due to pole-zero cancellation in transfer function with perfectly matched components.  I needed a 50Hz notch and tried to find out how close may I come close to designated frequency with off the shelf components. Programmed an excel sheet to make a table of values. I ended up using 68nF capacitor with 47k resistor to give 50Hz notch with 0.4% error. Below table shows the mantissa values of 1/ 2\pi R C with 10% tolerance components. A multiplication with proper powers of 10 would select the actual components.

Table: R-C values selection with 10% tolerance

 

10 12 15 18 22 27 33 39 47 56 68 82
10 15.915 13.263 10.610 88.419 72.343 58.946 48.229 40.809 33.863 28.421 23.405 19.409
12 13.263 11.052 88.419 73.683 60.286 49.122 40.191 34.007 28.219 23.684 19.504 16.174
15 10.610 88.419 70.736 58.946 48.229 39.298 32.153 27.206 22.575 18.947 15.603 12.939
18 88.419 73.683 58.946 49.122 40.191 32.748 26.794 22.672 18.813 15.789 13.003 10.783
22 72.343 60.286 48.229 40.191 32.883 26.794 21.922 18.550 15.392 12.918 10.639 88.223
27 58.946 49.122 39.298 32.748 26.794 21.832 17.863 15.114 12.542 10.526 86.686 71.886
33 48.229 40.191 32.153 26.794 21.922 17.863 14.615 12.366 10.261 86.123 70.925 58.816
39 40.809 34.007 27.206 22.672 18.550 15.114 12.366 10.464 86.828 72.873 60.013 49.767
47 33.863 28.219 22.575 18.813 15.392 12.542 10.261 86.828 72.048 60.469 49.798 41.296
56 28.421 23.684 18.947 15.789 12.918 10.526 86.123 72.873 60.469 50.751 41.795 34.659
68 23.405 19.504 15.603 13.003 10.639 86.686 70.925 60.013 49.798 41.795 34.419 28.543
82 19.409 16.174 12.939 10.783 88.223 71.886 58.816 49.767 41.296 34.659 28.543 23.670

The above table shows the value of 60Hz frequency with 0.02% error with component selection 39 and 68. One possibility might be 39k resistor and 68nF capacitor.