[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

PIC16f877 Application ?

Posted on 2006-04-16
Medium Priority
779 Views
Hi ,

1>> How to generate a 40 Khz and a 2 khz pulse ?
2>> How to "AND" them in order to send it to a I/O Pin of 16f877a ?

I am using PICC lite Hitech Compiler and Micro chip MPLab ...

Thanks,

Vpool
0
Question by:vpool
• 3
• 3

LVL 31

Expert Comment

ID: 16467408
If we are talking hardware logic circuits here, then you would have a crystal oscillator which you would feed into a counter.  The counter would be designed to produce one pulse every so many pulses (depends on the frequency of the crystal as to the detail).  This resulting pulse (operating at 40kHz) would then be used as the clock pulse for your system.  If you want to produce a pulse at 2kHz you would need to design a flip-flop counter which counted to 20, then reset itself.  You would do this by taking the correct Q and Not Q outputs from the Flip Flops and feeding them into Reset them when they are at Logic 1.

20 decimal = 10100 in binary so you need 5 Flip Flops.  The Reset pulse needs to use (from Most Significant first)

Q and Not Q and Q and Not Q and Not Q would be the AND logic you would need.  In practice you would invert the Q's for Not Q's and vice versa and use a NAND gate.

The Reset pulse would also feed the I/O pin of your microcontroller.

There's lots of different ways to do this, depending on which Flips Flops you use.  I don't know what devices are around these days (I used to do this kind of design in the 1970's with TTL 74XX devices).
0

Author Comment

ID: 16468138
Please tell me how to do it with software.......C Programming
0

LVL 3

Expert Comment

ID: 16475460
You already asked a similar question that I've answered here:

http://www.experts-exchange.com/Programming/Q_21781619.html

If you have an interrupt that's happening at 40kHz, to get a 2kHz output as well, you need to divide it by 20.  Have a counter in your 40kHz interrupt, and when it hits 20, toggle the state of the 2kHz output.  At the same time, on each 40kHz interrupt, you can calculate the "AND" of the two states (40kHz and 2kHz) to arrive at your combined output.

- initialise divide-by counter to 20
- set up a 40kHz interrupt (it needs to run at 80kHz to get the 'up' and 'down' transitions at the right speed)
- start the counter that the interrupt runs from

In the 40kHz interrupt service routing:
- swap state of 40kHz output
- decrement divide-by counter
- if counter is 0, then:
- reset counter to 20
- swap state of 2kHz output
- "AND" the two outputs together
- set output pin to result of "AND" calculation

A lot of the code for doing this in the article linked above.
0

Author Comment

ID: 16483319
You have been the best help....
Please explain the anding procedure in detail...
Cheers,
Vpool
0

LVL 3

Accepted Solution

steveiam earned 1500 total points
ID: 16483821
In C you can do a bitwise AND (i.e. operating on the binary bits of the values involved) like this:

int8 value1 = 1;
int8 value2 = 0;

int8 andResult = value1 & value2;
0

Author Comment

ID: 16492204
It woould be great if u can provide the code with the comment....I am getting really confused....

Cheers,
Vipul..
0

LVL 3

Expert Comment

ID: 16494398
What part are you specifically confused about, and what is causing the confusion?

Rather than me writing the entire program, and doing all the work for you, I'm happy to help with specific parts.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Before You Read The Article Please make sure you understand these two concepts: Variable Scope (http://www.php.net/manual/en/language.variables.scope.php) and Property Visibility (http://www.php.net/manual/en/language.oop5.visibility.php).  And to …
Introduction This question got me thinking... (http://www.experts-exchange.com/questions/28707487/GLOBALS.html) Why shouldn't we use Globals? This is a simple question without a simple answer.  How do you explain these concepts to a programmer w…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.