Giter Site home page Giter Site logo

avr_tinytune's People

Contributors

blakelivingston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

avr_tinytune's Issues

Non-PLL AVR support.

Hi there,

I just stumbled upon this project and found it quite interesting.
I'd like to port it to the ATMega8 and higher, of which do not have the built-in PLL for fast PWM and a different configuration of timers.
I'm only new to AVRs, but have been thoroughly reading datasheets all day.
I've got an ATMega8 and to try and get it working with this code I've modified the timer related code in tinytune.c as follows:

Sample interrupt now comes from Timer1 (16 bit timer on ATMega) @ F_CPU/8/SAMPLE_CLOCK_DIVIDER = SAMPLE_RATE?
I changed to the appropriate interrupt vector (TIMER1_OVF_vect) and can see some activity on PORTB[0:1] as should be in the interrupt code, so I /assume/ it's doing the right thing.

void initSampleInterrupt(void) {
  /* OLD CODE
  // Clock : Sys/8 (2mhz)
  // Fast PWM mode (|WGM0-2)
  TCCR0A = (1 << WGM00) | (1 << WGM01);
  TCCR0B = (1 << CS01) | (1 << WGM02);
  // Enable interrupt on overflow.
  TIMSK |= (1 << TOIE0);
  // In fast PWM mode, the timer overflows at OCR0A
  // Our timer / OCR0A = SAMPLE RATE
  // Do make sure this is under 255..
  OCR0A = SAMPLE_CLOCK_DIVIDER;
  sei();
  // Enable interrupts
  */

  TIMSK |= (1 << TOIE1);
  // fast pwm ( WGM13, 12, 11,10) for TOP controlled by OCR1A
  TCCR1B |= (1 << WGM12 ) | (1 << WGM13);
  TCCR1A |= (1 << WGM10) | (1 << WGM11);
  TCCR1B |= (1 << CS11); // CS11 for /8 divider
  OCR1A = SAMPLE_CLOCK_DIVIDER;
  sei();
}

The next change I made was to get 8-pwm going as fast as I can out of the other timer that supports it on the ATMega (Timer2) using the following code:

This should set up 8-bit PWM at a frequency of F_CPU / (prescale * 256).

void initPWMB(void) {
  /*TCCR1 = (1 << CS10); // Run at PCK/1
  GTCCR = (1 << PWM1B) | (1 << COM1B0); //Enable PWMB (pb4)
  DDRB |= (1 << PB4) | (1 << PB0) | (1 << PB1); // Output on pb4
  OCR1C = 0xff; */

  // set up timer 2 - this will be the output PWM
  TCCR2 |= ((1 << WGM21) | (1 << WGM20)); // Fast-PWM (p.115)
  TCCR2 |= (1 << COM21); // non-inverting OC2 pin output (p115)
  TCCR2 &= ~(1 << COM20);
  TCCR2 |= (1 << CS10); // prescale 1x
  OCR2 = 0;
}

I've also changed the first line of the interrupt routine to change the PWM duty cycle:
OCR2 = sample_buffer[sample_buf_clock++];

Everything should be in order, but alas, I get no sound.
I've tried a basic test sine table using the same timers and that seems to work fine, but here I get dead silence.

Would you happen to have some extra knowledge on how this code would be best ported to the ATMega hardware (looks like there's a hardware multiply instruction) or anything on minimum timings (perhaps an interrupt is being overflowed)? I've tried running from the internal 8 MHz RC as well as an external 16 MHz crystal as well lowering the sample rate.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.