You mean you want to run the above lines of code as an interrupt? I don't think so.... The pauses will kill you.... What is your anticipated interrupt period?
By the way, What processor are you using and at what frequency?
You mean you want to run the above lines of code as an interrupt? I don't think so.... The pauses will kill you.... What is your anticipated interrupt period?
By the way, What processor are you using and at what frequency?
Last edited by Dave; - 7th April 2015 at 12:53.
Dave Purola,
N8NTA
EN82fn
I want to run this task in a way, that main task won't interfere with it, nor it execution will affect main task.
Processor can be any of 16F family at any possible frequency.
It’s not the pauses, the loop never ends:
Only your main program can do that.Code:SOFTPWM: code GOTO SOFTPWM
This ISR doesn’t allow your main program to ever run once it’s called.
If you get this going I’ll do the rest from there.
The code to flash one led on/off per second is only needed
to prove the include file is being included from the right directory and everything works.
At the speeds you’re talking about you can have up to eight software PWM channels
who’s rising and falling edges are synchronised to the clock cycle fairly easily.
especially easy if the frequency of the outputs are the same.
Code:DEFINE OSC xx ‘ tell PBP the clock frequency you’re using DEFINE NOCLRWDT ‘ this only means the program has it’s own clrwdt instruction ‘ you can still set the watchdog timer on at programming time include “Elapsed.bas” ‘ DT’s Elapsed Timer code from PBP forum ‘ drop the Elapsed.bas file in the PBP folder ‘don’t bother declaring SecondsChanged variable, ‘it should already be accessible because it’s declared in the include file ‘CMCON = 7 ‘uncomment to set analogue ports digital if the device has analogue ports ‘and the led is connected to one of them trisb.1 = 0 ‘ set led output whichever pin you have the led connected ledstate var bit gosub ResetTime 'reset time 00:00:00 gosub StartTimer 'start timer ' cycle: @ clrwdt ‘ if SecondsChanged = 1 then SecondsChanged = 0 ledstate = ledstate + 1 portb.1 = ledstate ‘ use your led pin of course endif ‘ goto cycle ‘
Below is the actual code which currently runs on 16F870 @ 4mhz:
It smoothly dims in-out leds, as needed. Here I'm imitating external change of A,B,C by introducing variable F and altering it's value in loop. Imagine there's no that FOR/NEXT loop, and values of A,B,C are updated elsewhere, but this code runs in interrupt. Will it work?Code:FOR F=1 TO 8 A=F C=F B=9-F FOR E=0 TO 10 IF A=1 THEN PORTC.0=0 IF B=1 THEN PORTC.1=0 if c=1 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>1 THEN PORTC.0=0 IF B>1 THEN PORTC.1=0 if c>1 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>2 THEN PORTC.0=0 IF B>2 THEN PORTC.1=0 if c>2 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>3 THEN PORTC.0=0 IF B>3 THEN PORTC.1=0 if c>3 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>4 THEN PORTC.0=0 IF B>4 THEN PORTC.1=0 if c>4 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>5 THEN PORTC.0=0 IF B>5 THEN PORTC.1=0 if c>5 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>6 THEN PORTC.0=0 IF B>6 THEN PORTC.1=0 if c>6 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 IF A>7 THEN PORTC.0=0 IF B>7 THEN PORTC.1=0 if c>7 then PORTC.2=0 PAUSE LODINI PORTC.0=1 PORTC.1=1 PORTC.2=1 NEXT NEXT
Depending on what your main code does, the answer might be yes.
Just remembering that the ISR is tied up for any of those pauses that could happen.
So maybe you’d have the first one, but I wouldn’t say you have the second one.
Because it’s not done in a way you could forget about it.The idea is to realize multichannel software PWM using interrupt.
I want to run this code in background of main task.
If you sent a serial, LCDOUT, I2C, etc. command from your main program,
and it got interrupted part way through for the above, the command in the main program wouldn’t work
.. unless those pauses were extremely small maybe.
Main program interacts only with user via buttons, by pressing which, user adjusts led brightness value, so a slight delay/flicker when pressing the buttons is acceptable.
CuriousOne, Here ia a small template for a program I just wrote that you can use as a starting point. It uses DT interrupts. I have them set for 1 millisecond and using 2 complete ports for the leds. Those ports are B & D. These interrupts are running in the background updating the led status from the 16 byte array. You can change the values in the array at any time in the main program. Enjoy. Let me know if it works for you.
Dave Purola,
N8NTA
EN82fn
Bookmarks