Hello,
i have question regarding PWM reading. I know, there are so many examples and documentations in the web but i have something special.
Ok, for me it sounds special
I have a PWM Signal which is controlled in 200KHz but by ground.
How should i do that when i want to read the pwm value which will be set to gnd?
I have a teensy 3.2 and connect the GND to Pin 2. (Or do i need a resistor to prevent a short circuit when PIN is HIGH and will be connected to GND by PWM?)
Do i have to set the Pin 2 to HIGH(INPUT_PULLIP) and read the time of the falling edge?
Is that the correct way?
I did not complete the wiring for testing, and i still need to understand a lot of the PWM but if i know the frequency of 200KHz, how do i output the value from 0% to 100%?
Add a timer, count the values in one second and map it?
Then i just know the value every second, is there a way to have it faster?
Thanks a lot, for the most here the questions may sound stupid but for me PWM is new.
Regards
Thomas
i have question regarding PWM reading. I know, there are so many examples and documentations in the web but i have something special.
Ok, for me it sounds special
I have a PWM Signal which is controlled in 200KHz but by ground.
How should i do that when i want to read the pwm value which will be set to gnd?
I have a teensy 3.2 and connect the GND to Pin 2. (Or do i need a resistor to prevent a short circuit when PIN is HIGH and will be connected to GND by PWM?)
Do i have to set the Pin 2 to HIGH(INPUT_PULLIP) and read the time of the falling edge?
Is that the correct way?
Code:
volatile int pwm_value = 0;
volatile int prev_time = 0;
void setup() {
Serial.begin(115200);
pinMode(2,INPUT_PULLUP);
attachInterrupt(2, falling, FALLING);
}
void loop() { }
void rising() {
attachInterrupt(2, rising, RISING);
prev_time = micros();
}
void falling() {
attachInterrupt(0, falling, FALLING);
pwm_value = micros()-prev_time;
Serial.println(pwm_value);
}
I did not complete the wiring for testing, and i still need to understand a lot of the PWM but if i know the frequency of 200KHz, how do i output the value from 0% to 100%?
Add a timer, count the values in one second and map it?
Then i just know the value every second, is there a way to have it faster?
Thanks a lot, for the most here the questions may sound stupid but for me PWM is new.
Regards
Thomas