STM 32 How to multiply PWM inputs - stm32

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.

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...

How to sample a signal from a continuous time domain in to a input port digital design (Simulink to HDL integration)

I am doing Simulink based Hardware software co-simulation. I have a simulink block which is outputing fixed point 32 bit data in a continuous domain. I want to send this data to an HDL design again in fixed point 32 bit format. Whenever i integrate the two blocks together, i am getting error. I tried adding quantizer but it only works on uint/double data types which is not acceptable to the HDL block. How can I discretize the data such that it is acceptable in the RTL domain? If i add unit delay,it works but the data is delayed which is not fair
Thanks a lot for your help
To sample a continuous signal and convert it to digital electronics, you usually need an ADC: "Analog to digital converter".
You should start by googling ADC integration.

Simscape Physical Signal: Why does is exist?

What is the added value of simscape physical signals compared to normal simulink signals? As far as I can see, from a functional perspective there is no difference between the two types of signals: I can add units to both types, they both have a direction of flow, and they both have similar function blocks like adding, substracting... Only for physical signals the available types of blocks is very limited. Why didn't the matlab guys just use normal simulink lines instead of the physical signals?
Physical signals, unlike Simulink signals, have units associated with them. This means that they follow a number of rules, for example to ensure that the right unit is used (e.g. you can't add kg and m/s). From the documentation:
Using the Physical Signal Ports
The following rules apply to Physical Signal ports:
You can connect Physical Signal ports to other Physical Signal ports with regular connection lines, similar to Simulink signal
connections. These connection lines carry physical signals between
Simscape blocks.
You can connect Physical Signal ports to Simulink ports through special converter blocks. Use the Simulink-PS Converter block to
connect Simulink outports to Physical Signal inports. Use the
PS-Simulink Converter block to connect Physical Signal outports to
Simulink inports.
Physical Signals can have units associated with them. Simscape block dialogs let you specify the units along with the parameter
values, where appropriate. Use the converter blocks to associate units
with an input signal and to specify the desired output signal units.
Any sensor block in Simscape (in whatever physical domain) will output a physical signal. You can then convert it into a normal Simulink for feed to your controller. Similarly, any source block in Simscape (in whatever physical domain) will take a physical signal as input.
I suggest you just read the Simscape product page
In particular,
Simscape components represent physical elements, such as pumps, motors, and op-amps. Lines in your model that connect these components correspond to physical connections in the real system that transmit power.
Accompanying that description is the following image, which shows how Simscape models can be far more intuitive to build than a model which uses standard signal. This means models are far more maintainable and clearer to, for example, engineers who may not have a comp-sci background.
Let's delve into what a "physical connection" is somewhat.
[Simscape] employs the Physical Network approach, which differs from the standard Simulink modeling approach and is particularly suited to simulating systems that consist of real physical components.
[ ... ]
Each system is represented as consisting of functional elements that interact with each other by exchanging energy through their ports.
You stated in your question that both methods have a flow direction. This is wrong!
Simscape blocks try and balance the energy between the inlet(s) and outlet(s). For instance a fixed orifice in a fluid system may have high pressure on one side. Simscape will try and solve the pressure balance each iteration. You would need some custom Simulink subsystem to achieve this if not for Simscape.
What is the added value of simscape physical signals compared to normal simulink signals?
What is it that you think Simscape physical signals provide? Is it one number? How do you solve a mass-spring-damper system with just position? It's position AND it's speed AND it's acceleration.
I can add units to both types
No you can't. You put whatever you want in Simulink. You don't get to choose anything about what's in the physical signal in Simscape. You can specify units in the blocks that the signals connect, but you don't get to pick what the pipe itself is carrying.
they both have a direction of flow
No they don't. Your head and your torso are connected. There's no directionality to this. They're just connected. The physical signal is likewise just showing that (things) are physically connected. Again, the mass-spring-damper system: If the damper points to the mass, and the spring points to the mass, then is there any possibility that the damper could affect the spring? Yes, of course. The damper affects the spring because the damper affects the mass and the mass affects the spring.
The spring affects the mass, and the mass affects the spring. The signal is bidirectional. You're confusing signal directionality with kinematic chains.
they both have similar function blocks like adding, substracting
If you're on a train that's going 30 mph, and you're walking forward at 3 mph, how fast are you going relative to the world frame? What if you're walking backward? There is a physical meaning in adding and subtracting physical signals.
[For] physical signals the available types of [function blocks are] very limited
What is it that you're thinking they're missing? Can you also provide a description of what the physical meaning of that function block would be?
Why didn't the matlab guys just use normal simulink lines instead of the physical signals?
Because they're not the same. The biggest point is probably that Simscape is signal + derivative + second derivative, but again they're just conceptually different. Simulink is an easy way to write code - do this step, move along the arrow, do the next step, etc. Simscape is a pictorial representation of a physical system. The physical signal lines just show that things are connected. The system gets solved simultaneously.
I don't think it's mainly about the enforcement of physical signal units, nice though this is.
I think it's about the solver - and before it gets to the solver, about the choice of states and equation causality - rearranging the equations ready to be solved.
Simulink doesn't have any truck with this and just gets straight on with integrating signals as a succession of samples. I know it gets complicated with variable step solvers, but they are only doing extra fancy numerical analysis with the sampled data. Integration and the here-and-now is what it's all about!
Simscape just starts with a bucket of variables and a bucket of equations that variously depend on said variables. A 'bipartite graph', I believe they call it.
Just as we have to navigate a route through simultaneous equations to pick off the simple ones and substitute (or the matrix equivalents of this) Simscape has to do likewise in software so wants to keep alive augmented info on signals like which equations they are in and whether it knows or can easily obtain their derivatives, what they are, etc. Physical signals behave for us users just like Simulink signals, but I reckon they are there to provide the valuable service to Simscape of keeping this augmented info alive and linked between blocks so that one massive matrix equation can be formed for the whole system, not separate ones that get sampled as Simulink systems between Simulink blocks.
This rearrangement of equations ready for the more conventional solver getting stuck in is a black art indeed! We learn very little of how Simscape does it from the MathWorks docs, but you can install OpenModelica for free and see how that does it.

High Frequency GPIO toggle AVR

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.

Should Serial communication occur at standard Baud Rates?

I am interfacing an ATMega8 microcontroller to my PC using a serial to USB converter. The program I use to receive data is MATLAB. Is it strictly necessary for me to send and receive data in standard baud rates for serial communication? Would it be possible for me to send and receive in, say,208333 bps?
I'm using AVR programming at the sending end and MATLAB at the receiving end, and I'm wondering why I must use standard baud rates?
I'm using a DKU-5 cable modified to a serial converter in Windows 8.
An RS-232 serial port operates with an implicit clock. The receiver in the USB converter synchronises to the transmitters clock by identifying the middle of the start bit and then samples subsequent bits a single bit timing later. In order to sample the bits in the middle and limit the effect of jitter and timing skew (Asynchronous communication) the receiver typically samples the signal at 16 times the actual data rate. This implies that the receiver is able to produce a clock signal at this speed by dividing its oscillator by an integral number to reach the sampling rate.
The oscillators are typically chosen to allow divisors that produce standard clock speeds with low error rates, particularly at the higher speeds. Choosing a non-standard speed is likely to give to a large error from the desired speed increasing the likelihood of transmission errors.
The classic way (which may not be applicable here) is to use a synchronous link that does not require the oversampling and allows an increased speed. This is probably easiest to implement in your case by introducing a USB slave into your device. This will then support the host clocking that will be 1 Mbit/s, much faster than any asynchronous link.
A more hardware oriented site may give you better answers.