High Frequency GPIO toggle AVR - toggle

I have a basic AVR setup with ATmega328P and a FreeRTOS kernel running on it. I want to toggle a GPIO pin set as output at high frequency between 30kHz-60kHz. The frequency of GPIO toggle is continuously determined by other RTOS tasks and function which is between 30kHz-60kHz.
I want to ask how to toggle the GPIO at such high frequencies that are constantly changing. I am using Atmel Studio 7. Please help.

If you plan to change the frequency at about let's say every 2 pulse then software MAY be a solution. If the frequency will stay for several 10th or 100ds of pulses, PWM is definitely the good way to do.
Of course you can manage PWM frequency and period on the go. You will need to read timer/counterX with PWM part of the datasheet. If you need always 50% duty cycle, §15.7.2 is the best way to configure. If you need both duty cycle and frequency the §15.7.3 is adapted.
Cover all the possible configuration would be to broad to write here but if you start implementation and experience issues you can ask new question.

Related

Reading 4-20ma transmitter stm32 adc

I try to use 4-20 ma pressure transmitter
With stm32 internal adc
Problem reading is flacuating too much I have to take average for 128-256 reading to take stable reading
Is that normal solution or there is other way to filter data and transmitter signal ??
Many reasons can affect the reading stability. Basically grounding, PCB layout, input cables, noise on the uController supply pins, input RC filter, the ADC code...
I have a similar application using a current resistor of 162R from input connector to the same ground of the ADC input. Than a series resistor of 22k and a ceramic capacitor of 47nF to ground, placed close to the ADC pin.
With that I take 10 ADC measures and make an average. Signal is stable.
Please, share your code and circuit diagram...

Relational operator/Compare to zero in continuous mode are not continuous on fast signals. In discrete mode it works as expected

I'm trying to simulate some electronics stuff in Simulink. Current mode PWM, so I need to compare MOSFET current with constant.
I tried to use "Relational operator" and "Compare to zero" with the same result.
In Continuous simulation mode, it reacts all over the place, like +-5e-6 sec and it is no help when the PWM signal is 20e-6 sec period.
When I run it in Discrete mode on 5e-8 sec sample time it works all right.
In tutorials, all electronics simulation runs in continuous mode, and calculating blocks seem to work right but not those blocks. Are there some settings for this?
The system is based on Simscape / Electrical / Specialized Power Systems blocks
Like this example: https://www.mathworks.com/help/physmod/sps/ug/boost-converter.html

stm32 multiple channel with different sampling rate

I am working on project that which I need to employ two adc channels with different sampling rates over STM32F4x. The first channel where I need to monitor DC voltage (Vbat) with minimum sampling rate. While, the other channel I will use to pick up ECK with sampling rate about 1Khz. I have a problem with the CPU load which I am intending to solve using the DMA.
My problem is that I need only DMA for the ADC channel while the I dont it for monitoring the VBAT. How I will be able to use 2 channels of ADC with different sampling rates?
Most of the f4 UC have more than one ADC converter. Just use one for the Vbat and the second one for the high frequency monitoring.
Another option is to start injected conversion for the Vbat - what the injected conversion is - read the Reference Manual

What is the most appropriate clock/time source for software-based signal processing?

Let's say I want to sample a pair of GPIO pins of my Raspberry Pi* with a frequency around 10kHz to feed a software-based signal analyzer (written in C for instance). What is the most appropriate method to obtain an accurate timestamp for each sample? Accurate means, the delay between acqiring the sample and reading the clock/time source should be at least constant or negligible at best. The signal analyzer does not necessarily operate in realtime.
I am aware that the sampling quality may also be affected by other circumstances (e.g. preemptive mulititasking), but the question is only about acuqiring an accurate timestamp for each sample.
*) In general: any signal like a pulse wave (high/low) or an audio signal (quantized). The Raspberry Pi is only an example, since it has everything to acquire the signal already built-in.

STM 32 How to multiply PWM inputs

I'm going to make few parts of plane cockpit.
I need to use about 20 encoders, about 10 character LCDs and a lot of switches/triggers/buttons.
I think it's not a problem with LCDs and buttons, because I can use shift-registers, but I don't know what should I do with encoders (PWM signal).
I'll appreciate for any suggestions about how to use a lot of PWM inputs in one board.
It depends on the signal speed and the resolution you want. But you can sample this inputs also using SPI or GPIOs. You can them regularly using a timer and then calculate the pulse width or the encoder steps in software.
For quadrature encoders there are chips you can read out over SPI or bus interface.
Another possibility would be to use an FPGA or CPLD to preprocess the inputs.
If it's safety relevant (plane cockpit), you should take care about hardware and software architecture/design, but you know that probably.