Timer Interrupt creates problem

Started by "Prashant D. Kharade" December 9, 2008
Hello,







I am a new to Embedded world. I have chosen AVR series to work



I am doing a Datalogger project.







Facing a problem during the execution.



I am sequentially switching the relays, measuring the ADC count & sending to UART for checking purpose.



I have tried my best & step by step as suggested, but still there is problem.







Problem : The ADC count calculation goes wrong if Timer interrupt is used.



If Timer interrupt is not used, then ADC counts for all 24 channels are send correctly by UART via serial port.



If Timer code is added, the channel1 always shows count=1, & randomly 2 channels shows wrong ADC count.







Project details : 24 channel Data logger for battery system using Atmega128.







a. 20 Batteries are connected in series to a Charger.



b. We have to measure voltage of 20 batteries, current passing through the battery & temperature of pilot battery.



c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.



d. Relays are driven via ULN2803. Relays are connected in 8row & 3 columns.



e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5, & PC6.



f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 & sign bit are not used.)



g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3 wire RTD).



h. Max232 is used for external world communication.







Software :







a. AVRStudio – 4.13



b. AVR GCC - -20070525



c. For UART library of Peter Fleurry is used.







Attachment :



a. Circuit diagram (3 pages)



b. Code in zip file.







What code is doing :







1. Switches on Relays 1 to 24 sequentially.



2. Measure voltages appearing at ADC channels in for of ADC counts.



3. Sending it the counts to UART.



4. Timer interrupt used to calculate RTC in future. Presently switches on & off LED at one second. So interrupt at one second.



5. If timer interrupt is bypassed all ADC counts are send to serial port correctly.



6. If Timer is used ch1 always gives false ADC count reading & other any 2 channels randomly gives wrong ADC count.







I have tried my best. Did various permutations & combinations.



Initially ADC was used under program control, now I have used ADC under ADC interrupt mode.







Please help.







Best regards



Prashant D. Kharade



Pune. India.



Phone +91 9881739315



















From: a...@atmel.com [mailto:a...@atmel.com]

Sent: 08 December 2008 19:05

To: Prashant D. Kharade

Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem







Dear Customer,



As we do not have the source code with us, we are unable to test it here. In the request, what do you mean by "We are switching 24 relays & get the data." and "If we remove the interrupt all 24 counts from 24 relays are absolutely perfect", are you trying to get any data from the relay?



We recommend to refer the device datasheet under table "ADC Conversion Time" in page number 235 for more details about conversion time require for ADC result, in the mean time if any interrupt occurs then there is a possibility for getting random values as result.



We request you to try the ADC task separately first to identify any problem in it. If it works perfect then try the switching of relays individually. When both the functions works fine try to include timer counter interrupt of glowing an LED. By this step by step procedures we can identify where the issue arrises.



Even after implementing all the above mentioned instructions, if the problem still persists then feel free to contact us with setup details, reference voltage configured, minimal running code and fuse settings.





Best Regards,

Srinivasan Mariappan

Atmel Technical Support Team



---------------------------------

Please help us improve by rating your experience of our support on this request:

http://support.atmel.no/srv.htm?sid=1&hc=K1ynnhLQsQjKhV3

---------------------------------

Support and FAQ: http://support.atmel.no/

Distributors: http://www.atmel.com/dyn/general/contact.asp

Atmel AVR: http://www.atmel.com/AVR/

Discussion Forum: http://www.avrfreaks.net/phorum/



---------------------------------

Participate in the 2008 Atmel Customer Satisfaction Survey:

http://www.atmel.com/quality_customer_survey_08/

---------------------------------







Family : AVR® 8-Bit RISC

OtherPartNumber :

Part_no : ATmega128

Name : Prashant

Title : Engg

Company : Ador Powertron Ltd.

City : Pune

Street : 51 DII block MIDC

State : Maharashtra

Country : India

Postal_Code : 411027

Phone : --91-9881739315

Fax :

Site : www.adorpowertron.com

Email : p...@adorpower.com

Problem : Timer Interrupt creats problem

Details : We are designing a datalogger of 24 channels. We are switching 24 relays & get the data. In Timer compare interrupt we are just switching on/pff LED. But if the timer compare interrupt code is added the ADC counts are randomly varying. If we remove the interrupt all 24 counts from 24 relays are absolutely perfect. I tried 2 options. ADC under program control & ADC under interrupt control.But still no improvement. How can you give support & help. Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India



No virus found in this incoming message.

Checked by AVG - http://www.avg.com

Version: 8.0.176 / Virus Database: 270.9.15/1838 - Release Date: 08-12-2008 18:16




