bad cog or bad program??

bnikkelbnikkel Posts: 78
edited 2020-04-22 - 20:29:51 in Propeller 1
this code worked at one point and now it does not. everything runs but as soon as *cog3 "fade routine" tries to run, nothing happens. the rest of the program continues to run. i finally got it to work by Not starting *cog2 the timer cog and just adding T=T+1 into the main loop. So am i running more cogs than i think or are some of the cogs burnt out?

"i deleted a lot of the redundant pattern color codes because this file was to big to post"
#include "simpletools.h"
#include "ws2812.h"
#include "fdserial.h"



#define LED_COUNT   127

uint32_t ledColors[127];

#define pattern_count  (sizeof(pattern) / sizeof(pattern[0])) 

ws2812 *driver;
fdserial *transmit;

uint32_t white[] = {0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,

0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,

0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,
0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff,0x99ffff
};





uint32_t change[] = {
COLOR_RED,0xfa0505,0xf50a0a,0xf00f0f,0xeb1414,0xe61919,0xe11e1e,0xdc2323,0xd72828,0xd22d2d,
0xcd3232,0xc83737,0xc33c3c,0xbe4141,0xb94646,0xb44b4b,0xaf5050,0xaa5555,0xa55a5a,0xa05f5f,
0x996464,0x996969,0x996e6e,0x997373,0x997878,0x99797d,0x998282,0x998787,0x998c8c,0x999191,
0x999696,0x999b9b,0x99a0a0,0x99a5a5,0x99aaaa,0x99afaf,0x99b4b4,0x99b9b9,0x99bebe,0x99c3c3,
0x99c8c8,0x99cdcd,0x99d2d2,0x99d7d7,0x99dcdc,0x99e1e1,0x99e6e6,0x99ebeb,0x99f0f0,0x99f5f5,
0x999999
};








volatile int button0;
volatile int button1;
volatile int button2;
volatile int button3;
volatile int button4; // play/pause

int recv = 0;

int delay = 15;  //red sweep speed
int p = 1; // pause/play

volatile int t = 0; //count timmer
volatile int a = 0; //start running count for timmer


void red();   //sub
void clear(); //sub

void touch(); //cog
int *cog1;

void timer(); //cog
int *cog2;

void fade();  //cog
int *cog3;
volatile int c3 = 0; //cog3 FADE running or not
int c4 = 0; //subroutine RED running or not

//-------------------------------------------------------------------------------------

int main(void)
{
       transmit = fdserial_open(0, 1, 0, 9600);
       driver = ws2812b_open(); 
       
       cog1 = cog_run(touch, 128);   
  pause(1000);   
 //      cog2 = cog_run(timer, 128);   
  pause(1000);  
     
   clear();
//--------------------------------------
//while(1){


//clear();
//pause(1000);

//fade();
//pause(5000);

//red();
//pause(1000);
//}

while(1){
  
  t = t + 1;
  
  if(t > 200)
  {
    t = 0;
  }    
  
  
     if((t > 100) && (c4 == 1))
     {
       c4 = 0;  
       a = 0;  //stop timer
       t = 0;  //reset timer  

       if(c3 == 1)
        { 
        cog_end(cog3);
        c3 = 0;
        }    
       cog3 = cog_run(fade, 128); 
       c3 = 1;        
         print("check");      
    
       pause(100);         
      }              
      
   
      
      
  
     if(button0 == 1){//play video
      // cog_end(cog3);
      //  high(13);
      recv = 0;              
      while(recv != 35)
        {   
       dprint(transmit,"%c%c", 49,13);            
            pause(10); 
       recv = fdserial_rxTime(transmit,100);
        }         
        red();
        t = 0; //reset timer
        a = 1; //start timer
        p = 1; //pause/play
        pause(20);
       }else{    
        //low(13); 
       }   
       
       
       
     if(button1 == 1){//play video
      // cog_end(cog3);
      //  high(14);
      recv = 0;              
      while(recv != 35)
        {   
       dprint(transmit,"%c%c", 50,13);            
            pause(10); 
       recv = fdserial_rxTime(transmit,100);
        }
        red();
        t = 0; //reset timer        
        a = 1; //start timer
        p = 1; //pause/play
        pause(20);
       }else{    
        //low(14); 
       }          
        
        
        
     if(button2 == 1){//play video
      // cog_end(cog3);
      //  high(15);
      recv = 0;              
      while(recv != 35)
        {   
       dprint(transmit,"%c%c", 51,13);            
            pause(10); 
       recv = fdserial_rxTime(transmit,100);
        }
        red();
        t = 0; //reset timer         
        a = 1; //start timer
        p = 1; //pause/play
        pause(20);
       }else{    
        //low(15); 
       }           
        
        
        
     if(button3 == 1){//play video
      // cog_end(cog3);
      //  high(16);
      recv = 0;              
      while(recv != 35)
        {   
       dprint(transmit,"%c%c", 52,13);            
            pause(10); 
       recv = fdserial_rxTime(transmit,100);
        }
        red();
        t = 0; //reset timer         
        a = 1; //start timer
        p = 1; //pause/play
        pause(20);
       }else{    
        //low(16); 
       }  
       
       
       
     if((button4 == 1) && (p == 1))//play/pause
     {
       // high(17);
       recv = 0;              
      while(recv != 35)
        {   
       dprint(transmit,"%c%c", 56,13);            
            pause(10); 
       recv = fdserial_rxTime(transmit,100);
        }
        p = 0;
        pause(1000);
       }else{    
        //low(17); 
       }         
       
     if((button4 == 1) && (p == 0))//play/pause
     {
      //  high(18);
      recv = 0;              
      while(recv != 35)
        {   
       dprint(transmit,"%c%c", 57,13);            
            pause(10); 
       recv = fdserial_rxTime(transmit,100);
        }
        p = 1;
        
        pause(1000);
       }else{    
        //low(18); 
       }       
               
       print("t= %d\n", t);       
 //      print("%d,%d,%d,%d,%d,\n", button0,button1,button2,button3,button4);
       
       
       
                 
   pause(100);
        
  }
}




