Connect with us

Generating 38khz waves of variable duty cycle.

Discussion in 'Microcontrollers, Programming and IoT' started by eptheta, Dec 31, 2010.

Scroll to continue with content
  1. eptheta

    eptheta

    188
    0
    Dec 20, 2009
    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.
     
  2. LTX71CM

    LTX71CM

    182
    0
    May 23, 2010
    Is it 38kHz or 380kHz, you mention both, twice. What language will you be using? C? ASM?
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,497
    2,839
    Jan 21, 2010
    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).
     
  4. eptheta

    eptheta

    188
    0
    Dec 20, 2009
    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.
     
  5. LTX71CM

    LTX71CM

    182
    0
    May 23, 2010
    How close to 38kHz do you need to be? Is this for an IR project?
     
  6. eptheta

    eptheta

    188
    0
    Dec 20, 2009
    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.
     
  7. eptheta

    eptheta

    188
    0
    Dec 20, 2009
    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:
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    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: Jan 2, 2011
  8. eptheta

    eptheta

    188
    0
    Dec 20, 2009
    No one ?
    Are you guys familiar with AVR microcontrollers or should I just ask at AVRfreaks?
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-