Darrel, that algorithm is slick!
Does PBP allow assignments in expressions like C? For example;
Code:while(1) { x = (x+1)&7; portb ^= ((!(LoopLED[x]=(LoopLED[x]+1)%LoopCON[x])) << x); delay_us(2500); }
Darrel, that algorithm is slick!
Does PBP allow assignments in expressions like C? For example;
Code:while(1) { x = (x+1)&7; portb ^= ((!(LoopLED[x]=(LoopLED[x]+1)%LoopCON[x])) << x); delay_us(2500); }
If "8 lines" is about the loop part, then here is my code.
Think like a politician. Is is not less then 8?
Code:<font color="#000080"><b>EEPROM </b></font><font color="#FF0000">0</font>,[<font color="#FF0000">50</font>,<font color="#FF0000">22</font>,<font color="#FF0000">38</font>,<font color="#FF0000">75</font>,<font color="#FF0000">17</font>,<font color="#FF0000">40</font>,<font color="#FF0000">62</font>,<font color="#FF0000">13</font>] <font color="#000080"><i>'RB0 - RB7 time intervals </i></font>Time <font color="#000080"><b>VAR BYTE</b></font>[<font color="#FF0000">8</font>] Timer <font color="#000080"><b>VAR BYTE</b></font>[<font color="#FF0000">8</font>] Temp <font color="#000080"><b>VAR BYTE </b></font>Preload <font color="#000080"><b>VAR WORD </b></font>T1CON = <font color="#FF0000">%00000000 </font><font color="#000080"><i>' 1:1 @4Mhz </i></font>TMR1IF <font color="#000080"><b>VAR </b></font>PIR1.<font color="#FF0000">0 </font><font color="#000080"><i>' An alias for overflow bit. </i></font>TMR1ON <font color="#000080"><b>VAR </b></font>T1CON.<font color="#FF0000">0 </font>Begin: Preload = <font color="#FF0000">55543 </font><font color="#000080"><i>'Timer1 preload value for excat 10ms. interval. </i><b>FOR </b></font>Temp = <font color="#FF0000">0 </font><font color="#000080"><b>TO </b></font><font color="#FF0000">7 </font><font color="#000080"><b>READ </b></font>Temp ,Time[Temp] <font color="#000080"><i>'Fill time-intervals. </i></font>Timer[Temp] = <font color="#FF0000">0 </font><font color="#000080"><i>'Clear timer array. </i><b>NEXT </b></font>Temp T: TMR1IF = <font color="#FF0000">0 </font>TMR1L = Preload.LowByte TMR1H = Preload.HighByte TMR1ON = <font color="#FF0000">1 </font>Start: <font color="#000080"><b>IF </b></font>TMR1IF <font color="#000080"><b>THEN </b></font>INT_TMR ' 1 line. <font color="#000080"><b>GOTO </b></font>Start INT_TMR: TMR1ON = <font color="#FF0000">0 </font><font color="#000080"><b>FOR </b></font>Temp = <font color="#FF0000">0 </font><font color="#000080"><b>TO </b></font><font color="#FF0000">7 </font><font color="#000080"><b>IF </b></font>Timer[Temp] = Time[Temp] <font color="#000080"><b>THEN </b></font>PORTB.<font color="#FF0000">0</font>[Temp] = PORTB.<font color="#FF0000">0</font>[Temp] ^<font color="#FF0000">1 </font>Timer[Temp] = <font color="#FF0000">0 </font><font color="#000080"><b>ENDIF </b></font>Timer[Temp] = Timer[Temp] + <font color="#FF0000">1 </font><font color="#000080"><b>NEXT </b></font>Temp <font color="#000080"><b>GOTO </b></font>T <font color="#000080"><b>END </b></font>
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
I am working on the skeleton of a generic task handler that will manage say 16 tasks concurrently. The LEDs are just simulating tasks that occur at set intervals. One of the tasks will be a seconds counter (with an interval of 1000mS) that is the basis of a RTC (good to the accuracy/stability of the HS crystal clock) and accurate timing is therefore an important concern. So using any kind of Pause or Delay function would not work.
Using a hardware timer is really the only way to do it. However, the timer also has to account for whatever time is used up by instruction cycles - which can vary depending on conditional branches and time spent in each task. DT's method of using a CCP in compare mode solves this problem nicely. Thanks.
No I have not seen that link, thanks for pointing it out. I looked at Salvo and several other co-operative and pre-emptive RTOSes. Salvo is actually quite nice and has a small footprint. However, at $1,500 for a full-source license, it is somewhat pricey for my current needs - although it must be said that compared to some other commercial (particularly the pre-emptive ones such Avix, CMX, etc.) products, you could still call it a bargain. There are several free (and/or open source) pre-emptive systems for higher end devices but I find them extremely cumbersome to use and very resource hungry. The few that I looked at required about 20K ROM and 5-6K RAM for a useable configuration. I am also wanting something that can be easily ported to other devices/platforms (such as PIC24/dsPIC33 and 32-bit ARM Cortex M0/M3) and can be implemented using only a high level language (whether BASIC or C).
I have implemented what is basically a time-sliced task handler that will do 16 tasks in about 250 bytes of ROM and 75 bytes of RAM - additional tasks require 2 bytes of RAM per task. Small enough to run on a PIC12/16 - reducing the number of tasks could reduce the ROM (and RAM) footprint even further. Works fine - as I mentioned in a previous post, I have an application where an RTC is implemented using one of the tasks as an accurate seconds counter.
Bookmarks