5. Problems and Errors
The CO2 sensor sends the sensor value as PWM data.
So I tried to use Input Capture Register. Timer4 is used.
When I checked it with a logic analyzer, I checked high output for about 200ms.
I thought "mu16CO2HighLevelCount" should be about 3,125 (200,000us / 64us).
However, the value measured by the serial monitor was not 100 degrees.
I want to use ICR ..... Please check if there is a wrong part.
I can not find it even if I continue to googleing.....t.t
somebody help me....t.t
i choose 1024 prescaling. (Arduino mega2560 is 16MHz)
so i thought one count in timer4(TCNT4) was equal to 64us.
the pwm waveform was measured with a logic analyzer.
It is approximately 200ms. (i want to attach image...but i don't know how....t.t)
so i thought high count(ICR4) would be displayed on the serial monitor.
because i initialized TCNT4 in risingEdge. and I read ICR4 in fallingEdge.
( 200(ms) / 64(us) = 200,000(us) / 64(us) = 3,125 = 0xC35 )
so I expected the value displayed on the serial monitor.....
12, 53
3125
but the count displayed on the serial monitor is strange....(t.t) it was as follows.
0, 251
251
ah...100 is "ICR4L" value....and now it will continue to change.
but it's displayed as 0 ~ 250
You can make a quick operational check of your CO2 sesnor based on the following strategy:
1. The cycle time of the PWM signal is known (1004 ms).
2. The ON time varies with CO2 concentration. The ON time pulse is sharply marked by a rising edge and a falling edge.
3. Connect the PWM signal with a digital pin (say, DPin-5) and with an interrupt pin (say, INT0).
4. Interrupt your MEGA by the rising edge of the PWM signal and immediately starts TC1 as Timer-1 to count 16 MHz clocking pulses from the internal oscillator.
5. After starting TC1, keep polling the logic value of DPIN-5 for LL-state. As long as LL-state is detected at DPin-5, stop TC1 and reads its counts (say, N).
6. Now, compute CO2 level from the following formula:
Cppm=2000×(TH-2ms)/(TH+TL-4ms)
TH = High level output time during cycle in ms = 625*10-7*N
If you like the above algorithm, write Arduino codes for it; test it and post it in this thread.