it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,



I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.



Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is problem.



Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24 channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1, & randomly 2 channels shows wrong ADC count.



Project details : 24 channel Data logger for battery system using Atmega128..



a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3 columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5, & PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 & sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3 wire RTD).

h. Max232 is used for external world communication.



Software :



a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.



Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.



What code is doing :



1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on & off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any 2 channels randomly gives wrong ADC count.



I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC interrupt mode.



Please help.



Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315









From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem



Dear Customer,

As we do not have the source code with us, we are unable to test it here. In the request, what do you mean by "We are switching 24 relays & get the data." and "If we remove the interrupt all 24 counts from 24 relays are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion Time" in page number 235 for more details about conversion time require for ADC result, in the mean time if any interrupt occurs then there is a possibility for getting random values as result.

We request you to try the ADC task separately first to identify any problem in it. If it works perfect then try the switching of relays individually. When both the functions works fine try to include timer counter interrupt of glowing an LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem still persists then feel free to contact us with setup details, reference voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www.atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -



Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24 relays & get the data. In Timer compare interrupt we are just switching on/pff LED. But if the timer compare interrupt code is added the ADC counts are randomly varying. If we remove the interrupt all 24 counts from 24 relays are absolutely perfect. I tried 2 options. ADC under program control & ADC under interrupt control.But still no improvement. How can you give support & help. Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

No virus found in this incoming message.
Checked by AVG - http://www.avg. com
Version: 8.0.176 / Virus Database: 270.9.15/1838 - Release Date: 08-12-2008 18:16


















Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:a...] On Behalf Of Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,



I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.



Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is problem.



Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24 channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1, & randomly 2 channels shows wrong ADC count.



Project details : 24 channel Data logger for battery system using Atmega128..



a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3 columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5, & PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 & sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3 wire RTD).

h. Max232 is used for external world communication.



Software :



a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.



Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.



What code is doing :



1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on & off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any 2 channels randomly gives wrong ADC count.



I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC interrupt mode.



Please help.



Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315









From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem



Dear Customer,

As we do not have the source code with us, we are unable to test it here. In the request, what do you mean by "We are switching 24 relays & get the data." and "If we remove the interrupt all 24 counts from 24 relays are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion Time" in page number 235 for more details about conversion time require for ADC result, in the mean time if any interrupt occurs then there is a possibility for getting random values as result.

We request you to try the ADC task separately first to identify any problem in it. If it works perfect then try the switching of relays individually. When both the functions works fine try to include timer counter interrupt of glowing an LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem still persists then feel free to contact us with setup details, reference voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www.atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -



Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24 relays & get the data. In Timer compare interrupt we are just switching on/pff LED. But if the timer compare interrupt code is added the ADC counts are randomly varying. If we remove the interrupt all 24 counts from 24 relays are absolutely perfect. I tried 2 options. ADC under program control & ADC under interrupt control.But still no improvement. How can you give support & help. Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

Dear Prashant,

Hmm you should put :
TCCR3B=0x00; // to stop Timer-3 for example, before start ADC
and put :
TCCR3B=0x03; // to start again Timer-3, with frequency of 125 kHz (see ATmega128 datasheet)
-> TCCR = Timer and Counter Control Register

cmiiw
-Adam

________________________________
From: Prashant D. Kharade
To: a...
Sent: Tuesday, December 9, 2008 2:55:50 PM
Subject: RE: [AVR club] Timer Interrupt creates problem

Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:avrclub@yahoogroups..com] On Behalf Of Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,

I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.

Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is problem..

Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24 channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1, & randomly 2 channels shows wrong ADC count.

Project details : 24 channel Data logger for battery system using Atmega128..

a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3 columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5, & PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 & sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3 wire RTD).

h. Max232 is used for external world communication.

Software :

a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.

Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.

What code is doing :

1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on & off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any 2 channels randomly gives wrong ADC count..

I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC interrupt mode.

Please help.

Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315

From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem

Dear Customer,

As we do not have the source code with us, we are unable to test it here. In the request, what do you mean by "We are switching 24 relays & get the data." and "If we remove the interrupt all 24 counts from 24 relays are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion Time" in page number 235 for more details about conversion time require for ADC result, in the mean time if any interrupt occurs then there is a possibility for getting random values as result.

