China
Offline
Jr. Member
Karma: 0
Posts: 60
I love Arduino
|
 |
« on: September 10, 2006, 07:42:14 am » |
Hi ! "ATmega8/168 AI" have two more AD pin(AD6 & AD7) , Arduino use "ATmega8 PI" , so only have 6 AD pin(0-5) .
Now I see "Arduino Mini" use "ATmega168 AI" ,and have the AD6 & AD7 , I want to make sure that could I use " analogRead(6) ;" to use AD6 ?
thank you !
|
|
|
|
|
Logged
|
|
|
|
|
berlin
Offline
Sr. Member
Karma: 0
Posts: 293
|
 |
« Reply #1 on: September 16, 2006, 03:50:07 am » |
it didn't work for me. i have an arduino mini from ars electronica. with arduino005 only 5 analog inputs work (AD0 -AD4). can anyone confirm this?
is this a software or hardware thing?
//kuk
edit: i was wrong. six inputs work. but AD6 und AD7 don't.
|
|
|
|
« Last Edit: September 16, 2006, 04:12:04 am by leKuk »
|
Logged
|
|
|
|
|
Forum Administrator
Cambridge, MA
Offline
Faraday Member
Karma: 8
Posts: 3532
|
 |
« Reply #2 on: September 16, 2006, 04:46:32 pm » |
Yes, the software doesn't yet support the extra analog inputs. But take a look at ARDUINO/lib/targets/arduino/wiring.c and pins_arduino.c, you might be able to add the support easily.
|
|
|
|
|
Logged
|
|
|
|
|
China
Offline
Jr. Member
Karma: 0
Posts: 60
I love Arduino
|
 |
« Reply #3 on: September 16, 2006, 09:40:44 pm » |
Hi! I know M168 have 5 PWM(D/A) , and I don't know how to add the other 2 PWM in : int analog_out_pin_to_timer_array[NUM_DIGITAL_PINS] = { NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, // on the ATmega168, digital pin 3 has pwm #if defined(__AVR_ATmega168__) TIMER2B, #else NOT_ON_TIMER, #endif NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER1A, TIMER1B, #if defined(__AVR_ATmega168__) TIMER2A, #else TIMER2, #endif NOT_ON_TIMER, NOT_ON_TIMER, }; If Arduino 06 can add these new AD and DA to soft , it will be better!
|
|
|
|
|
Logged
|
|
|
|
|
China
Offline
Jr. Member
Karma: 0
Posts: 60
I love Arduino
|
 |
« Reply #4 on: September 16, 2006, 09:42:56 pm » |
I'm sorry , M168 have 6 PWM
|
|
|
|
|
Logged
|
|
|
|
|
berlin
Offline
Sr. Member
Karma: 0
Posts: 293
|
 |
« Reply #5 on: September 17, 2006, 05:37:04 am » |
Yes, the software doesn't yet support the extra analog inputs. But take a look at ARDUINO/lib/targets/arduino/wiring.c and pins_arduino.c, you might be able to add the support easily. i must admit, i already had one look to see if could find something. didn't think it would be too easy. but i promise to try with a little more time in the next days.
|
|
|
|
|
Logged
|
|
|
|
|
China
Offline
Jr. Member
Karma: 0
Posts: 60
I love Arduino
|
 |
