Ai-Thinker-Open / GPRS_C_SDK

Ai-Thinker A9/A9G GPRS (with GPS(A9G)) module C development SDK
https://ai-thinker-open.github.io/GPRS_C_SDK_DOC
MIT License
447 stars 233 forks source link

Does A9G support PWM for led fading ? #211

Open TridentTD opened 5 years ago

TridentTD commented 5 years ago

Is there any example for led fading ?

Thank you.

gsmwhatnot commented 5 years ago

There is no PWM pin on A9/A9G module but PWM in nature is nothing but a GPIO pin which goes HIGH/LOW very fast in order to control output voltage. There is OS_SleepUs (sleep in microseconds ) function which you can use in order to mimic PWM behavior.

I don't know what is the GPIO voltage of A9 but let's say it's 1.8v so in 1000 microseconds if GPIO goes HIGH for 500 microsecond and goes LOW for another 500 microsecond the voltage reading should be 0.9v ( with ordinary multimeter of-course ) and if it goes 200 microsecond HIGH and 800 microsecond LOW the it should produce 0.36v and so on ...

PS: 1) This is not a proper PWM approach because PWM cycling frequency is much higher ( +100kHz ) but this should be enough for our eyes to "FEEL" that LED is fading.

2) You should make this function to work parallel with your main code ( I call it pseudo-multi-thread ) otherwise your main code will loop inside PWM indefinitely.

TridentTD commented 5 years ago

Is there any timer interrupt for creating pin-output higher frequency in A9G ?

gsmwhatnot commented 5 years ago

I haven't dove into that area yet, I think you should wait for a proper response from Neutree. Meanwhile you can test to see whether my suggestion works or not, it would be nice to have feedback in here as well.