problem with ADC unit of atmega64

Discussion in 'The Projects Forum' started by Soroosh.m, Jun 1, 2012.

  1. Soroosh.m

    Thread Starter New Member

    May 14, 2012
    17
    0
    I have connected two IR receivers to PIN0 , PIN1 of ADC unit but the first sensor has effect on the other one! what should i do to solve this problem? :eek:
    [​IMG]
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Is that the correct way to connect an IR receiver? Have you looked at the datasheet for that receiver. It may give you some circuits recommendations
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Are these some sort of analog IR sensor? If so, got as match and a voltmeter?

    Hold the match (a simple IR source) over each sensor in turn and note the response on pins 60 & 61 with the voltmeter. If you get the expected response (each acts individually) then your problem is with your code.

    If so, post a bit of code, just enough to demonstrate the problem. How you set up the converter and how you obtain the result.

    If not, take a good picture of your unit and post that back here.
     
  4. Soroosh.m

    Thread Starter New Member

    May 14, 2012
    17
    0
    this is my sensor: http://solderslingers.com/cart/images/ir-led.JPG
    and this is my code:
    Code ( (Unknown Language)):
    1.  
    2. (i use codevision)
    3. #include <mega64.h>
    4. #include <stdio.h>
    5. #include <stdlib.h>
    6. #include <delay.h>
    7.  
    8. // Alphanumeric LCD Module functions
    9. #include <alcd.h>
    10.  
    11. #define ADC_VREF_TYPE 0x60
    12.  
    13. // Read the 8 most significant bits
    14. // of the AD conversion result
    15. unsigned char read_adc(unsigned char adc_input)
    16. {
    17. ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
    18. // Delay needed for the stabilization of the ADC input voltage
    19. delay_us(10);
    20. // Start the AD conversion
    21. ADCSRA|=0x40;
    22. // Wait for the AD conversion to complete
    23. while ((ADCSRA & 0x10)==0);
    24. ADCSRA|=0x10;
    25. return ADCH;
    26. }
    27.  
    28. // Declare your global variables here
    29. char lcd[10];
    30. void main(void)
    31. {
    32. // Declare your local variables here
    33.  
    34. // Input/Output Ports initialization
    35. // Port A initialization
    36. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    37. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    38. PORTA=0x00;
    39. DDRA=0x00;
    40.  
    41. // Port B initialization
    42. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    43. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    44. PORTB=0x00;
    45. DDRB=0x00;
    46.  
    47. // Port C initialization
    48. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    49. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    50. PORTC=0x00;
    51. DDRC=0x00;
    52.  
    53. // Port D initialization
    54. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    55. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    56. PORTD=0x00;
    57. DDRD=0x00;
    58.  
    59. // Port E initialization
    60. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    61. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    62. PORTE=0x00;
    63. DDRE=0x00;
    64.  
    65. // Port F initialization
    66. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    67. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    68. PORTF=0x00;
    69. DDRF=0x00;
    70.  
    71. // Port G initialization
    72. // Func4=In Func3=In Func2=In Func1=In Func0=In
    73. // State4=T State3=T State2=T State1=T State0=T
    74. PORTG=0x00;
    75. DDRG=0x00;
    76.  
    77. // Timer/Counter 0 initialization
    78. // Clock source: System Clock
    79. // Clock value: Timer 0 Stopped
    80. // Mode: Normal top=0xFF
    81. // OC0 output: Disconnected
    82. ASSR=0x00;
    83. TCCR0=0x00;
    84. TCNT0=0x00;
    85. OCR0=0x00;
    86.  
    87. // Timer/Counter 1 initialization
    88. // Clock source: System Clock
    89. // Clock value: Timer1 Stopped
    90. // Mode: Normal top=0xFFFF
    91. // OC1A output: Discon.
    92. // OC1B output: Discon.
    93. // OC1C output: Discon.
    94. // Noise Canceler: Off
    95. // Input Capture on Falling Edge
    96. // Timer1 Overflow Interrupt: Off
    97. // Input Capture Interrupt: Off
    98. // Compare A Match Interrupt: Off
    99. // Compare B Match Interrupt: Off
    100. // Compare C Match Interrupt: Off
    101. TCCR1A=0x00;
    102. TCCR1B=0x00;
    103. TCNT1H=0x00;
    104. TCNT1L=0x00;
    105. ICR1H=0x00;
    106. ICR1L=0x00;
    107. OCR1AH=0x00;
    108. OCR1AL=0x00;
    109. OCR1BH=0x00;
    110. OCR1BL=0x00;
    111. OCR1CH=0x00;
    112. OCR1CL=0x00;
    113.  
    114. // Timer/Counter 2 initialization
    115. // Clock source: System Clock
    116. // Clock value: Timer2 Stopped
    117. // Mode: Normal top=0xFF
    118. // OC2 output: Disconnected
    119. TCCR2=0x00;
    120. TCNT2=0x00;
    121. OCR2=0x00;
    122.  
    123. // Timer/Counter 3 initialization
    124. // Clock source: System Clock
    125. // Clock value: Timer3 Stopped
    126. // Mode: Normal top=0xFFFF
    127. // OC3A output: Discon.
    128. // OC3B output: Discon.
    129. // OC3C output: Discon.
    130. // Noise Canceler: Off
    131. // Input Capture on Falling Edge
    132. // Timer3 Overflow Interrupt: Off
    133. // Input Capture Interrupt: Off
    134. // Compare A Match Interrupt: Off
    135. // Compare B Match Interrupt: Off
    136. // Compare C Match Interrupt: Off
    137. TCCR3A=0x00;
    138. TCCR3B=0x00;
    139. TCNT3H=0x00;
    140. TCNT3L=0x00;
    141. ICR3H=0x00;
    142. ICR3L=0x00;
    143. OCR3AH=0x00;
    144. OCR3AL=0x00;
    145. OCR3BH=0x00;
    146. OCR3BL=0x00;
    147. OCR3CH=0x00;
    148. OCR3CL=0x00;
    149.  
    150. // External Interrupt(s) initialization
    151. // INT0: Off
    152. // INT1: Off
    153. // INT2: Off
    154. // INT3: Off
    155. // INT4: Off
    156. // INT5: Off
    157. // INT6: Off
    158. // INT7: Off
    159. EICRA=0x00;
    160. EICRB=0x00;
    161. EIMSK=0x00;
    162.  
    163. // Timer(s)/Counter(s) Interrupt(s) initialization
    164. TIMSK=0x00;
    165.  
    166. ETIMSK=0x00;
    167.  
    168. // USART0 initialization
    169. // USART0 disabled
    170. UCSR0B=0x00;
    171.  
    172. // USART1 initialization
    173. // USART1 disabled
    174. UCSR1B=0x00;
    175.  
    176. // Analog Comparator initialization
    177. // Analog Comparator: Off
    178. // Analog Comparator Input Capture by Timer/Counter 1: Off
    179. ACSR=0x80;
    180. SFIOR=0x00;
    181.  
    182. // ADC initialization
    183. // ADC Clock frequency: 125.000 kHz
    184. // ADC Voltage Reference: AVCC pin
    185. // Only the 8 most significant bits of
    186. // the AD conversion result are used
    187. ADMUX=ADC_VREF_TYPE & 0xff;
    188. ADCSRA=0x87;
    189.  
    190. // SPI initialization
    191. // SPI disabled
    192. SPCR=0x00;
    193.  
    194. // TWI initialization
    195. // TWI disabled
    196. TWCR=0x00;
    197.  
    198. // Alphanumeric LCD initialization
    199. // Connections specified in the
    200. // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    201. // RS - PORTA Bit 0
    202. // RD - PORTA Bit 1
    203. // EN - PORTA Bit 2
    204. // D4 - PORTA Bit 4
    205. // D5 - PORTA Bit 5
    206. // D6 - PORTA Bit 6
    207. // D7 - PORTA Bit 7
    208. // Characters/line: 8
    209. lcd_init(8);
    210.  
    211. while (1)
    212. {
    213. // Place your code here
    214. lcd_clear();
    215. itoa(read_adc(0),lcd);
    216. lcd_puts(lcd);
    217. itoa(read_adc(1),lcd);
    218. lcd_puts(lcd);
    219. }
    220. }
    221.  
     
    Last edited by a moderator: Jun 1, 2012
  5. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    Can you describe more on how the first IRR affects the second IRR.

    Allen
     
    Last edited: Jun 2, 2012
  6. Soroosh.m

    Thread Starter New Member

    May 14, 2012
    17
    0
    i hold the IR source on the first IRR and the value of ADC0 changes for example from 0 to 200 and the value of ADC1 changes from 0 to 20!!!! :eek:
     
  7. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    How powerful is your IR source and how far is it from the other sensor?
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Place the other sensor inside a sealed tin can and repeat the experiment.

    If you get similar results there is an electrical problem in the ground path.
     
  9. raviypujar

    New Member

    May 20, 2012
    9
    2
    I faced a similar problem with a different Microcontroller.
    some micro controller require that in addition to enabling the ADC functionality on the pin, you also need to make the particular pin as input port. so check with your controller and if it requires then,
    when you are reading channel0 make only its pin as input and make remaining ports as output. and similarly for reading channel1 make only its pin as input. remaining should stay as output.

    - Ravi
    <SNIP>
     
    Last edited by a moderator: Jun 17, 2012
    Soroosh.m likes this.
  10. Soroosh.m

    Thread Starter New Member

    May 14, 2012
    17
    0
    the ir source does not affect on the second sensor!
     
Loading...