CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

IR-Code simulation student needs help!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








IR-Code simulation student needs help!
PostPosted: Sat Mar 17, 2007 11:24 am     Reply with quote

Hello everybody,

my name is Bernhard, I am a student from Austria(next to Germany) and i am shortly before my school leaving examination.

My job is it to create an IR-Code.
I use the MPLAB 7.5 , CCS C and the PIC18F452.


I need your help!
Let me try to explain what my code is about:


I have an array codin[] which is a simplified version of the real code. I made a decode routine where the codin data is being converted. For example a "1" would be converted 1,0,0,0 . That means, when using timer0, 400us high followed by 1200us low time(see code). The new code is then send to the codout[] array, and there timer0 creates pulses.
The first three bits of codin[] are used to identify the IR-protocol.
Then the simplified code data comes.
The output data is based on the values in codout[].

So, now to my problem Wink

The simulation of codout[] doesnt match with the converted codin[] data.
I use the MPLAB(7.5) IDE Logic Analyzer.

The IR-Code begins with a specified start impuls length, like (1,1,1,1,1,0,0,0), that means 5*400us(timer0) + 3*400us.
That must accur everytime before I send the Code.
I thought it would be possible to fill the codout[] with the start value, and after that i start decoding, but it doesn't work. (please see code)

Rolling Eyes I hope that my text can be understood Smile

It would be a huge oblige, when you could help me!!!
Thanks in advance!
best regards Bernhard


Here is my code:


Code:

#include<18F452.h>
#fuses XT,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#use standard_io(c)
 
int x=0, i=3, value;
int count=3; 
int codin [] = {0,0,0,1,1,1,1,0,0,0}; // simplified for test
int codout[] = {};  // empty array


#int_timer0

void isr()

 {

set_timer0(80);  // timer overflow 400us

   if(codout[count]==1)  // value check in codout array
   {
      output_high(Pin_B5);
                           setup_ccp1(CCP_PWM);
   }
   else
   {
      output_low(Pin_B5);
      setup_ccp1(CCP_OFF);
   }
count++;
if(count>22)  // the codout array consits of 22digits
count=3;   //set to 3 because field number 0,1,2 are used for Identification
}

void yamaha()  // yamaha code decoder
{
   // here comes the start impuls 5*400us + 3*400us, doest work
           //codout[x]=1;     
           //codout[x+1]=1;
          // codout[x+2]=1;
           //codout[x+3]=1;
          // codout[x+4]=1;
           //codout[x+5]=0;
           //codout[x+6]=0;
          // codout[x+7]=0;
         //x=x+8;

        for(i=0; i<8; i++)
   {
      if (codin[i]==0)  // check input array for 0
         {
         codout[x]=1;
         codout[x+1]=0;
         x= x+2;
        }

      else if (codin[i]==1) // check input array for 1

         {
         codout[x]=1;
         codout[x+1]=0;
         codout[x+2]=0;
         codout[x+3]=0;
         x= x+4;
         }
   }
}



