atmega

Unexpected float behaviour in C with AVR atmega8

↘锁芯ラ 提交于 2019-12-10 15:44:17
问题 I've been trying to figure out why I cannot get a sensible value from multiplying an unsigned int with a float value. Doing something like 65535*0.1 works as expected but multiplying a float with a uint from memory creates mad values. I have a function that reads an ADC and returns an uin16_t. With this value I am printing it to a 4-digit led-display, which is working fine. Multiplying the same value with 1.0 returns something different entirely (it's too large for my display so I don't

ATMEGA32 UART Communication

别说谁变了你拦得住时间么 提交于 2019-12-08 03:50:51
问题 I am trying to do serial communication in ATMEGA32 and I have a question: In asynchronous serial communication both UBRRH and UCSRC registers have same location. I don't know which conditions that location will act as UBRRH and for which conditions, it will act as UCSRC . I need different values for each register according to the work assigned to those registers In the datasheet, they have mentioned the use of URSEL bit for selection betweem two registers but somehow I am not getting that.

ATMEGA32 UART Communication

房东的猫 提交于 2019-12-06 14:51:54
I am trying to do serial communication in ATMEGA32 and I have a question: In asynchronous serial communication both UBRRH and UCSRC registers have same location. I don't know which conditions that location will act as UBRRH and for which conditions, it will act as UCSRC . I need different values for each register according to the work assigned to those registers In the datasheet, they have mentioned the use of URSEL bit for selection betweem two registers but somehow I am not getting that. The answer is: Yes, the URSEL bit. According to the datasheet: When doing a write access of this I/O

Arduino: Lightweight compression algorithm to store data in EEPROM

心已入冬 提交于 2019-12-05 13:26:32
问题 I want to store a large amount of data onto my Arduino with a ATmega168/ATmega328 microcontroller, but unfortunately there's only 256 KB / 512 KB of EEPROM storage. My idea is to make use of an compression algorithm to strip down the size. But well, my knowledge on compression algorithms is quite low and my search for ready-to-use libraries failed. So, is there a good way to optimize the storage size? 回答1: You might have a look at the LZO algorithm, which is designed to be lightweight. I don

Using a rotary encoder with AVR Micro controller

不打扰是莪最后的温柔 提交于 2019-12-04 13:05:05
问题 I'm having trouble getting a rotary encoder to work properly with AVR micro controllers. The encoder is a mechanical ALPS encoder, and I'm using Atmega168. Clarification I have tried using an External Interrupt to listen to the pins, but it seems like it is too slow. When Pin A goes high, the interrupt procedure starts and then checks if Pin B is high. The idea is that if Pin B is high the moment Pin A went high, then it is rotating counter clock-wise. If Pin B is low, then it is rotating

Using a rotary encoder with AVR Micro controller

泄露秘密 提交于 2019-12-03 09:07:38
I'm having trouble getting a rotary encoder to work properly with AVR micro controllers. The encoder is a mechanical ALPS encoder , and I'm using Atmega168 . Clarification I have tried using an External Interrupt to listen to the pins, but it seems like it is too slow. When Pin A goes high, the interrupt procedure starts and then checks if Pin B is high. The idea is that if Pin B is high the moment Pin A went high, then it is rotating counter clock-wise. If Pin B is low, then it is rotating clock-wise. But it seems like the AVR takes too long to check Pin B, so it is always read as high. I've

How to convert byte array (containing hex values) to decimal

三世轮回 提交于 2019-12-02 23:06:10
问题 I am writing some code for an Atmel micro-controller. I am getting some data via Uart, and I store these hex values into an array. Suppose the elements of the array are: 1F, 29, and 3C. I want to have one hex number like 0x1F293C, and convert it to a decimal number. So, I want to get “2042172” at the end. The array could have n elements, so I need a general solution. Thank you. 回答1: If you have a array of characters like "0x1F293C" and want to convert it to int try this code: char

Is a logical right shift by a power of 2 faster in AVR?

我与影子孤独终老i 提交于 2019-11-29 10:23:42
I would like to know if performing a logical right shift is faster when shifting by a power of 2 For example, is myUnsigned >> 4 any faster than myUnsigned >> 3 I appreciate that everyone's first response will be to tell me that one shouldn't worry about tiny little things like this, it's using correct algorithms and collections to cut orders of magnitude that matters. I fully agree with you, but I am really trying to squeeze all I can out of an embedded chip (an ATMega328) - I just got a performance shift worthy of a 'woohoo!' by replacing a divide with a bit-shift, so I promise you that this

Testing Code for Embedded Application

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 03:32:39
Background: I am developing a largish project using at Atmel AVR atmega2560. This project contains a lot of hardware based functions (7 SPI devices, 2 I2C, 2 RS485 MODBUS ports, lots of Analogue and Digital I/O). I have developed "drivers" for all of these devices which provide the main application loop with an interface to access the required data. Question: The project I am developing will eventually have to meet SIL standards. I would like to be able to test the code and provide a good level of code coverage. However I am unable to find any information to get me started on how such a

Is a logical right shift by a power of 2 faster in AVR?

孤者浪人 提交于 2019-11-28 03:50:10
问题 I would like to know if performing a logical right shift is faster when shifting by a power of 2 For example, is myUnsigned >> 4 any faster than myUnsigned >> 3 I appreciate that everyone's first response will be to tell me that one shouldn't worry about tiny little things like this, it's using correct algorithms and collections to cut orders of magnitude that matters. I fully agree with you, but I am really trying to squeeze all I can out of an embedded chip (an ATMega328) - I just got a