Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4799

SDK • Re: Could use a sanity check of this code

$
0
0
I assume that measuring a fan's RPM would be fine with this method and not really needing to dive into PIO. I was looking for another project to measure the clock frequency of I2C I made a debug probe into an I2C sniffer the only feature I didn't figure out was the clock measurement I think looking in to how to do that was where I came across the PWM as a counter.
Measuring the fan RPM is exactly the sort of thing the PWM's counter mode is ideal for.

Measuring I2C clock speed is more tricky, as I2C is not normally a continuous clock - if you sit there waiting and do a 1-byte I2C transaction, you are going to count 18 clocks no matter how long you wait. You could maybe use the PWM_DIV_B_HIGH mode to count how much time the pin is high (more useful if you then use the GPIO pin override to invert the signal and it then tells you how much time the pin is low). I'd probably use PIO for an I2C analyser, or if it's something only needed occasionally, do it by polling in the CPU with interrupts disable - perhaps in the 2nd CPU core.
I think that it's too much as that project sits there isn't enough over head on the CPU it takes both cores and a PIO state machine to decode the i2c fast enough.

But now I've hit a snag in my plans. The PWM counter is work perfectly now the problem is the board I wrote the code for and the code the code is run on are just slightly different... The Fan Tach sensor is moved to GPIO 6 and that isn't compatible with PWM counting, I'm guessing this is why there was a change. Now I'm stuck how do I mimic the counter using GPIO 6 this is clearly a PIO job. I'm going to have to learn PIO coding to solve this I think.

Okay here is my thinking and I don't know if PIO can do this but it seems like it could, I just have the PIO count the pulses like the PWM would and then read and reset the count. Now I thought about this and maybe PIO can't do this effectively so maybe it could do all of it count and call the interrupt every 500 ms with the count and reset it self?

Statistics: Posted by DarkElvenAngel — Mon May 06, 2024 1:30 am



Viewing all articles
Browse latest Browse all 4799

Trending Articles