embedded

Is there any alternative to using % (modulus) in C/C++?

一笑奈何 提交于 2019-12-17 07:12:09
问题 I read somewhere once that the modulus operator is inefficient on small embedded devices like 8 bit micro-controllers that do not have integer division instruction. Perhaps someone can confirm this but I thought the difference is 5-10 time slower than with an integer division operation. Is there another way to do this other than keeping a counter variable and manually overflowing to 0 at the mod point? const int FIZZ = 6; for(int x = 0; x < MAXCOUNT; x++) { if(!(x % FIZZ)) print("Fizz\n"); //

How do you implement a class in C? [closed]

余生长醉 提交于 2019-12-17 06:19:50
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . Assuming I have to use C (no C++ or object oriented compilers) and I don't have dynamic memory allocation, what are some techniques I can use to implement a class, or a good approximation of a class? Is it always a good idea to isolate the "class" to a separate file? Assume that

Difference between const & const volatile

我怕爱的太早我们不能终老 提交于 2019-12-17 03:24:08
问题 If we declare a variable as volatile every time the fresh value is updated If we declare a variable as const then the value of that variable will not be changed Then const volatile int temp; What is the use of declaring the variable temp as above? What happens if we declare as const int temp ? 回答1: An object marked as const volatile will not be permitted to be changed by the code (an error will be raised due to the const qualifier) - at least through that particular name/pointer. The volatile

Send a structure using UART [closed]

*爱你&永不变心* 提交于 2019-12-14 04:14:49
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I have a two boards: - Master board (M board) - Slave board (S board) M board shall send a request to S board and the latter shall answer. The answer of the slave is a struct: typedef struct{ uint8_t userID; uint8_t userPass; uint16_t userData; }UserTypeDef; UserTypeDef User;

How to prevent LDM/STM instructions expansion in ARM Compiler 5 armcc inline assembler?

非 Y 不嫁゛ 提交于 2019-12-14 03:54:05
问题 I'm trying to generate AXI bus burst accesses using STM/LDM instructions in inline assembly in .c file compiled with ARM Compiler 5 armcc. inline void STMIA2(uint32_t addr, uint32_t w0, uint32_t w1) { __asm { STMIA addr!, { w0, w1 } } } But ARM Compiler armcc User Guide, paragraph 7.18 is saying: "All LDM and STM instructions are expanded into a sequence of LDR and STR instructions with equivalent effect. However, the compiler might subsequently recombine the separate instructions into an LDM

Organizing static data in C++

烈酒焚心 提交于 2019-12-14 03:52:31
问题 I'm working on some embedded software where there is some static information about "products". Since the information for a certain product never changes during execution I would like to initialize these data structures at compile time to save some space on the stack/heap. I made a Product class for the data, intending to make a huge array of all the products in the system and then do lookups in this structure, but I haven't figured out quite how to get it working. The arrays are giving me

Looking to write electrical engineering related open software [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-14 03:47:59
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I apologize if this question is a little broad. Hopefully your answers will help me narrow it down to more meaningful questions. I'm experienced in software engineering and had a recent conversation with a friend who suggested that electrical engineering is very software driven

How does one properly deserialize a byte array back into an object in C++?

人盡茶涼 提交于 2019-12-14 03:21:48
问题 My team has been having this issue for a few weeks now, and we're a bit stumped. Kindness and knowledge would be gracefully received! Working with an embedded system, we are attempting to serialize an object, send it through a Linux socket, receive it in another process, and deserialize it back into the original object. We have the following deserialization function: /*! Takes a byte array and populates the object's data members */ std::shared_ptr<Foo> Foo::unmarshal(uint8_t *serialized,

How do I separate digits from a double and store them as an int in C?

谁都会走 提交于 2019-12-14 03:13:43
问题 Say I have a double as follows: double aDouble = 15.6; and I want to convert it to three int's as follows: int x = 1; int y = 5; int z = 6; How would I go about doing this? 回答1: double aDouble = 15.6; int tmp = aDouble*10; int x, y, z; x = tmp/100; tmp -= x * 100; y = tmp/10; tmp -= y * 10; z = tmp; 回答2: Since this looks like homework, I will give you 2 clues. 15.6 = 1 * 10 + 5 * 1 + 6 * 0.1 casting from a double to an int trucates the double. You should be able to work out the rest. 来源:

PID feedback & Position Controller with DC motor/encoder

放肆的年华 提交于 2019-12-14 02:03:07
问题 I'm having a hard time getting both PID feedback and positioning to run at the same time. My thought to calculate the RPM is to: start a timer and count encoder pulses using an interrupt. use some simple math to convert to RPM. reset variables used and start over. I can calculate RPM but then I can only call my PID controller after the calculation (however long I want to wait to get good resolution.) This results in very messy code. Is there a simpler method or something I'm missing? Info