Is NodeMCU's PWM limited to one frequency? - nodemcu

In the NodeMCU doc, it appears PWM on a pin may be set one of two ways, either through PWM or GPIO.
In the PWM doc it says that if you set PWM on one pin for a certain frequency then that frequency is set for all other pins using PWM. This means that you don't have RGB but rather 50 shades of grey.
The GPIO section does not mention this limitation. Is it on place? Is there only one timer on the chip itself available for PWM?

You seem to be confusing the effects of Frequency and Duty cycle on an RGB led, you will have 3 pins connected on which you generate a PWM, where you can set the duty cycle to change the intensity, whether all those frequencies are the same or not doesn't matter.

Related

Microprocessor Generation of Summed Sine Waves with Random LF Modulation

I would like to program a micro to do the following:
Generate five audio frequency sine waves at different frequencies and amplitudes
Sum the above sine waves into one signal
Generate a pseudo-random low frequency waveform at a set amplitude
Multiply the two signals above so that the summation of the five signals randomly changes in amplitude and frequency.
What would be the recommended approach to this in terms of chosen micro (prefer PIC if possible) and design of the code? I am asking for general advice on how to get started with this project.

PIC24F issues reading analog AC microphone values

I am using a PIC24FJ128GA010 to read the microphone values. When I read the raw values from the sensor I am getting like 270 but over time the value will go down to 90 and stop. 3.3V is being used and when noise is made the values will change even when its slowly going down to 90. I am not sure why this is the case. I just have 3.3V, ground and an analog input pin connected to the microphone. The microphone I believe picks up noise from -1.7V to 1.7V.
I am setting AD1CON2 = 0x0000; where AVss and AVdd is used as Vref.
Is there a way I can fix the readings from the microphone to display 90 right away? I know that 90 represents 0 and probably will need to fix that so the values would be read just on the positive side. Would using a capacitor help fix this issue?
I am very new to programming microcontrollers and would appreciate any help.

Keep ESP32 non-RTC GPIO pin state HIGH in deep sleep

I'm using Arduino IDE, and I'm trying to keep a pin's state held (HIGH, in my case).
I have GPIO16, GPIO17, GPIO18 (which I believe are all non-RTC GPIO pins). They're connected to three P-channel MOSFETs, which power an RGB LED. So my three pins need to be held HIGH while sleeping.
When my ESP32 goes into deep sleep, the RGB LED slowly fades up to full white brightness 😅
After searching around, the method posted elsewhere doesn't work as expected. I've tried the below, but no luck.
Arduino IDE:
gpio_hold_en((gpio_num_t) 16);
gpio_hold_en((gpio_num_t) 17);
gpio_hold_en((gpio_num_t) 18);
gpio_deep_sleep_hold_en();
delay(10000);
esp_deep_sleep_start();
Strangely though, now the blue LED (on GPIO 18) doesn't come on, just the other two (16 and 17) snap to full brightness as soon as I call deep sleep.
Does it matter that they're GPIO vs RTC GPIO?
Is it possible to hold them HIGH during deep sleep? I've also tried INPUT_PULLUP but no luck either.
They're SMD soldered on custom PCBs so I'm trying to solve this in software, before I consider swapping for N-Channel MOSFETs or just making new boards entirely.

how to control servo motor using embedded c using simple code?

i'm working on a school project "automatic railway system"
my project suppose to close the gate when the train coming to the station with a buzzer on with 90 sec count down display on 7-seg. and a led flashing.
after the train leaving the station, the gate opens and the buzzer off and the led off .
i tried to use a dc motor to open and close the gate but it didn't give me the accurate angle that i need to i try to use a servo motor .
so i need it to open the gate at position zero and close it at position 90 .
all the code i found on the internet they using PWM and timers which i didn't take it in my course , so can anyone help me to do this with simple code ,please ?
i'm using Atmega32 running at 16000000 HZ
Its depend on your analog servo (which is controlled by PWM) frequency specification. After you learn about the servo specification, you can set your PWM using build-in features on cvavr compiler, or you can do some research about PWM registers.
Here is some example of PWM setup
//using OC0 (B.3)
DDRB.3 = 1; //set B.3 as output
TCCR0=0b0111 0001;
TCNT0=0; //set to Phase Correct PWM mode, no prescaler, and inverted output
//to assign a value to your PWM
OCR0 = 127 //50% duty cycle since it was 8 bit

Using a particle filter with multiple sensors with different sampling rates

Current situation:
I have implemented a particle filter for an indoor localisation system. It uses fingerprints of the magnetic field. The implementation of the particle filter is pretty straight forward:
I create all particles uniformly distributed over the entire area
Each particle gets a velocity (gaussian distributed with the mean of a 'normal' walk speed) and a direction (uniformly distributed in all directions)
Change velocity and direction (both gaussian distributed)
Move all particles in the given direction by velocity multiplied by the time difference of the last and the current measurement
Find the closest fingerprint of each particle
Calculate the new weight of each particle by comparing the closest fingerprint and the given measurement
Normalize
Resample
Repeat #3 to #9 for every measurement
The problem:
Now I would like to do basically the same but add another sensor to the system (namely WiFi measurements). If the measurements would appear at the same time there wouldn't be a problem. Then I would just calculate the probability for the first sensor and multiply this by the probability of the second sensor to get my weight for the particle at #6.
But the magnetic field sensor has a very high sample rate (about 100 Hz) and the WiFi measurement appears roughly every second.
I don't know what would be the best way to handle the problem.
Possible solutions:
I could throw away (or average) all the magnetic field measurements till a WiFi measurement appears and use the last magnetic field measurement (or the average) and the WiFi signal together. So basically I reduce the sample rate of the magentic field sensor to the rate of the WiFi sensor
For every magnetic field measurement I use the last seen WiFi measurement
I use the sensors separated. That means if I get a measurement of one sensor I do all the steps #3 to #9 without using any measurement data of the other sensor
Any other solution I haven't thought about ;)
I'm not sure which would be the best solution. All the solutions dont seem to be good.
With #1 I would say I'm loosing information. Although I'm not sure if it makes sense to use a sample rate of about 100 Hz for a particle filter.
At #2 I have to assume that the WiFi signal doesn't chance quickly which I can't prove.
If I use the sensors separately the magnetic field measurements become more important than the WiFi measurements since all the steps will have happened 100 times with the magnetic data till one WiFi measurement appears.
Do you know a good paper which is dealing with this problem?
Is there already a standard solution how to handle multiple sensors with different sample sizes in a particle filter?
Does a sample size of 100 Hz make sense? Or what would be a proper time difference for one step of the particle filter?
Thank you very much for any kind of hint or solution :)
In #2 instead of using sample-and-hold you could delay the filter by 1s and interpolate between WiFi-measurements in order to up-sample so you have both signals at 100Hz.
If you know more about the WiFi behavior you could use something more advanced than linear interpolation to model the Wifi behavior between updates. These folks use a more advanced asynchronous hold to up-sample the slower sensor signal but something like a Kalman filter might also work.
With regards to update speed I think 100Hz sounds high for your application (assuming you are doing positioning of a human walking indoors) since you are likely to take a lot of noise into account, lowering the sampling frequency is a cheap way to filter out high-frequency noise.

Resources