![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi friends i have to convert analog voltage and read the conversion value on the output port through digiview, i have written the code but i think its not working can any one help me out i am giving dc voltage of 2v as input to adc pin. here is the code #include <avr/io.h> #include <avr/iom128.h> #include <avr/signal.h> #include <avr/delay.h> unsigned char data[]; unsigned char counter; unsigned char i; void data_send(void); void init(void); void delay_loop(unsigned char); #define adc_data; /* ADC interrupt service routine*/ SIGNAL(SIG_ADC) { adc_data=((2*256)/5) data[0]=adc_data; //data[0]=ADCH; data_send(); // send packet data ADCSRA= 0x00; // disable ADC } void delay_loop1(unsigned long us) {for(;us>0;us--) {asm("nop");} } void init(void) { PORTA=0xFF; ADMUX= 0xE0; // Vref (1.1v) internal , channel pB3 of ADC ADCSRA= 0xC7; // enable ADC ; start conv. counter=0; // initial value } void data_send(void) { for(i=0;i<8;i++) { if(data[0] & (01<<i)) { PORTA= 0X40; delay_loop1(1000000); } else { PORTA = 0x00; delay_loop1(1000000); } } } void main() { init(); ADMUX= 0xE0; // Vref (1.1v) internal , channel pB3 of ADC ADCSRA= 0xEF; // enable ADC ; start conv. sei(); // interrupt enable while(1); } | |
| |
| | #2 |
|
I found something strange in your code ![]() Code: ADMUX= 0xE0; // Vref (1.1v) internal , channel pB3 of ADC "i am giving dc voltage of 2v as input to adc pin." So, how can you measure 2V with 1.1V ref voltage?? And further: 1) Why continously initialising ADMUX with 0xE0? You did it once in "init" that should be enough? 2) What's the purpose of adc_data? It's continously set to 102(.4) due to your formula without any variable in it ![]() 3) Since you then transfer the variable data[0], also filled with adc_data, I expect that you will see a condtant value on your serial port... | |
| |
| | #3 |
|
hello my friend, i am sorry i have written 1.1 v as internal reference by mistake actually i am using 2.56 v as internal voltage to ADC pin. i am very confused whether the adc conversion would go into effect without adc_data,in this function i am defining the formula for ADC i.e ADC=((Vin*256)/2.56). I have to view the conversion on a digiview device. further more comments and suggestions are higly appreciated. thank you. | |
| |
|
| Tags |
| adc, board, conversion, olimex |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Home made PCB's | markland556 | General Electronics Chat | 27 | 22nd February 2008 03:31 PM |
| LED Message Board!!! | c3cube | Micro Controllers | 2 | 10th February 2006 09:06 AM |
| Pic Development Board | bryan1 | Micro Controllers | 27 | 12th November 2005 09:59 AM |
| how do you get perfect pcbs? | monkeytree | General Electronics Chat | 26 | 26th April 2005 06:07 PM |
| Developer board for car application | turbo97se | Micro Controllers | 2 | 5th January 2004 04:57 PM |