We request you to try the ADC task separately first to identify any problem in it. If it works perfect then try the switching of relays individually. When both the functions works fine try to include timer counter interrupt of glowing an LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem still persists then feel free to contact us with setup details, reference voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www..atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -

Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24 relays & get the data. In Timer compare interrupt we are just switching on/pff LED. But if the timer compare interrupt code is added the ADC counts are randomly varying. If we remove the interrupt all 24 counts from 24 relays are absolutely perfect. I tried 2 options. ADC under program control & ADC under interrupt control.But still no improvement. How can you give support & help. Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

Dear Adam,

Thanks. But I have two doubts / problems

1. If I disable timer I will not able to count timer ticks or rather I will miss timer tick count. Which I am supposed to do. At each second, I have to increment timer counts. If it matches particular time, then again I have to do data logging in Timer based datalogging. If I disable timer, then timing calculations will be wrong.

2. Why ADC count calculation (stored in global variables) shall change, if timer interrupt occurs. They must be stored on stack & retrieved back as per theory.

Please help.

Regards

Prashant

-----Original Message-----
From: a... [mailto:a...] On Behalf Of Adam Aliyya Machfud
Sent: 09 December 2008 20:23
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

Dear Prashant,

Hmm you should put :
TCCR3B=0x00; // to stop Timer-3 for example, before start ADC
and put :
TCCR3B=0x03; // to start again Timer-3, with frequency of 125 kHz (see ATmega128 datasheet)
-> TCCR = Timer and Counter Control Register

cmiiw
-Adam

________________________________
From: Prashant D. Kharade
To: a...
Sent: Tuesday, December 9, 2008 2:55:50 PM
Subject: RE: [AVR club] Timer Interrupt creates problem

Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:avrclub@yahoogroups..com] On Behalf Of Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,

I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.

Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is problem..

Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24 channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1, & randomly 2 channels shows wrong ADC count.

Project details : 24 channel Data logger for battery system using Atmega128..

a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3 columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5, & PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 & sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3 wire RTD).

h. Max232 is used for external world communication.

Software :

a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.

Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.

What code is doing :

1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on & off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any 2 channels randomly gives wrong ADC count..

I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC interrupt mode.

Please help.

Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315

From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem

Dear Customer,

As we do not have the source code with us, we are unable to test it here. In the request, what do you mean by "We are switching 24 relays & get the data." and "If we remove the interrupt all 24 counts from 24 relays are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion Time" in page number 235 for more details about conversion time require for ADC result, in the mean time if any interrupt occurs then there is a possibility for getting random values as result.

We request you to try the ADC task separately first to identify any problem in it. If it works perfect then try the switching of relays individually. When both the functions works fine try to include timer counter interrupt of glowing an LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem still persists then feel free to contact us with setup details, reference voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www..atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -

Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24 relays & get the data. In Timer compare interrupt we are just switching on/pff LED. But if the timer compare interrupt code is added the ADC counts are randomly varying. If we remove the interrupt all 24 counts from 24 relays are absolutely perfect. I tried 2 options. ADC under program control & ADC under interrupt control.But still no improvement. How can you give support & help. Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

OK,
If you need logging the data every second, then divide timer service into 500mS (half second).
arrange a flag for task indication.
for ex. a bit indicates task, then 0 = count timer value, 1 = read ADC value.
toggle the bit with every 500 mS timer call

Kishor Soni
--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: RE: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 1:25 PM

Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the
end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:a...] On Behalf Of
Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,



I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.



Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending
to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is
problem.



Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24
channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1,
& randomly 2 channels shows wrong ADC count.



Project details : 24 channel Data logger for battery system using Atmega128...



a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the
battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3
columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5,
& PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 &
sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3
wire RTD).

h. Max232 is used for external world communication.



Software :



a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.



Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.



What code is doing :



1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on
& off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port
correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any
2 channels randomly gives wrong ADC count.



I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC
interrupt mode.



Please help.



Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315









From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem



Dear Customer,

As we do not have the source code with us, we are unable to test it here. In
the request, what do you mean by "We are switching 24 relays & get the
data." and "If we remove the interrupt all 24 counts from 24 relays
are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion
Time" in page number 235 for more details about conversion time require for
ADC result, in the mean time if any interrupt occurs then there is a possibility
for getting random values as result.

We request you to try the ADC task separately first to identify any problem in
it. If it works perfect then try the switching of relays individually. When both
the functions works fine try to include timer counter interrupt of glowing an
LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem
still persists then feel free to contact us with setup details, reference
voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this
request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www.atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -



Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24
relays & get the data. In Timer compare interrupt we are just switching
on/pff LED. But if the timer compare interrupt code is added the ADC counts are
randomly varying. If we remove the interrupt all 24 counts from 24 relays are
absolutely perfect. I tried 2 options. ADC under program control & ADC under
interrupt control.But still no improvement. How can you give support & help..
Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

Dear Kishor,

I am little confused with your explanation.
Datalogger is time based or event based.

1. Event based - Signal will come remotely to indicate start datalogging.
2. Time based - User can give fixed time, like 1sec, 30sec, 1min, 10 min. Then after each 10sec or set time datalogging shall be done.

Now I am testing in event based.
When I am giving external command, some channel reads wrong because, Timer interrupt is working.
I am measuring time at resolution of 1sec. The moment it goes to timer interrupt, the ongoing ADC reading goes wrong.

Why this is happening? How to overcome this ?

Regards

Prashant
p...@adorpower.com
-----Original Message-----
From: a... [mailto:a...] On Behalf Of Kishor Soni
Sent: 10 December 2008 11:52
To: a...
Subject: RE: [AVR club] Timer Interrupt creates problem

OK,
If you need logging the data every second, then divide timer service into 500mS (half second).
arrange a flag for task indication.
for ex. a bit indicates task, then 0 = count timer value, 1 = read ADC value.
toggle the bit with every 500 mS timer call

Kishor Soni
--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: RE: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 1:25 PM

Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the
end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:a...] On Behalf Of
Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,



I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.



Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending
to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is
problem.



Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24
channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1,
& randomly 2 channels shows wrong ADC count.



Project details : 24 channel Data logger for battery system using Atmega128...



a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the
battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3
columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5,
& PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 &
sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3
wire RTD).

h. Max232 is used for external world communication.



Software :



a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.



Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.



What code is doing :



1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on
& off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port
correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any
2 channels randomly gives wrong ADC count.



I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC
interrupt mode.



Please help.



Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315









From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem



Dear Customer,

As we do not have the source code with us, we are unable to test it here. In
the request, what do you mean by "We are switching 24 relays & get the
data." and "If we remove the interrupt all 24 counts from 24 relays
are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion
Time" in page number 235 for more details about conversion time require for
ADC result, in the mean time if any interrupt occurs then there is a possibility
for getting random values as result.

We request you to try the ADC task separately first to identify any problem in
it. If it works perfect then try the switching of relays individually. When both
the functions works fine try to include timer counter interrupt of glowing an
LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem
still persists then feel free to contact us with setup details, reference
voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this
request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www.atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -



Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24
relays & get the data. In Timer compare interrupt we are just switching
on/pff LED. But if the timer compare interrupt code is added the ADC counts are
randomly varying. If we remove the interrupt all 24 counts from 24 relays are
absolutely perfect. I tried 2 options. ADC under program control & ADC under
interrupt control.But still no improvement. How can you give support & help..
Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

Where is this documented?
I had roughly the same set of problems with my project, and stopping
timer interrupts during ADC measurements seems to have fixed them.
However, I can't find references to the issues.

Anyway ... thanks for the input!