void sony()  //  It is not yet used!
{
   for(i=0; i<11>17
   value =13; // set 50% PWM duty cycle // for 38khz value-> 13 for 56khz value-> 9
      set_pwm1_duty(value); 
   choose();

  while(1) {
          }

}

bernhard3



Joined: 17 Mar 2007
Posts: 2

View user's profile Send private message

PostPosted: Sat Mar 17, 2007 11:35 am     Reply with quote

Embarassed I think I made a mistake!

I did not log in, so I sent my message as a quest!
I cannot edit it anymore...
And a part of my code is not displayed correctly!

Sorry, for that, I try to complete my code Rolling Eyes

greetings Bernhard

Code:


void sony()  //  It is not yet used!
{
   for(i=0; i<11; i++)
   {
      if (codin[i]==0)
         {
         codout[x]=0;
         codout[x+1]=0;
         x= x+2;
         }

      else if (codin[i]==1)

         {
         codout[x]=0;
         codout[x+1]=0;
         codout[x+2]=0;
         codout[x+3]=0;
         x= x+4;
         }
   }
}

void choose() // for IR-code identification
{int j;
if(codin[j]==0 && codin[j+1]==0 && codin[j+2]==0)
{
   yamaha();
}
else if(codin[j]==1 && codin[j+1]==1 && codin[j+2]==1)
{
  sony();
}
}


void main()

{
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER1);   
   setup_timer_0 (RTCC_INTERNAL|RTCC_8_BIT); 
   setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
    setup_timer_2(T2_DIV_BY_1, 17, 1);   //  (4MHz / (4 * TMR2 prescale value * 38KHz)) - 1 = 25 || for 56khz->17
   value =13; // set 50% PWM duty cycle // for 38khz value-> 13 for 56khz value-> 9
      set_pwm1_duty(value); 
   choose();

  while(1) {
          }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 17, 2007 11:43 am     Reply with quote

Quote:
int x=0, i=3, value;
int count=3;
int codin [] = {0,0,0,1,1,1,1,0,0,0}; // simplified for test
int codout[] = {}; // empty array

The line in bold is wrong.

You must declare the array size, either by initializing it as you have
done with 'codin' or by putting a value inside the brackets.
Example:
Code:
int codout[10];


Your current code is over-writing other variables. Look at the .SYM
file in your project directory:
Code:

01A     value
01B     count
01C-025 codin
026     codout
027     yamaha.@SCRATCH
028     yamaha.@SCRATCH
029     yamaha.@SCRATCH
02A     isr.@SCRATCH

Notice that 'codout' is only one byte long. If you write more than
one byte to it, you will destroy the yamaha scratch variables and
also the isr scratch variable. Your program will not run correctly.
That's why it's important to declare the size of the 'codout' array.

-------
Also, when you post code, make sure that you disable HTML.
Some of the lines in your code were garbled because HTML was enabled.
There is a tickbox below the posting window to disable it.
It looks like this:
Quote:
x Disable HTML in this post
bernhard3



Joined: 17 Mar 2007
Posts: 2

View user's profile Send private message

PostPosted: Sat Mar 17, 2007 11:59 am     Reply with quote

@ PCM programmer

Thank's for your fast respond!

Code:

int codout[10];


Is it correct that with [10] , ten fields, with a start value of 0, are created?
When i use "int" I have 256 digits?
Arrow
Code:

int codout[255];

Is 255 the maximum field number when using int?

greetings Bernhard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 17, 2007 12:15 pm     Reply with quote

In CCS, 'int' mean an 8-bit unsigned integer.

If you use an 'int' as the array index, you can declare an array
of 256 elements. Example:
Code:

int array[256];

void main()
{
int i;    // Array index 
int c;

c = array[i];   

while(1);
}

The value of 'i' can be from 0 to 255.
buneri
Guest







Problem in Timer Isr
PostPosted: Sat Apr 07, 2007 1:52 am     Reply with quote

I m using two timers timero and timer1 in my project. My project is to creat pulses of width 500us with respect to the percentage value of ADC. For example for 5V i need 200 pulses and for 2.5V i need 100 pulses and the hundred pulses with 0s width.
Also i need 500us width pulse in start and at the end of 100ms delay i.e at the end of 200 pulses but this output is on anther pin.

I have connected an LED to both of the output pin, I seen the mistake in timing.
Here is my code if anyone find mistake plz tell me,

// PIN_D0 500us pulse after every 100ms delay
// PIN_D1 500us pulses wrt the ADC value


#include <16F877.h>
#device icd=true
#device adc=10
#fuses HS,NOLVP,NOWDT
#use delay(clock=20000000)

#define boundry PIN_D7
#define pulse PIN_D0

int pulses=0,NOP;

#int_RTCC
RTCC_isr()
{
pulses++;
if((pulses < (NOP+1)) && (pulses > 1))
output_toggle(pulse);

if(pulses >= (NOP+1))
output_bit(pulse,0);

set_rtcc(255-39);
}


#int_TIMER1
TIMER1_isr()
{
pulses=0;
set_timer1(65535-6250);
}




void main()
{
float value;

setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
//enable_interrupts(INT_RTCC);
//disable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
set_rtcc(0);
output_bit(boundry,0);
output_bit(pulse,0);
set_adc_channel(1);

// TODO: USER CODE!!
while(1)
{
delay_us(10);
value=read_adc();
NOP = (value/1023)*2*100;
enable_interrupts(INT_RTCC);
//set_rtcc(0);

if(pulses==0)
output_bit(boundry,1);

if(pulses==1)
{
output_bit(boundry,0);
enable_interrupts(INT_TIMER1);
set_timer1(0);
}

}//while
}//main
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group