Interrupts are the ticket.
This is pretty cool,
http://www.picbasic.co.uk/forum/showthread.php?t=3251
Interrupts are the ticket.
This is pretty cool,
http://www.picbasic.co.uk/forum/showthread.php?t=3251
Last edited by mackrackit; - 9th August 2008 at 00:56.
Dave
Always wear safety glasses while programming.
What is the connection to my question? How do you create a program that lets a led flash while proceeding with another task to symbolize that it is busy using your interrupt thingy?
Last edited by Ted's; - 10th August 2008 at 16:44.
Well, the connection is... Multithreading is pretty much the same as an interrupt.
This may help you understand it a bit.
http://en.wikipedia.org/wiki/Thread_(computer_science)
So if someting tries to start another "task" an interrupt is flagged. How you do this or what you do with it is up to you.
Dave
Always wear safety glasses while programming.
Hi,
If you look at the second post in this thread :
http://www.picbasic.co.uk/forum/show...stant+interupt
you will see a code snippet that ALMOST does what you want to do. It has a main loop where it is just performing a pause and then a timer is setup to toggle the led.
This is very close to what you are asking for.. just enable the interupt before entering your task (so the led will start to flash) and when you exit your task disable it again.
If you change the preloaded value (and prescaler if you have to) for the timer you can have different fast flashing led depending what task you are performing...
This is not difficult because of the EXCELLENT code provided by DT.
This might ( I didn't compile and test it, and I am not sure if it is the right register for your PIC) work and should flash the LED while you are performing my_task only.. just remember if my_task is very fast you might come out of it before we flash since the LED is flashing once per sec or something now.Code:LED1 VAR PORTB.1 INCLUDE "DT_INTS-14.bas" ' Base Interrupt System INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _ToggleLED1, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM goto main my_task: T1CON = $31 ; Prescaler = 8, TMR1ON to desice how fast we will flash @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts ;do all the stuff you want to do here @ INT_DISABLE TMR1_INT ; DISABLE Timer 1 interrupts RETURN Main: GOSUB my_task PAUSE 10 GOTO Main '---[TMR1 - interrupt handler]-------------------------------------------------- ToggleLED1: TOGGLE LED1 @ INT_RETURN
also we will go back to my_task every 10 sek... but what you do in your main loop I leave to you to decide.
/me
Last edited by Jumper; - 10th August 2008 at 16:50.
This seems to be time critical, so if a pauseus is included the other task won't continue.
What I actually want to do is this: (see picture)(strongly abbreviated)
Down means LED is off, Up means LED is on. The x-axis represents time.
So it is a LED light - fader.
So time could be 100ms meaning the LED is being switched on successively in a repeating manner till it will have taken 50ms then the process is reversed amounting to a total of 100ms.
Can you suggest a code for this?
Last edited by Ted's; - 10th August 2008 at 16:55.
To start with by using DT instant interupts the interupt will be performed no matter what the PIC is up to for the moment.. The PIC will stop in it tracks, do the interupt, toggle the led, return and then comtinue off where it was before.
First you wanted to flash a LED to show a busy task, now you want to fade a LED....
Is that one led or 255 leds or fading while doing other stuff..... I think I speak for more people than myself when I say "hmmm confused"..
What have you done previously, how much do you know about the PIC HW and what will your project do when it is done?
Good luck and I will keep an eye on this thread to see if I can help later on
First of all you have good English. We are talking about one led fading in and out which is being repeated. Imagine a flashing led. Now imagine the led is on. Imagine it not being on instantly but having an increase in brightness. Then imagine it having a decrease in brightness. Increase and decrease amount to flashing time. It softens the led's appearance.
Last edited by Ted's; - 10th August 2008 at 21:08.
Bookmarks