microcontroller

Any Faster RMS Value Calculation in C?

廉价感情. 提交于 2019-12-04 01:16:21
问题 I am writing a software for a small 8-bit microcontroller in C. Part of the code is to read the ADC value of a current transformer (ZCT), and then calculate the RMS value. The current flowing through the ZCT is sinusoidal but it can be distorted. My code as follow: float adc_value, inst_current; float acc_load_current; // accumulator = (I1*I1 + I2*I2 + ... + In*In) double rms_current; // Calculate the real instantanous value from the ADC reading inst_current = (adc_value/1024)*2.5; // 10bit

Where can I find soft-multiply and divide algorithms?

不想你离开。 提交于 2019-12-03 23:51:46
I'm working on a micro-controller without hardware multiply and divide. I need to cook up software algorithms for these basic operations that are a nice balance of compact size and efficiency. My C compiler port will employ these algos, not the the C developers themselves. My google-fu is so far turning up mostly noise on this topic. Can anyone point me to something informative? I can use add/sub and shift instructions. Table lookup based algos might also work for me, but I'm a bit worried about cramming so much into the compiler's back-end...um, so to speak. Here's a simple multiplication

Writing a delay subroutine?

爷,独闯天下 提交于 2019-12-03 22:26:59
问题 I need to write a delay subroutine. It should delay about 1 second. It has to be for 8051 environment, DS89C430 micrcontroller ( 11.0592 MHz XTAL). How can I write this subroutine? Delay1sec: ... .... ... .... ... 回答1: To get an exact 1 second delay that also works during interrupts, you need to use a hardware timer, not a software timer. I would advise you to use one of the available on-board timers as suggested by Jerry Coffin. Here's an approach involving a built-in timer and counting

How to make a delay in assembly for avr microcontrollers?

不问归期 提交于 2019-12-03 18:10:17
问题 I am having a problem in calculating delays. I want to make a delay for 1 sec when I am using 1MHz clock speed for my atmega128 microcontroller. I use proteus for simulation and avr studio for coding in assembly for atmel microcontroller. For example this code is for 8MHz clock microcontroller Delay_15mS: ; For CLK(CPU) = 8 MHz LDI dly1, 120 ; One clock cycle; Delay1: LDI dly2, 250 ; One clock cycle Delay2: DEC dly2 ; One clock cycle NOP ; One clock cycle BRNE Delay2 ; Two clock cycles for

Free alternative to MPLAB (PIC development)

穿精又带淫゛_ 提交于 2019-12-03 16:16:20
问题 I started using MPLAB recently, but for someone that works with Eclipse and VS the IDE it's very limited. Do you know any free IDE or how to configure Ecplise or Netbeans to PIC development? Thanks all 回答1: The underlying toolchain (compiler/linker etc.) can be used from any environment including Eclipse and Visual Studio, though Eclipse is probably the more flexible in this respect. MPLAB has a feature to export a project as a makefile that can be used with GNU make, although you may rather

How can you do C++ when your embedded compiler doesn't have operator new or STL support?

三世轮回 提交于 2019-12-03 14:45:41
I am working on a group senior project for my university and I have run into a major hurdle in trying to get my code to work. The compiler that we have for our 8 bit Atmel microcontroller does not support the new or delete operators, and it does not support the C++ STL. I could program it in C, but I have to implement an A* algorithm which I have never done before. While I have tried C initially I soon realized that I never did pure C before. Trying to model objects with structs and functions is slowing me down since I am so used to the much cleaner C++ syntax. Regardless, the exact wording

How do I generate random numbers in a microcontroller efficiently?

梦想与她 提交于 2019-12-03 13:07:46
How do I generate random numbers in a microcontroller efficiently? Are there any general guidelines or a particular fast method? You can generate pseudorandom numbers by manipulation of bits by simulating a LINEAR FEEDBACK SHIFT REGISTER The question then becomes 'how many bits do you want to simulate?' Wikipedia has some information. One normally generates pseudo-random numbers and not actual random numbers, although both are possible at varying rates. There are two general categories, depending on whether the sequence will be used for cryptographic purposes. The primary distinction is

How to illustrate an interrupt-driven process?

好久不见. 提交于 2019-12-03 12:42:15
This question is related to diagraming a software process. As an electrical engineer, much of the software I do is for embedded micro-controllers. In school, we learned to illustrate our algorithm using a flowchart. However, nowadays, many of my embedded projects are heavily interrupt-driven where the main process runs some basic algorithm a variety of interrupt sources provide its stimulus. So, my question is, what are some diagramming techniques that I can use to illustrate my process such that future developers can understand what I am doing easily and get involved in development? Here are

How to set STM32 to generate standard CRC32

↘锁芯ラ 提交于 2019-12-03 12:24:06
I am trying to generate CRC with STM32L4 hardware modul. I would like to validate fatfs files so basically I have byte arrays. I am using this CRC generator . Unfortunately I cannot figure out how to set STM32L4 to generate the same result. I need CRC32 and I have configuration: hcrc.Instance = CRC; /* The default polynomial is not used. It is required to defined it in CrcHandle.Init.GeneratingPolynomial*/ hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE; /* Set the value of the polynomial */ hcrc.Init.GeneratingPolynomial = 0x4C11DB7; //hcrc.Init.GeneratingPolynomial = 0xFB3EE248;

Tic Tac Toe and Minimax - Creating an imperfect AI on a microcontroller

…衆ロ難τιáo~ 提交于 2019-12-03 11:56:08
I have created a Tic-Tac-Toe game on a microcontroller, including a perfect AI (perfect meaning that it doesn't lose). I did not use a minimax algorithm for that, just a little state machine with all possible and optimal moves. My problem now is that I wanted to implement different difficulties (Easy, Medium and Hard). The AI so far would be the hard one. So I've thought about how to do this the best way and ended up wanting to use the minimax algorithm but in a way that it calculates all the scores for all game positions so that I can also sometimes pick the second best score instead of the