On Tue, 4 Nov 2003 20:12:02 +0530, you wrote: >Hi, > >Summary: Should I use interrupts to do all time-based activities that a >PIC does ?... > >I've just finished coding and testing a PIC project that was ~10 months >in making. It has an LCD, 4-key keypad, temperature sensor, optos, LEDs >etc. - A PID temperature controller. The controller accepts setpoints >for timer, temperature, Kp, Ki and Kd. The timer can count from 1 second >to 999.59 minute. The duty cycle for the opto is approximately 0.25 >seconds (1 ms x 255). > >The loop runs like this: >1. Display the actual temperature and timer, >2. Take an ADC reading, >3. Calculate PWM, >4. Run opto for that long, >5. Store the current timer values in EEPROM, >6. Check if the user has pressed any key and depending on it do >something. Keypress is monitored all the while by PortB interrupt on >change and only after steps 1-5 are over, it acts on what key is >pressed. > >Everything works fine, it accepts user inputs, calculates PWM, runs >opto, monitors key presses, shows current timer. The problem is... > >I run the loops sequentially, so it does one thing at a time. So even if >the PIC is in the middle of running the opto and a timer second crosses >over, the display is refreshed much later when duty cycle is over. And >it looks as if the timer is irregular. Further, there is a major fault >in the system that the PWM runs discontinuously - LCD display, EEPROM >save, ADC reading are outside the duty cycle. > >My question is, should I use interrupts to do these activities? >1. Inside the interrupt routine have a counter and flag for each of the >above activity. 2. Every millisecond, update the flags. 3. After >returning from the millisecond interrupt, check flags and do relevant >activities. > >Will this be a _good_ design? I mean, everything being interrupt driven. > >The post is a bit too verbose for my liking, but I'd like to make my >problem very clear. Sorry... > >Thanks, >Mohit. You should certainly do the PWM under interrupts, as this will guarantee = consistent timing.=20 You may also want to do the ADC reading as well, so it happens at = consistent intervals. The other stuff will be less time-critical, so it won't really matter = when you do them. -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics