Understanding the setup

4 years 3 months ago - 4 years 3 months ago #2045 by Mireczko
Hello,
Is someone able to help me understand the ADC nad PWM setup? What are the values of chosen registers responsible for? Are there any possibilities to rewrite the code in more arduino-like way?

// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0

// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8 );
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}

Please Log in to join the conversation.

3 years 9 months ago #2118 by Boris
Replied by Boris on topic Understanding the setup
This is an elegant solution that reveals the full potential of the controller.
It’s better not to change these settings, because, in my opinion, they are very good.
Arduino functions are intended for widespread use in various tasks, they are also good, but they will be too slow for our task.

AnalogRead
Dual PWM Circuits
Timers on the ATmega168/328

Please Log in to join the conversation.

Time to create page: 0.098 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio