Pic: Two task at a time

Status
Not open for further replies.

lipschutz

Member
hi

i am working on a project using 16f72. i need to generate two 50Hz signals on two of the output pins and that is not a problem to implement. the problem is while executing this code i will have to read the battery voltage using ADC or any other means(of which i am not sure of). as you guess-- depending on the battery voltage the program will branch to some other location.

on the other hand if am i to use ADC, the time required to get the value will be variable as far as i know. assuming this: will i be able to use ADC withing the 10ms duty cycle while be on accurate in time.

any suggestions will be helpful. thanks in advance.

-lipschutz

NB: any handy but robust discrete electronic solution will be appreciable as well but of course i will prefer an all-in-PIC solution.
 
10mS is an absolutely immense amount of time in PIC terms - one common method would be to use timer interrupts to generate your 50Hz signals, and do the rest in the main program loop (where it will spend almost all it's time waiting doing nothing),
 
hi,
From your description its a 50Hz square wave not sinusoidal, so you should be able to read an ADC value within the 10mSec window.

If you capture the actual ADC value during one 10mSec period you could process the value over subsequent 10mS periods.

E.

damn: Nigel must have had sugar frosties for breakfast. beat me too it.
 
Start an a/d conversion, count the number of 50hz cycles and when you know you've done enough for the a/d module to have finished (depends on clock speed etc, but its probably only going to be one cycle, if the processor clock is fixed then the time per conversion should be the same, 1024 atod clock cycles x the division ratio you've programmed) then read the battery voltage and process it between 50hz o/p's.

As Nige says with interrupts its easy.

Another way if you dont like interrupts, setup timer1 and poll it to see when 10ms has passed, if you poll it quick enough it'll be fine.
 
thanks for your suggestions. i will try it using timer interrupt cause it sounds simple and robust.

-lipschutz
 
thanks for your suggestions. i will try it using timer interrupt cause it sounds simple and robust.

-lipschutz

If you check my tutorials there are a couple that use timer interrupts in a similar way, the dual 7 segment LED one and the 8x8 LED matrix one.
 
The only time I do not use interrupts is when I use a chip that doesnt support them.
 
thanks Nigel, i am going to check it out.

by the way is it possible to use timer interrupt within an external interrupt? to be specific as the supply mains goes down (RB0:INT) the ISR invokes which in turn requires the 50Hz signals (timer interrupt) to serve the power from the battery.

-lipschutz
 
Yes, you can have multiple interrupts - that's why you need to check what caused it in the ISR.
 
If you look at INTCON and PIR and PIE registers you'll see various bits to enable different interrupts and also the corresponding interrupt request flags.
 

lol
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…