Prashant D. Kharade wrote:
> Dear Kishor,
>
> I am little confused with your explanation.
> Datalogger is time based or event based.
>
> 1. Event based - Signal will come remotely to indicate start datalogging.
> 2. Time based - User can give fixed time, like 1sec, 30sec, 1min, 10 min. Then after each 10sec or set time datalogging shall be done.
>
> Now I am testing in event based.
> When I am giving external command, some channel reads wrong because, Timer interrupt is working.
> I am measuring time at resolution of 1sec. The moment it goes to timer interrupt, the ongoing ADC reading goes wrong.
>
> Why this is happening? How to overcome this ?
>
> Regards
>
> Prashant
> p...@adorpower.com
> -----Original Message-----
> From: a... [mailto:a...] On Behalf Of Kishor Soni
> Sent: 10 December 2008 11:52
> To: a...
> Subject: RE: [AVR club] Timer Interrupt creates problem
>
> OK,
> If you need logging the data every second, then divide timer service into 500mS (half second).
> arrange a flag for task indication.
> for ex. a bit indicates task, then 0 = count timer value, 1 = read ADC value.
> toggle the bit with every 500 mS timer call
>
> Kishor Soni
> --- On Tue, 12/9/08, Prashant D. Kharade wrote:
> From: Prashant D. Kharade
> Subject: RE: [AVR club] Timer Interrupt creates problem
> To: a...
> Date: Tuesday, December 9, 2008, 1:25 PM
>
> Thanks Kishor Soni.
> I have already put cli() instruction at start of ADC start & sei() at the
> end.
>
> But still the problem comes. I am not able to identify.
>
> Regards
>
> Prashant D. Kharade
>
> -----Original Message-----
> From: a... [mailto:a...] On Behalf Of
> Kishor Soni
> Sent: 09 December 2008 12:08
> To: a...
> Subject: Re: [AVR club] Timer Interrupt creates problem
>
> it is simple. disable timer during ADC conversion is going on.
>
> --- On Tue, 12/9/08, Prashant D. Kharade wrote:
> From: Prashant D. Kharade
> Subject: [AVR club] Timer Interrupt creates problem
> To: a...
> Date: Tuesday, December 9, 2008, 10:28 AM
>
> Hello,
>
>
>
> I am a new to Embedded world. I have chosen AVR series to work
>
> I am doing a Datalogger project.
>
>
>
> Facing a problem during the execution.
>
> I am sequentially switching the relays, measuring the ADC count & sending
> to UART for checking purpose.
>
> I have tried my best & step by step as suggested, but still there is
> problem.
>
>
>
> Problem : The ADC count calculation goes wrong if Timer interrupt is used.
>
> If Timer interrupt is not used, then ADC counts for all 24
> channels are send correctly by UART via serial port.
>
> If Timer code is added, the channel1 always shows count=1,
> & randomly 2 channels shows wrong ADC count.
>
>
>
> Project details : 24 channel Data logger for battery system using Atmega128...
>
>
>
> a. 20 Batteries are connected in series to a Charger.
>
> b. We have to measure voltage of 20 batteries, current passing through the
> battery & temperature of pilot battery.
>
> c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.
>
> d. Relays are driven via ULN2803. Relays are connected in 8row & 3
> columns.
>
> e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5,
> & PC6.
>
> f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 &
> sign bit are not used.)
>
> g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3
> wire RTD).
>
> h. Max232 is used for external world communication.
>
>
>
> Software :
>
>
>
> a. AVRStudio 4.13
>
> b. AVR GCC - -20070525
>
> c. For UART library of Peter Fleurry is used.
>
>
>
> Attachment :
>
> a. Circuit diagram (3 pages)
>
> b. Code in zip file.
>
>
>
> What code is doing :
>
>
>
> 1. Switches on Relays 1 to 24 sequentially.
>
> 2. Measure voltages appearing at ADC channels in for of ADC counts.
>
> 3. Sending it the counts to UART.
>
> 4. Timer interrupt used to calculate RTC in future. Presently switches on
> & off LED at one second. So interrupt at one second.
>
> 5. If timer interrupt is bypassed all ADC counts are send to serial port
> correctly.
>
> 6. If Timer is used ch1 always gives false ADC count reading & other any
> 2 channels randomly gives wrong ADC count.
>
>
>
> I have tried my best. Did various permutations & combinations.
>
> Initially ADC was used under program control, now I have used ADC under ADC
> interrupt mode.
>
>
>
> Please help.
>
>
>
> Best regards
>
> Prashant D. Kharade
>
> Pune. India.
>
> Phone +91 9881739315
>
>
>
>
>
>
>
>
>
> From: a...@atmel.com [mailto:a...@atmel.com]
> Sent: 08 December 2008 19:05
> To: Prashant D. Kharade
> Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem
>
>
>
> Dear Customer,
>
> As we do not have the source code with us, we are unable to test it here. In
> the request, what do you mean by "We are switching 24 relays & get the
> data." and "If we remove the interrupt all 24 counts from 24 relays
> are absolutely perfect", are you trying to get any data from the relay?
>
> We recommend to refer the device datasheet under table "ADC Conversion
> Time" in page number 235 for more details about conversion time require for
> ADC result, in the mean time if any interrupt occurs then there is a possibility
> for getting random values as result.
>
> We request you to try the ADC task separately first to identify any problem in
> it. If it works perfect then try the switching of relays individually. When both
> the functions works fine try to include timer counter interrupt of glowing an
> LED. By this step by step procedures we can identify where the issue arrises.
>
> Even after implementing all the above mentioned instructions, if the problem
> still persists then feel free to contact us with setup details, reference
> voltage configured, minimal running code and fuse settings.
> Best Regards,
> Srinivasan Mariappan
> Atmel Technical Support Team
>
> ------------ --------- --------- --------- --------- --------- -
> Please help us improve by rating your experience of our support on this
> request:
> http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
> ------------ --------- --------- --------- --------- --------- -
> Support and FAQ: http://support. atmel.no/
> Distributors: http://www.atmel. com/dyn/general/ contact.asp
> Atmel AVR: http://www.atmel. com/AVR/
> Discussion Forum: http://www.avrfreak s.net/phorum/
>
> ------------ --------- --------- --------- --------- --------- -
> Participate in the 2008 Atmel Customer Satisfaction Survey:
> http://www.atmel. com/quality_ customer_ survey_08/
> ------------ --------- --------- --------- --------- --------- -
>
>
>
> Family : AVR 8-Bit RISC
> OtherPartNumber :
> Part_no : ATmega128
> Name : Prashant
> Title : Engg
> Company : Ador Powertron Ltd.
> City : Pune
> Street : 51 DII block MIDC
> State : Maharashtra
> Country : India
> Postal_Code : 411027
> Phone : --91-9881739315
> Fax :
> Site : www.adorpowertron. com
> Email : pdkharade@adorpower .com
> Problem : Timer Interrupt creats problem
> Details : We are designing a datalogger of 24 channels. We are switching 24
> relays & get the data. In Timer compare interrupt we are just switching
> on/pff LED. But if the timer compare interrupt code is added the ADC counts are
> randomly varying. If we remove the interrupt all 24 counts from 24 relays are
> absolutely perfect. I tried 2 options. ADC under program control & ADC under
> interrupt control.But still no improvement. How can you give support & help..
> Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India
>
Then you tell me what is you want to do exactly.
can you sand me block diagram or flow chart ?

Kishor Soni

--- On Wed, 12/10/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: RE: [AVR club] Timer Interrupt creates problem
To: a...
Date: Wednesday, December 10, 2008, 2:29 PM

Dear Kishor,

I am little confused with your explanation.
Datalogger is time based or event based.

1. Event based - Signal will come remotely to indicate start datalogging.
2. Time based - User can give fixed time, like 1sec, 30sec, 1min, 10 min. Then
after each 10sec or set time datalogging shall be done.

Now I am testing in event based.
When I am giving external command, some channel reads wrong because, Timer
interrupt is working.
I am measuring time at resolution of 1sec. The moment it goes to timer
interrupt, the ongoing ADC reading goes wrong.

Why this is happening? How to overcome this ?

Regards

Prashant
p...@adorpower.com
-----Original Message-----
From: a... [mailto:a...] On Behalf Of
Kishor Soni
Sent: 10 December 2008 11:52
To: a...
Subject: RE: [AVR club] Timer Interrupt creates problem

OK,
If you need logging the data every second, then divide timer service into 500mS
(half second).
arrange a flag for task indication.
for ex. a bit indicates task, then 0 = count timer value, 1 = read ADC value.
toggle the bit with every 500 mS timer call

Kishor Soni
--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: RE: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 1:25 PM

Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the
end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:a...] On Behalf Of
Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,



I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.



Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending
to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is
problem.



Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24
channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1,
& randomly 2 channels shows wrong ADC count.



Project details : 24 channel Data logger for battery system using Atmega128....



a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the
battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3
columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5,
& PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 &
sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3
wire RTD).

h. Max232 is used for external world communication.



Software :



a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.



Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.



What code is doing :



1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on
& off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port
correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any
2 channels randomly gives wrong ADC count.



I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC
interrupt mode.



Please help.



Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315









From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem



Dear Customer,

As we do not have the source code with us, we are unable to test it here. In
the request, what do you mean by "We are switching 24 relays & get the
data." and "If we remove the interrupt all 24 counts from 24 relays
are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion
Time" in page number 235 for more details about conversion time require
for
ADC result, in the mean time if any interrupt occurs then there is a
possibility
for getting random values as result.

We request you to try the ADC task separately first to identify any problem in
it. If it works perfect then try the switching of relays individually. When
both
the functions works fine try to include timer counter interrupt of glowing an
LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem
still persists then feel free to contact us with setup details, reference
voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this
request:
http://support. atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support. atmel.no/
Distributors: http://www.atmel. com/dyn/general/ contact.asp
Atmel AVR: http://www.atmel. com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel. com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -



Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24
relays & get the data. In Timer compare interrupt we are just switching
on/pff LED. But if the timer compare interrupt code is added the ADC counts are
randomly varying. If we remove the interrupt all 24 counts from 24 relays are
absolutely perfect. I tried 2 options. ADC under program control & ADC
under
interrupt control.But still no improvement. How can you give support &
help..
Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India

Hi, thanks for the input.



Attached is C code.



I have total 24 relays to shift & measure voltage appearing.

Datalgooer is connected to Battery string. Battery is connected to a thyristor charger panel.

So there is lot of ripple.

So I had plan to measure each channel for 50 times & take the average.

For current measurement, 75mV amplifier is connected. It has huge ripple. So I have to wait for 400ms, then take the 50 samples & average it.

