![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| So far I have been coding a control program and have found it quite straightforward. I am encountering problems while trying to make my chip do several things at once. At a certain point in the program I want to set an output pin high for a short time, aswell as another pin high for a longer time. This loop may be executed again while the second pin is high, keeping it high. This kind of thing would be easy to do in java or similar by sending two programing threads off doing the two different methods. I realise that is a high level concept and the only way I can think of reproducing that on a PIC would be using complex timing and checks, which I want to aviod to keep the performance. Is there anything built into pics (16f877) to help me achieve this? Any good tutotials on this kind of thing? Thanks | |
| |
| | (permalink) |
| You could use timer interrupt routines, generate interrupts at regular intervals and decrement a number of counter registers (one for each pin you want to stay high), when the particular counter reaches zero simply turn the pin off. To set the pin high, simply set it high with BCF and reset the counter for the time you require. What exactly are you trying to do, they could well be an easier solution for your specific problem - particularly if the requirements are fixed (such as the width is always the same, and one is always the longest). Something like this: Pin1 high Pin2 high Delay time1 Pin1 low Delay time2-time1 Pin2 low You get the idea? - this isn't in any kind of code of course!. | |
| |
| | (permalink) |
| I like to use a setup where each separate thread is a function call that either does something or exits quickly to allow the other task functions to run. Code: void Task_1 (void)
{
if (counter == TIME1)
{
Pin1 = 0;
}
}
void Task_2 (void)
{
if (counter == TIME2)
{
Pin2 = 0;
}
}
void main ()
{
Task_1();
Task_2();
} Hope this helps Brent | |
| |
| | (permalink) |
| Thanks guys, lots for me to be getting on with. No doubt I will be back with questions soon :twisted: | |
| |
| | (permalink) |
| HI Guys I have been looking into using interrupt routines to perform the timing checks, the problem is I am already using an interrupt routine. I am using pic basic compiler which only has one command for responding to an interrupt which I am already using. There doesnt appear to be a way of differentiating between the timer triggered interrupts and the ones triggered by a leading edge on pin 6 INT,RB0 Is this a limitation in the language I am using or the pic itself (16f628)? Thanks John | |
| |
| | (permalink) | |
| Quote:
If your language doesn't support this you may be in trouble!. | ||
| |