//----------------------------SUBROUTINE------------------------------------------------



void clear()
{  
if(c3 == 1)
 { 
 cog_end(cog3);
 c3 = 0;
 }
 pause(100);
 
 
 
 ws2812_set(driver, 24, white, 127);
 ws2812_set(driver, 25, white, 127);
pause(1000);
}


//------------


void red()
{

   
if(c3 == 1)
 { 
 cog_end(cog3);
 c3 = 0;
 }
 pause(100);

      
        ws2812_set(driver, 24, redtop1, 127);
        ws2812_set(driver, 25, redtop1, 127);
pause(delay);
        ws2812_set(driver, 24, redtop2, 127);
        ws2812_set(driver, 25, redtop2, 127);       
pause(delay);
        ws2812_set(driver, 24, redtop3, 127);
        ws2812_set(driver, 25, redtop3, 127);
pause(delay);
        ws2812_set(driver, 24, redtop4, 127);
        ws2812_set(driver, 25, redtop4, 127);
pause(delay);
        ws2812_set(driver, 24, redtop5, 127);
        ws2812_set(driver, 25, redtop5, 127);
pause(delay);
        ws2812_set(driver, 24, redtop6, 127);
        ws2812_set(driver, 25, redtop6, 127);
pause(delay);
        ws2812_set(driver, 24, redtop7, 127);
        ws2812_set(driver, 25, redtop7, 127);
pause(delay);
        ws2812_set(driver, 24, redtop8, 127);
        ws2812_set(driver, 25, redtop8, 127);
pause(delay);
        ws2812_set(driver, 24, redtop9, 127);
        ws2812_set(driver, 25, redtop9, 127);
pause(delay);
        ws2812_set(driver, 24, redtop10, 127);
        ws2812_set(driver, 25, redtop10, 127);
pause(delay);
        ws2812_set(driver, 24, redtop11, 127);
        ws2812_set(driver, 25, redtop11, 127);
pause(delay);
        ws2812_set(driver, 24, redtop12, 127);
        ws2812_set(driver, 25, redtop12, 127);
pause(delay);
        ws2812_set(driver, 24, redtop13, 127);
        ws2812_set(driver, 25, redtop13, 127);
pause(delay);
        ws2812_set(driver, 24, redtop14, 127);
        ws2812_set(driver, 25, redtop14, 127);
pause(delay);
        ws2812_set(driver, 24, redtop15, 127);
        ws2812_set(driver, 25, redtop15, 127);
pause(delay);
        ws2812_set(driver, 24, redtop16, 127);
        ws2812_set(driver, 25, redtop16, 127);
pause(delay);
        ws2812_set(driver, 24, redtop17, 127);
        ws2812_set(driver, 25, redtop17, 127);
pause(delay);
        ws2812_set(driver, 24, redtop18, 127);
        ws2812_set(driver, 25, redtop18, 127);
pause(delay);
        ws2812_set(driver, 24, redtop19, 127);
        ws2812_set(driver, 25, redtop19, 127);
pause(delay);
        ws2812_set(driver, 24, redtop20, 127);
        ws2812_set(driver, 25, redtop20, 127);
pause(delay);
        ws2812_set(driver, 24, redtop21, 127);
        ws2812_set(driver, 25, redtop21, 127);
pause(delay);
        ws2812_set(driver, 24, redtop22, 127);
        ws2812_set(driver, 25, redtop22, 127);
pause(delay);
        ws2812_set(driver, 24, redtop23, 127);
        ws2812_set(driver, 25, redtop23, 127);
pause(delay);
        ws2812_set(driver, 24, redtop24, 127);
        ws2812_set(driver, 25, redtop24, 127);
pause(delay);
        ws2812_set(driver, 24, redtop25, 127);
        ws2812_set(driver, 25, redtop25, 127);
pause(delay);
        ws2812_set(driver, 24, redtop26, 127);
        ws2812_set(driver, 25, redtop26, 127);
pause(delay);
        ws2812_set(driver, 24, redtop27, 127);
        ws2812_set(driver, 25, redtop27, 127);
pause(delay);
        ws2812_set(driver, 24, redtop28, 127);
        ws2812_set(driver, 25, redtop28, 127);
pause(delay);
        ws2812_set(driver, 24, redtop29, 127);
        ws2812_set(driver, 25, redtop29, 127);
pause(delay);
        ws2812_set(driver, 24, redtop30, 127);
        ws2812_set(driver, 25, redtop30, 127);
pause(delay);
        ws2812_set(driver, 24, redtop31, 127);
        ws2812_set(driver, 25, redtop31, 127);
pause(delay);
        ws2812_set(driver, 24, redtop32, 127);
        ws2812_set(driver, 25, redtop32, 127);
       
 c4 = 1; 
 pause(100);            
}