« Reply #6 on: September 17, 2006, 06:49:58 am » |
kuk[ch65306] I think mellis is right , AD6 and AD7 are the number of "CH" , it is easy to add them ,and make them work  . but I don't have "Arduino Mini" , so I can't test it , I will buy some M168 next week to make it sure. the code: int analogRead(int pin) { unsigned int low, high, ch = pin;
// the low 4 bits of ADMUX select the ADC channel ADMUX = (ADMUX & (unsigned int) 0xf0) | (ch & (unsigned int) 0x0f);
// without a delay, we seem to read from the wrong channel delay(1);
// start the conversion sbi(ADCSRA, ADSC);
// ADSC is cleared when the conversion finishes while (bit_is_set(ADCSRA, ADSC));
// we have to read ADCL first; doing so locks both ADCL // and ADCH until ADCH is read. reading ADCL second would // cause the results of each conversion to be discarded, // as ADCL and ADCH would be locked when it completed. low = ADCL; high = ADCH;
// combine the two bytes return (high << 8) | low; }
|
|
|
|
|
Logged
|
|
|
|
|
berlin
Offline
Sr. Member
Karma: 0
Posts: 293
|
 |
« Reply #7 on: September 17, 2006, 10:26:53 am » |
well,
i'm doing a little trial & error with no success so far. do i understand it right that those files "wiring.c" and "pins_arduino.c" from the lib/targets/arduino folder are the EXACT files that are used when my program gets compiled? do i have to restart the arduino IDE or are these files read each time when i start the compiling process?
so far, i tried my luck mostly in pins_arduino.c, as wiring.c seems to be written quite dynamical. but my programm seems unaffected. i can't even disable one of the existing analog ins :-/
@fallen did you change someting in the code that you posted?
|
|
|
|
|
Logged
|
|
|
|
|
Forum Administrator
Cambridge, MA
Offline
Faraday Member
Karma: 8
Posts: 3532
|
 |
« Reply #8 on: September 17, 2006, 12:33:43 pm » |
I'm pretty sure that wiring.c and pins_arduino.c get recompiled every time you compile/verify or upload your sketch, but I can't swear to it. What did you try to disable an existing analog input?
|
|
|
|
|
Logged
|
|
|
|
|
China
Offline
Jr. Member
Karma: 0
Posts: 60
I love Arduino
|
 |
« Reply #9 on: September 17, 2006, 07:00:36 pm » |
kuk: Yes , I change "ch = analogInPinToBit(pin) " to "ch = pin" , in "analogInPinToBit(pin)" , there are only return 0~5 , now you can use 0~7, but I don't have "Arduino Mini" , so I can't test it , if it can't work , I so sorry about it.
|
|
|
|
|
Logged
|
|
|
|
|
berlin
Offline
Sr. Member
Karma: 0
Posts: 293
|
 |
« Reply #10 on: September 20, 2006, 09:12:26 am » |
@fallen: i see, but don't i rather have to adapt the array in arduino_pins.c ? pin_t analog_in_pin_to_port_array[NUM_ANALOG_IN_PINS] = { { PC, 0 }, { PC, 1 }, { PC, 2 }, { PC, 3 }, { PC, 4 }, { PC, 5 }, };
i think this array maps the numbered pins to the right inputs on the atmega. i tried adding 2 lines { PC, 6 }, { PC, 7 }, but that didn't work. (shouldn't it be ADC instead of PC anyway?) but even after i deleted some of the existing pairs, my program still worked with the six existing analog ins. i don't have my board here at the moment so i cannot work on it right now. //kuk
|
|
|
|
|
Logged
|
|
|
|
|
berlin
Offline
Sr. Member
Karma: 0
Posts: 293
|
 |
« Reply #11 on: September 21, 2006, 06:52:18 am » |
so shame on me, i've always been editing the wrong files. i had downloaded arduino 005 twice, so it couldn't work. ha, but now it does. you just need to edit "arduino_pins.c". in line 53 change #define NUM_ANALOG_IN_PINS 6 to #define NUM_ANALOG_IN_PINS 8 then in pin_t analog_in_pin_to_port_array[NUM_ANALOG_IN_PINS] = { { PC, 0 }, { PC, 1 }, { PC, 2 }, { PC, 3 }, { PC, 4 }, { PC, 5 }, { PC, 6 }, { PC, 7 }, };
add the last two lines as shown here. everything works fine for my needs. i don't need exact analog values though, so those two extra ins might still be a little different from the others. thank you mellis and fallen for encouraging me to try this :-D best, kuk
|
|
|
|
|
Logged
|
|
|
|
|
|