??? 12/11/05 20:54 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#105058 - Classic Problem Responding to: ???'s previous message |
Mehdi said:
All things are OK, but there is a bit problem in my timing, when reading adc I disabled interrupts, This task destroys interrupts like zero cross detection on p3.2 And 135 seconds generating, when reading adc If i don't disable interrupts ,The returned value is damaged? If i use reading ADC in interrupts routine then generating 135 seconds is damaged! This is the classic shared data problem. You need to read data (an ADC) in an interrupt routine and share it with another routine. If you do not make the ADC read operation atomic e.g by disabling interrupts, you can get corrupt data. However, disabling interrupts can cause other operations not to function correctly. You have several options: 1. Read the ADC in the zero crossing routine. Do the zero crsooing stuff first then, if the ADC is ready, read it. The danger with this approach is if the zero crossing input stops you cannot read the ADC. However, loss of zero crossing is an arror anyway so you should be detecting it anyway. 2. You only need zero crossing when turning the heater on and off. Read the ADC when this is not happening 3. Consider synchronising everything to a single interval. As others have mentioned, you probably do not need to read the ADC more than one per second. As the ADC result is used to set the heater you don't need the zero cross untill after each ADC reading. You can also count 135 secs with this method and flash lamps at one second intervals too. HTH Ian |