Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.:D
 
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.
 
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
 
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.
 
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.:d

lol:)
 
Status
Not open for further replies.

Latest threads

Back
Top