On Fri, Mar 16, 2012 at 02:23:12PM +1000, cdb wrote: > Apart from being messy, I'm wondering would it be really bad programming= =20 > to disable interrupts actually inside the interrupt routine, and re-enabl= e=20 > them in the main routine. Honestly if you are doing that, the real question is if you need interrupts at all. Since PICs do not have vectored interrupts, I generally find that little advantage is gained over a main event loop with the exception of tasks that need to be done on a precision priority basis (i.e. if it doesn't get handled in the next X ns, then I've got a problem). Pretty much everything else can be checked and handled in the main loop. >=20 > I am reading a PIC16F690 ADC sequentially (6 channels) from within the=20 > interrupt. The interrupt contains 3 interrupt sources.=20 >=20 > 1. ADC Read. > 2. Auto convert via the ECCP compare mode special event trigger. > 3. Timer0 set to roll over every 500mS (approx). All three of these have flag bits in the PIR1/PIR2 register (by definition, otherwise they could not cause interrupts). So it's easy enough to simply check the flags in the main loop and when one fires off, handle the event. > Timer0 is used to allow the main body of the program to scale, display an= d=20 > possibly save to SD card. >=20 > My problem is that by the time the 500mS is up channel0 of the ADC has be= en=20 > read again obviously overwriting the previous contents. So do you need to read the ADC any faster than 500 mS? If not, simply start the ADC at the top of the main loop every 500 mS and read the values at the end of the loop. >=20 > My thoughts around this problem are - >=20 > 1. Disable interrupts until the main body has finished. > 2. Copy the raw ADC array contents to a second array and process that dat= a. >=20 > This would allow the interrupts to be disabled outside the interrupt. >=20 > This is for a 6 input power supply data logger (3 voltages, 3 current),=20 > this doesn't have to be 100% accurate (it is to be used to check voltage= =20 > deviations not actual voltages per se), but i would like it to be as=20 > accurate as possible. >=20 > I'm probably making this way more complicated than it needs to be, brain = is=20 > not in programming mode these days. >=20 > Any thoughts What about any of your interrupts has a "This needs to be done NOW!" quality? If nothing, then simply go without and let the main loop be the natural driver of these events. I generally find (with the exception of priority vectored interrupts) that in small projects interrupts are overrated. You example of wanting to disable the interrupt so that the main loop can finish is a perfect counterexample to why one is needed. The main loop is the priority over the ADC. So the ADC should not be in an interrupt. Just my 2 cents. BAJ >=20 > Colin. >=20 > PS: Can't use question marks, second keyboard of the week has just died. > -- > cdb, on 16/03/2012 >=20 >=20 >=20 >=20 >=20 >=20 > --=20 > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 Byron A. Jeff Department Chair: IT/CS/CNET College of Information and Mathematical Sciences Clayton State University http://cims.clayton.edu/bjeff --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .