顯示具有 AVR日誌 標籤的文章。 顯示所有文章
顯示具有 AVR日誌 標籤的文章。 顯示所有文章

2013年12月19日 星期四

用AVR實現 PID 控制器

用AVR實現 PID 控制器 及其應用 (Aapplications of AVR base PID controller) 
Update:2013/12/20
參考 : Matlab 2013a 外部程式語言介面 中 Video: "A new approach to embedded design for Automotive"

1. Application:
  • Magnetic Levitator (磁浮控制)
  • Motor Control (馬達控制)
  • Temperature Control  (溫控)......

2013年12月6日 星期五

IAR EWAVR-6213簡介及下載

IAR Embedded Workbench for Atmel AVR

IAR Embedded Workbench provides extensive support for devices in all AVR amilies.

安裝 IAR EWAVR-6.2.13後 debugging projec 出現 error 0x2000001c

                                                                                                       Author : 一心の流 (Alex Chung)
安裝 IAR  EWAVR- 6.2.13 後 debugging project出現 : 
  "Failed to initialize USB driver: error 0x2000001c "

問題 :
  • 已經有Debugger : USB JTAGICE MKII
  • 當安裝好EWAVR-6213, When debugging my projectt the following error appears: 
         "Failed to initialize USB driver: error 0x2000001c ",("Incorrect WinDriver version installed")

2013年12月5日 星期四

使用 IAR EWAVR-6213 編譯時出現 Error[e183]

 EWAVR-6213 Error message                                               Author : 一心の流 (Alex Chung)
Abstract :
My projects for the ATmega169P may not build properly in the latest version of IAR EWAVR6213. This may in fact be an IAR bug. But it is easy to work around.
You will see:
Linking Error[e183]: Static overlay map generation (-xo) is not supported for the A90 
Error while running Linker

2013年9月17日 星期二

C語言:如何在AVR@IAR中使用absolute address

C語言 : 如何在AVR@IAR中使用absolute address
C語言 : AVR@IAR中memory 如何分配

ABSOLUTE LOCATION
It is possible to specify the location of a variable (its absolute address)using either of the following two constructs:
1) The @ operator followed by a constant-expression.

    example: The following declaration locates PIND at address 10h

                 __no_init __io char PIND @ 0x10;

   The following declaration locates i at address 20 with the value 10:

               const int i@20=10;


2013年9月1日 星期日

配置ATmega128 ATmega169 fuse bit

keyboard: 配置 ATmega128  ATmega169 熔絲 位元 fuse bit lock bit

正確配置AVR ATmega128位元
ATmega128 lock bits  byte

AVR timer/count 的PWM功能設計要點

一、PWM脈寬調變
PWM是脈衝寬度調變的簡稱。實際上,PWM波也是一個連續的方波,但在一個週期中,其高電平和低電平的duty cycle是不同的。一個典型PWM的波形如圖所示。
在圖中,TPWM波的週期,T1是高電平的寬度,Vcc是高電平值。當該PWM波通過一個積分器後(低通濾波器)後,我們可以得到其輸出的平均電壓為:

2013年8月30日 星期五

AVR ADC clocking and sampling rate

1)ADC clockrate, sample per second(sps)
  ADC clock= xtal freq.(osc freq.)/division factor

 ADC Prescaler selection 
 ADPS2
ADPS1 
ADPS0 
Division Factor 
0
0
0
0
0
1
0
1
0
0
1
1
1
0
0
16 
1
0
1
32 
1
1
0
64 
1
1
1
128 
example:
 XATL =8Mhz,  division factor=128,    normal conversion = 13 cycles
 ADC clock = 8Mhz /128 = 62500hz = 62.5Khz ==>  T =16us
 sample per second(sps) = ADC clock/13 = 62500hz/13 = 4807.692hz  ==> T=208us

ADC of ATmegaXXX of AVR

THEORY OF OPERATION:

7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 
ADMUXREFS1REFS0 ADLAR MUX3 MUX2 MUX1 MUX0 
ADC Multiplexer Selection Register


 REFS1REFS0 Voltage Reference Selection 
 0AREF, Internal Vref turned off 
 0AVcc with external capacitor on AREF pin 
 1Reserved 
 1Internal 1.1V (ATmega168/328) or  2.56V on (ATmega8)
