Maker Pro
Maker Pro

Generating 38khz waves of variable duty cycle.

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
I am using an Atmega32 and want to generate 38khz waves with a programmable duty cycle.

My idea was to generate 380khz waves and then have a counter going from 1 to 10, and dividing it accordingly to get the appropriate duty cycle.
Now I can easily generate 38khz waves using timers, but...

I am afraid of using external crystals because I don't know how to configure those fuse bits. The in-built 1Mhz oscillator cannot produce 380khz accurately.

Is there any other way of either getting 38khz waves of a 10% duty cycle or getting 380khz without using external crystals ?

Thank you.
 

LTX71CM

May 23, 2010
182
Joined
May 23, 2010
Messages
182
Is it 38kHz or 380kHz, you mention both, twice. What language will you be using? C? ASM?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Have you googled "atmega32 PWM output"?

I have no idea if it can do PWM at 38kHz, but I'd be pursuing this track first (you don't say whether or not you've investigated this).
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
Sorry if I made this a little confusing.

-I want a 38khz wave with a variable duty cycle.
For this, I though i would generate a 380khz wave and keep it on for 5 cycles and off for 5 cycles, thus giving a 38khz waveform.(because I divide it by 10 every time--and this allows variable duty cycles)

-And I'll be using WinAVR in c.

-I did research on PWMs. It seems the only way to get 38khz PWM is to use a 16Mhz crystal(which I was trying to avoid), so i posted here hoping to find an alternative...

I think I'll just try and figure out how to get those fuse bits working...
If there is any other way to work around this sticking with my 1MHZ internal oscillator, please do tell me.

Thank you.
 

LTX71CM

May 23, 2010
182
Joined
May 23, 2010
Messages
182
How close to 38kHz do you need to be? Is this for an IR project?
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
Yeah, but the datasheet for the receiver chip says nothing about frequency range. It was built for 38khz and there are models for 35khz and 40khz so it may be pretty specific.

I have only tested it with 38khz (I made a remote control months ago using 555s which worked fine--IR transmitter and receiver)
But knowing RC oscillators, the 38khz couldn't have been very accurate.
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
I am afraid.
If I have a 16Mhz crystal and two 22pf capacitors connected as they are supposed to be on an Atmega32, what fuse bits should I set ?
The datasheet confused me a bit. This is what I got:
62374898.jpg

53629689.jpg

53792471.jpg

24963415.jpg


So from what I can understand:
CKSEL3-->CKSEL0 has to be 1111 to 1010
H:xxxxxxxx
L:xxxxyyyy (where yyyy is 1111 to 1010)

Table 5 just has start up times, it seems its easiest to just pick the lowest startup time unless you really need it otherwise.
So SUT1,SUT0 is now 11.
H:xxxxxxxx
L:xx11yyy1

I can't find anything else specific so should I just leave the rest default ?
So: H:10011001
L:11111111

H:0x99
L:0xFF

So my avrdude command is:
avrdude -c program -p m32 -P bsd -U lfuse:w:0xFF:m -U hfuse:w:0x99:m

Please correct me If i am wrong. I am using the BSD programmer(directly to my parallel port---bit-bashing). I don't want to put a chip into a coma.

Thank you.
 
Last edited:

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
No one ?
Are you guys familiar with AVR microcontrollers or should I just ask at AVRfreaks?
 
Top