This code, when I compiled and downloaded it in Arduino IDE, didn't work, when I compiled and downloaded it through "avr-gcc objcopy avrdude", worked, who can tell me why?
#include "avr/io.h"
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include "util/delay.h"
#define OCR1_MIN 2000
#define OCR1_GAIN 2000
void setup() {
// put your setup code here, to run once:
// Setup Timer1
//TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11); //NON Inverted PWM
//TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(1<<CS10); //PRESCALER=64 MODE=14(FAST PWM)
TCCR1A = 0b10100010;
TCCR1B = 0b00011010; //PRESCALER=8 MODE=14(FAST PWM)
//ICR1=4999; //fPWM=50Hz
ICR1 = 40000;
ADCSRA = 0b11000111;
//DDRC &= 0b11111100;
DDRB = 0b00000110;
}
void write_arm_motors(float motor0, float motor1){
OCR1A = OCR1_GAIN*motor0+OCR1_MIN;
OCR1B = OCR1_GAIN*motor1+OCR1_MIN;
return;
}
float read_knob_sensor(int knob){
float reading = 0; /* Sensor reading, normalised
(i.e., scaled) to be between
zero and one. */
//DDRC &= 0b11111100;
//ADCSRA = 0b11000111;
if(knob == 1){
ADMUX = 0b01100000; // ADC on Channel 0
} else if(knob == 0){
ADMUX = 0b01100001; // ADC on Channel 1
}
int readingInter = 0;
readingInter = ADCW>>6;
reading = readingInter / 1023.0;
_delay_ms(15);
//printf("reading = %f\n", reading);
return reading;
}
int main() {
setup();
while(1){
write_arm_motors(read_knob_sensor(0),read_knob_sensor(1));
}
}