REF Bits

2012年9月25日 星期二

AVR 教科書

Keyword : 用BAsic 語言 撰寫 AVR 晶片 程式

紐西蘭高職 教師編AVR 教科書(free download)

This is a textbook that I have written to support my high school students learning using the AVR for their technology projects. We have 300 students who learn to program the AVR and some do neat things.
The book is no charge, its almost 1000 pages of learning.
It starts with Bascom and does some C and C++
(I am interested in any C++ gurus feedback on what I have written)

The complementary software I have written is also free.
And there are a lot of students projects on my website as well.

Bill
Auckland
New Zealand
download: www.techideas.co.nz

2012年8月19日 星期日

AtmegaXXX系列 I/O port 位元操作

1)AtmegaXXX I/o port中不能用  PINA.0 or PORTA.2 這樣的定址法操作

2)在IAR C  compiler 中改用如下方式:

  * An example showing the SFR_B() macro call, the expanded result and usage of this result:
  *
  * SFR_B_R(0x1F,   AVR) Expands to:
   __io union {
              unsigned char AVR;                 // The sfrb as 1 byte
              struct {                                         // The sfrb as 8 bits
                      unsigned char AVR_Bit0:1,
                                    AVR_Bit1:1,
                                    AVR_Bit2:1,
                                    AVR_Bit3:1,
                                    AVR_Bit4:1,
                                    AVR_Bit5:1,
                                    AVR_Bit6:1,
                                    AVR_Bit7:1;
                     };
             } @ 0x1F;
  Examples of how to use the expanded result:
 a) 用   AVR |= (1<<5);           //設定AVR暫存器bit5=1  b)用   AVR_Bit5 = 1;             //設定AVR暫存器bit5=1 

2012年8月17日 星期五

I2c 通信中發生外部中斷

Q)What will happened if there occur external interrupt while communicating through I2C interface.?

Answer1)depends if you have a software I2C interface or if you use the TWI perihperal as I2C interface. the last will only be affected at the moment it needs to be serviced by interrupt.

Answer2)You should never miss an interrupt ( INT0 or other ) whatever you are doing. The processor sets a flag bit to say that an IRQ has occurred.

ATmega128 串列通信介面 source code

keyword : ATmega128 I2C  (TWI )  SM_bus 2-wire  SPI  UART  interface

1)  source codes  for ATmega128 UART

UARTM128.H
/* Prototypes */
void InitUART0( unsigned char baudrateL,unsigned char baudrateH );
unsigned char ReceiveByte0( void );
void TransmitByte0( unsigned char data );

void InitUART1( unsigned char baudrateL,unsigned char baudrateH );
unsigned char ReceiveByte1( void );
void TransmitByte1( unsigned char data );
 ...

2012年3月14日 星期三

rp-usb-connector

rp-usb-connector
http://code.google.com/p/rp-usb-connector/

[中文版本在本页下方:]

RoboPeak USB Connector is a driverless USB ISP programmer for AVR/C51 MCU. It is developed by RoboPeak team).

RoboPeak USB Connector is based on the work of AVR-Doper project (http://www.obdev.at/products/vusb/avrdoper.html), which is a STK500 compatible In-System Programmer (ISP) and High Voltage Serial Programmer (HVSP).

USB programmer for Atmel AVR controllers

USBasp - USB programmer for Atmel AVR controllers

USBasp is a USB in-circuit programmer for Atmel AVR controllers. It simply consists of an ATMega88 or an ATMega8 and a couple of passive components. The programmer uses a firmware-only USB driver, no special USB controller is needed.

Features

  • Works under multiple platforms. Linux, Mac OS X and Windows are tested.
  • No special controllers or smd components are needed.
  • Programming speed is up to 5kBytes/sec.
  • SCK option to support targets with low clock speed (< 1,5MHz).
  • Planned: serial interface to target (e.g. for debugging).

2011年9月23日 星期五

Lanconelli Open Systems

http://www.lancos.com/index.html

You'll find here several interesting projects related to electronics, embedded systems and programming. PonyProg, the most popular eeprom programmer on the Internet. CARACA, the free home automation system based on CANBus. WebTherm, a simple on-line thermometer. MiniThreads, how to do multitasking even with very small microcontrollers like AVR AT90S1200.

Home
   Who am I?
   Projects
     PonyProg
     CARACA
     WebTherm
     MiniThreads
     FPGA

2011年8月18日 星期四

Porting from IAR to AVR-GCC (WinAVR)...

A few tips on porting code from IAR to AVR-GCC (WinAVR)...

1)REGISTER/MEMORY LOCATIONS have aliases in the IAR .h file, sometimes have unidentical entries in the avr-gcc files (Often, avr-gcc are the correct ones wrt the datasheet). Such entries must be edited in the source code to match avr-gcc names.

Also, .h files are not called explicitly when using WinAVR, you just use a general call, and the makefile generator takes care of calling the proper .h file.

2011年8月17日 星期三

avr-gcc之section與relocation

      粗略的講,一個段代表一無縫隙的資料塊(位址範圍),一個段裏存儲的資料都為同一性質,如“唯讀”數據。as (彙編器)在編譯局部程式時總假設從0 位址開始,並生成目標檔。最後ld(鏈結器)在連接多個目標檔時為每一個段分配運行時(run-time)統一位址。這雖然是個簡單的解釋,卻足以說明我們為為什麼用段.

     ld 將這些資料塊正確移動到它們運行時的位址。此過程非常嚴格,資料的內部順序與長度均不能發生變化.這樣的資料單元叫做段,為段分配運行時位址叫再定位,此任務根據目標檔內的參考位址將段資料調整到運行時位址。

Avr-gcc 中彙編器生成的目標檔(object-file)至少包含四個段,分別為: .text 段、.data段、 .bss 段和.eeprom 段,它們包括了程式記憶體(FLASH)代碼,內部RAM 資料,和EEPROM 記憶體內的資料。這些段的大小決定了程式記憶體(FLASH)、資料記憶體(RAM)、EEPROM 記憶體的使用量,關係如下: 

程式記憶體(FLASH)使用量 = .text + .data

資料記憶體(RAM)使用量 = .data + .bss [+ .noinit] + stack [+ heap]

EEPROM 記憶體使用量 = .eeprom

2011年8月16日 星期二

WinAVR SRAM常數與FLASH區常數的定義與讀取

定義SRAM區常量與變數的定義基本相同,在前面加上const
const uint_t s_val = 0x01;

Falsh
區的整數變數的定義如下: 資料類型  變數名 PROGMEM = 
由於FLASH的變數是不能改變的,因此最好在定義時加上const,其實FLASH區變數應叫FALSH區常量可能更合適, 我喜歡叫FLASH常數.
const uint8_t f_val PROGMEM  = 0x01;
應用(讀取)方面,SRAM常量直接使用即可: : PORTB = s_val;

2011年8月14日 星期日

Porting from GCC to IAR

問題1:
Header file有說明了,為什麼說我沒有定義呢?真的鬱悶!在GCC下compile可以,為何出現identifier is undefined error?

void USART_Init(void)
{
UCSR 0C =(1<<< span>; //非同步操作,8位元資料,無奇偶校驗位,一個停止位
UBRR 0L = (F_CPU / BAUDRATE / 16 - 1) % 256;//設置串列傳輸速率
UBRR0H = (F_CPU / BAUDRATE / 16 - 1) / 256;
UCSR0B = (1<<<< span); //使能接收中斷,使能接收,使能發送
}

Error[Pe020]: identifier "UCSZ01" is undefined F:\AVR\main.c 32
Error[Pe020]: identifier "UCSZ00" is undefined F:\AVR\main.c 32
Error[Pe020]: identifier "RXCIE0" is undefined F:\AVR\main.c 36
Error[Pe020]: identifier "RXEN0" is undefined F:\AVR\main.c 36
Error[Pe020]: identifier "TXEN0" is undefined F:\AVR\main.c 36
Error[Pe020]: identifier "UDRE0" is undefined F:\AVR\main.c 44
Error[Pe020]: identifier "RXC0" is undefined F:\AVR\main.c 52
原因: