Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/07/06 04:20
Read: times


 
#123794 - Can you give comparsion
Responding to: ???'s previous message
Jez Smith said:
I know its a bit early to be thinking about such things, but... I thought I would post this bit of code as a quite clever pulse width modulation scheme which in this case I used to control twinkly lights on a christmas tree.The basic idea is that the inner loop allows the output on the port to transistion smoothly between two values,in this case two random numbers at a rate controlled by the 'step' variable, the maximum brightness is set by the TOTAL variable and the value that step can take is constrained by the requirement that (TOTAL%step==0).In this implementation even more twinklyness is achieved by modifying the step value at random.The longest transistion from one value to the next takes about one second running at 0.5Mips.I am sure people can modify it to achieve surprising results.




# define TOTAL 252 // (<255 !!)


int main(void)
{

uint8_t step=6, step2,reg1, reg2, n=0, up=1, cntr;


srand(10); //Seed the rng

reg1= rand() ; // The first random number

while (1)
{
reg2= rand() ; // The second random number
cntr= TOTAL; // Start with fresh counter

while (1)
{
n+=(up)?1:-1;
PORTB=(n>cntr)?reg2:reg1;
up=(n==255)?0:((n==0)?1:up);
if (cntr==0) break;
if (n==0) cntr-= step;
}

reg1=reg2;
step2=rand();
if((TOTAL % step2) ==0) step=step2;
}

}





Hi jez:

Could you write the above c program, in assembler say metalink which is now free to all members as asm51 on different links.
So everyone can see the comparsion of c program in assembler source code. I tryed different programs for christmas tree lights but I never been able to get comparsion between the two programs. I also can not write any c language. This code is
way for programmers to see differce in the language with simple example which you already provided to the members.
Anyway it was just idea I had as long as not to much work for you to give the example in assembler. I read your threads for last year and you are one great programmer. Your sense of humor is very funny at times when you give answers to students.


Best reguards,


Ralph Sack

List of 11 messages in thread
TopicAuthorDate
Twinkly lights driver.            01/01/70 00:00      
   Amazing...            01/01/70 00:00      
   we only have stupid lights in England            01/01/70 00:00      
   Can you give comparsion            01/01/70 00:00      
      yep,ill do that            01/01/70 00:00      
   actualy I cheated :-)            01/01/70 00:00      
      LFSR            01/01/70 00:00      
   yeah i was thinking about that today            01/01/70 00:00      
   triac control            01/01/70 00:00      
      triac control            01/01/70 00:00      
   You after them girlies again?            01/01/70 00:00      

Back to Subject List