Hey Guys, I've had this code for a while to send a 38khz signal to a proximity sensor (tsop and emitter pair). It works fine but I want to do some breadboard tests of the 328PU running on internal crystal at 8khz.
How could I edit the code to work at this lower frequency and still output 38khz.
Thanks John. I went with 0CR2A =26; and OCR2A = 13; and that seems to do it.
Another quick question. I've noticed that this modulated output ( and this is not related to my frequency request) only measures
1.3V is that typical. I don't have a lot of experience with square waves.
Hey John, no I couldn't forget, the pinmode 3 OUTPUT is stipulated in the same code I posted here. When I measure that Arduino pin 3 it reads roughly 1.3V. It still powers the emitter fine but I was thinking of adding a second emitter which is why I asked.
How did you measure that? A DMM reading may not be reliable. You need an oscilloscope to be sure what is really going on. For example is the signal a true square wave (50% duty cycle). If the duty cycle is around 25%, that might explain the voltage reading from your DMM.
As I understand it, OCR2B sets the duty cycle, and for 50% duty cycle it should be half the value of OCR2A, which you seem to be doing. But I know from experience that setting these timers up can be tricky. If some of the control register bits are not set correctly, the timer can be in a different mode than intended, and then OCR2A and OCR2B have slightly different effects. Checking the output with a scope would confirm the actual frequency, voltage and duty cycle which would tell you if the timer setup is wrong or your DMM isn't able to measure it accurately, or even if the pin is damaged or faulty.