So for current channel, there is additional delay.



For testing purpose, I am sending the ADC counts to PC via UART.



I am sequentially switching the relays, measuring the ADC count & sending to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is problem.



Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24 channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1, & randomly 2 channels shows wrong ADC count.



Project details : 24 channel Data logger for battery system using Atmega128.



a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3 columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5, & PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 & sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3 wire RTD).

h. Max232 is used for external world communication.



Software :



a. AVRStudio 4.14.589

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.



Attachment :

a. Code c file.



What code is doing :



1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on & off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any 2 channels randomly gives wrong ADC count.



I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC interrupt mode.



Please help.



Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315





From: Ivan Gomez [mailto:i...@yahoo.com]
Sent: 10 December 2008 23:50
To: Prashant D. Kharade
Subject: Re: [AVR club] Timer Interrupt creates problem



Hi Prashant,



I think that the problem you are facing is because when you are making a conversion with the ADC an interruptiom comes from the timer.



So I sugest the following solution for the "Event Based" datalogger you are using:



1. When you send the command to read data from the batteries, the first thing you have to do is read the register of the counter that is used to generate the interrupt to turn on/off the led.



2. You need to know how many clock cycles the ADC needs to make a conversion.



3. So having the value of the register of the counter and the number of cycles needed by the ADC you can decide to start the ADC conversion or wait until the next timer interrupt occurs and then start the ACD conversion.



I don't know if you got the idea, but here I will show you and example. Suppose the interrupt occurs when the counter reaches the value 0xAA (just an example).

So the value 0xAA (170 in decimal) is proportional to 1 second.

Now suppose the time the ADC needs to make a conversion is 100 ms (I know it is faster but this is just an example). 100 ms would be equivalent to have a counter value of 0x11 (17 in decimal)

So, if you read the value of the counter and it is grater than 0x99 (170 - 17 = 153 in decimal), you will need to wait until the timer interruption occurs, and after that you will be able to start the ADC conversion. Else if the value of the counter is less than 0x98 (152) you can start the conversion right now.



Hope this solve your problem.



Another question that i have is that when you are sending the information trough the UART, are you making conversions with the ADC??



Regards.



Ivan Gomez






________________________________

From: Prashant D. Kharade
To: a...
Sent: Wednesday, December 10, 2008 2:59:00 AM
Subject: RE: [AVR club] Timer Interrupt creates problem

Dear Kishor,

I am little confused with your explanation.
Datalogger is time based or event based.

1. Event based - Signal will come remotely to indicate start datalogging.
2. Time based - User can give fixed time, like 1sec, 30sec, 1min, 10 min. Then after each 10sec or set time datalogging shall be done.

Now I am testing in event based.
When I am giving external command, some channel reads wrong because, Timer interrupt is working.
I am measuring time at resolution of 1sec. The moment it goes to timer interrupt, the ongoing ADC reading goes wrong.

Why this is happening? How to overcome this ?

Regards

Prashant
p...@adorpower.com
-----Original Message-----
From: a... [mailto:a...] On Behalf Of Kishor Soni
Sent: 10 December 2008 11:52
To: a...
Subject: RE: [AVR club] Timer Interrupt creates problem

OK,
If you need logging the data every second, then divide timer service into 500mS (half second).
arrange a flag for task indication.
for ex. a bit indicates task, then 0 = count timer value, 1 = read ADC value.
toggle the bit with every 500 mS timer call

Kishor Soni
--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: RE: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 1:25 PM

Thanks Kishor Soni.
I have already put cli() instruction at start of ADC start & sei() at the
end.

But still the problem comes. I am not able to identify.

Regards

Prashant D. Kharade

-----Original Message-----
From: a... [mailto:a...] On Behalf Of
Kishor Soni
Sent: 09 December 2008 12:08
To: a...
Subject: Re: [AVR club] Timer Interrupt creates problem

it is simple. disable timer during ADC conversion is going on.

--- On Tue, 12/9/08, Prashant D. Kharade wrote:
From: Prashant D. Kharade
Subject: [AVR club] Timer Interrupt creates problem
To: a...
Date: Tuesday, December 9, 2008, 10:28 AM


Hello,

I am a new to Embedded world. I have chosen AVR series to work

I am doing a Datalogger project.

Facing a problem during the execution.

I am sequentially switching the relays, measuring the ADC count & sending
to UART for checking purpose.

I have tried my best & step by step as suggested, but still there is
problem.

Problem : The ADC count calculation goes wrong if Timer interrupt is used.

If Timer interrupt is not used, then ADC counts for all 24
channels are send correctly by UART via serial port.