//------------------------------------COGS------------------------------

void fade()
{
  //simpleterm_open();   

 // c3 = 1;

      pause(1000);        
    int base = 0;
    int idx, i;
    int c = 0xff0000;
    int color = 0;
    
  //print("entering");
    // repeat count times or forever if count < 0
    while(color < 51)  //# of colors in pattern
          {

         c = change[color]; 
             
 uint32_t pattern[] = {c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c
};            
             
        idx = base;                             // start at base
        for (i = 0; i < LED_COUNT; ++i) {       // loop through connected leds
            ledColors[i] = pattern[idx];        // Set channel color
            if (--idx >= pattern_count)         //Direction,   past end of list?
                idx = 51;                        // yes, reset, number of lights in pattern -1
        }
        if (++base >= pattern_count)            // set the base for the next time
            base = 0;            
            
        if (++color >= 52)            // # of colors in pattern
            color = 0;      
                 
       
        ws2812_set(driver, 24, ledColors, LED_COUNT); 
        ws2812_set(driver, 25, ledColors, LED_COUNT);
        
       pause(100);
    }  
    

  
   
  //print("exiting");                           

  //simpleterm_close(); 
         c3 = 0;           
         cog_end(cog3);   
       pause(100);
     
   //  while(1)
  //   {
  //   pause(100);
  //   }     
     
}



//--------------------------------
  
void touch()
{
  while(1){
    button0 = input(7);                  
    button1 = input(8);    
    button2 = input(9);    
    button3 = input(10);
    button4 = input(11);  //pause  
  pause(100);
}  
}

void timer()
{  
   while(1)
   {    
        if(a == 1)
         {     
           t = t+1;       
         }            
   pause(1000);  
   }     
}

Comments

  • It's extremely unlikely a cog is not working, and much more likely that you are trying to start a 9th cog.

    Remember that the code starts with the current cog.

    Can you use the serial port to output a message when each cog is started? If so, when you start a cog that coginit can return the cog number, so display that cog number to the serial port.

    Don't forget that fdserial (if it is similar to FullDuplexSerial) starts its' own cog for the pasm code too.
  • thats what i thought at first but i can only count 7 cogs at most?
  • Here is a routine to check available cogs
    PRI IdleCOGs | i,j,cogs[8]
        repeat i from 0 to 7
          cogs[i] := cognew(@entry,0) +1                    ' try to start cog(s)
          if cogs[i] 
            j++
        repeat i from 0 to 7
          if cogs[i]
            Print.Str(1 + str.integerToDecimal(cogs[i]-1, 1)) ' print avail cog#
            Print.Char(" ")
            cogstop(cogs[i] -1)                             ' stop the cog(s)
    
    DAT
    '' Just a simple pasm program to test if a cog is available
                  org       0
    entry         jmp       #entry                  ' loops here until cogstop forced!
    
Sign In or Register to comment.