If Timer code is added, the channel1 always shows count=1,
& randomly 2 channels shows wrong ADC count.

Project details : 24 channel Data logger for battery system using Atmega128...

a. 20 Batteries are connected in series to a Charger.

b. We have to measure voltage of 20 batteries, current passing through the
battery & temperature of pilot battery.

c. 2 spare channels. So 20voltage, 1 current & 1 temp. Channels.

d. Relays are driven via ULN2803. Relays are connected in 8row & 3
columns.

e. 8 rows are connected to portA & 3 columns are connected to PC4, PC5,
& PC6.

f. Voltages are switched via RL1 to RL20 & fed to ADC0. (ADC1 &
sign bit are not used.)

g. Current is given to ADC3 via RL21. Temp. Is given to ADC2.(Measured by 3
wire RTD).

h. Max232 is used for external world communication.

Software :

a. AVRStudio 4.13

b. AVR GCC - -20070525

c. For UART library of Peter Fleurry is used.

Attachment :

a. Circuit diagram (3 pages)

b. Code in zip file.

What code is doing :

1. Switches on Relays 1 to 24 sequentially.

2. Measure voltages appearing at ADC channels in for of ADC counts.

3. Sending it the counts to UART.

4. Timer interrupt used to calculate RTC in future. Presently switches on
& off LED at one second. So interrupt at one second.

5. If timer interrupt is bypassed all ADC counts are send to serial port
correctly.

6. If Timer is used ch1 always gives false ADC count reading & other any
2 channels randomly gives wrong ADC count.

I have tried my best. Did various permutations & combinations.

Initially ADC was used under program control, now I have used ADC under ADC
interrupt mode.

Please help.

Best regards

Prashant D. Kharade

Pune. India.

Phone +91 9881739315

From: a...@atmel.com [mailto:a...@atmel.com]
Sent: 08 December 2008 19:05
To: Prashant D. Kharade
Subject: (ATTicket:525645) Support Form: Timer Interrupt creats problem

Dear Customer,

As we do not have the source code with us, we are unable to test it here. In
the request, what do you mean by "We are switching 24 relays & get the
data." and "If we remove the interrupt all 24 counts from 24 relays
are absolutely perfect", are you trying to get any data from the relay?

We recommend to refer the device datasheet under table "ADC Conversion
Time" in page number 235 for more details about conversion time require for
ADC result, in the mean time if any interrupt occurs then there is a possibility
for getting random values as result.

We request you to try the ADC task separately first to identify any problem in
it. If it works perfect then try the switching of relays individually. When both
the functions works fine try to include timer counter interrupt of glowing an
LED. By this step by step procedures we can identify where the issue arrises.

Even after implementing all the above mentioned instructions, if the problem
still persists then feel free to contact us with setup details, reference
voltage configured, minimal running code and fuse settings.

Best Regards,
Srinivasan Mariappan
Atmel Technical Support Team

------------ --------- --------- --------- --------- --------- -
Please help us improve by rating your experience of our support on this
request:
http://support . atmel.no/ srv.htm?sid= 1&hc=K1ynnhLQsQj KhV3
------------ --------- --------- --------- --------- --------- -
Support and FAQ: http://support . atmel.no/
Distributors: http://www.atmel . com/dyn/general/ contact.asp
Atmel AVR: http://www.atmel . com/AVR/
Discussion Forum: http://www.avrfreak s.net/phorum/

------------ --------- --------- --------- --------- --------- -
Participate in the 2008 Atmel Customer Satisfaction Survey:
http://www.atmel . com/quality_ customer_ survey_08/
------------ --------- --------- --------- --------- --------- -

Family : AVR 8-Bit RISC
OtherPartNumber :
Part_no : ATmega128
Name : Prashant
Title : Engg
Company : Ador Powertron Ltd.
City : Pune
Street : 51 DII block MIDC
State : Maharashtra
Country : India
Postal_Code : 411027
Phone : --91-9881739315
Fax :
Site : www.adorpowertron. com
Email : pdkharade@adorpower .com
Problem : Timer Interrupt creats problem
Details : We are designing a datalogger of 24 channels. We are switching 24
relays & get the data. In Timer compare interrupt we are just switching
on/pff LED. But if the timer compare interrupt code is added the ADC counts are
randomly varying. If we remove the interrupt all 24 counts from 24 relays are
absolutely perfect. I tried 2 options. ADC under program control & ADC under
interrupt control.But still no improvement. How can you give support & help..
Best regards Prashant D. Kharade Ador Powertron Ltd. Pune India