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

tocki and timer1
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

tocki and timer1
PostPosted: Sat May 17, 2008 6:07 am     Reply with quote

hi

i use timer0 and timer1 of pic16f877a with an osc of 16Mhz. I have a 50hz input from the RA4/tocki pin as signal input. All i need is to specify a 1oms time resolution from TÄ°mer1. When i setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 ) then 10us corresponds to 10000 counts where i expect 5000.
So where does this doubly occur. Is there something which scales timer1 count by 2. I looked at datasheet but i couldn't find out anything.


Last edited by pokiko on Sat May 17, 2008 3:57 pm; edited 3 times in total
Indy



Joined: 16 May 2008
Posts: 24

View user's profile Send private message

PostPosted: Sat May 17, 2008 8:05 am     Reply with quote

What is your compiler version number?
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

PostPosted: Sat May 17, 2008 3:54 pm     Reply with quote

it is 4.020
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat May 17, 2008 4:06 pm     Reply with quote

The first releases of the v4 compiler were of very bad quality and only became more or less usable at version 4.030. I recommend you to upgrade to a newer version or use the older v3.249.
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

PostPosted: Sat May 17, 2008 4:26 pm     Reply with quote

so what about 4.049?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat May 17, 2008 5:07 pm     Reply with quote

4.049 is higher than 4.030, a reasonable stable version. Still getting the same bad results?

Can you post a short example program, including all #fuses, etc. So we can copy/paste it into our compiler?
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

ok
PostPosted: Sun May 18, 2008 1:45 pm     Reply with quote

Code:
#include <16F877A.H>
#device  ADC=10
#fuses HS, NOWDT, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=16000000)


#define maxPERIOD    9200   //nearly 10000
#define minPERIOD    4000



#int_TIMER0
void timer0_isr()

   set_timer0(255);
   set_timer1(0);
}

#int_CCP1
void pos_trig()
{
    output_high(pin_e0);   
    delay_us(1);
    output_low(pin_e0);
}


#int_CCP2
void neg_trig()
{
    output_high(pin_e0);   
    delay_us(1);
    output_low(pin_e0);
}


void main()
{
.......



         set_adc_channel(0);
         delay_us(10);
         ampereREAD = read_adc();         
           
         if(amperSET>ampereREAD)
         {
            CCP_1-=10;                               
            if (CCP_1<minPERIOD)
            {  CCP_1=minPERIOD;
               CCP_2=CCP_1+10000;                   
            }
            delay_ms(10);
         }
         else if(amperSET<ampereREAD)
         {
            CCP_1+=10;                                         
            if(CCP_1>maxPERIOD)
            {  CCP_1=maxPERIOD;
               CCP_2=CCP_1+10000;                   
            }
            delay_ms(10);
         }
         

}


void init_MCU(){
                    .............
          SETUP_TIMER_0(RTCC_EXT_L_TO_H | RTCC_DIV_1);           
            setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );
            setup_timer_2(T2_DISABLED,0,1);
            setup_CCP1( CCP_COMPARE_INT );
            setup_CCP2( CCP_COMPARE_INT );
           setup_CCP1( CCP_COMPARE_INT );
            setup_CCP2( CCP_COMPARE_INT );
}


Last edited by pokiko on Sun May 18, 2008 4:18 pm; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun May 18, 2008 3:01 pm     Reply with quote

The program is not complete and contains syntax errors (minPERYOD instead of minPERIOD).
How can we see from this program that your Timer1 is running twice as fast? I mean, which variables or what output should we check?

Please post a small (max. 1 page) and complete program. The program should contain all #fuses commands, etc. so that without modification we can copy/paste it into our compiler and run your example.
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

PostPosted: Mon May 19, 2008 2:38 am     Reply with quote

thanks

Last edited by pokiko on Wed May 21, 2008 12:48 am; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 19, 2008 5:30 pm     Reply with quote

Code:
setup_spi(SPI_SS_DISABLED);
SPI_SS_DISABLED may only be used on a slave! For a master this define equals the define SPI_CLK_DIV_16.
To disable the SPI hardware you should use use:
Code:
setup_spi(FALSE);


Code:
SETUP_ADC(ADC_CLOCK_DIV_2);
At 16MHz this is creating too short conversion times, check Table 11-1 in the datasheet. For 16MHz use DIV_32 or slower:
Code:
SETUP_ADC(ADC_CLOCK_DIV_32);


CCP_2 is not initialised at startup.

ckielstra wrote:
Please post a small (max. 1 page) and complete program.
The program is not small and does not compile because of a missing '}'. This means you never tested this version. Also there is an endless loop, again making this a useless test program.
The posted program contains a lot of irrelevant code. Please post a smaller and tested version.

You may think I'm lazy, and that's true, but there are also other reasons why I'm continuing to ask for a small and tested program:
- In making the program smaller there is a good chance you will find the problem yourself.
- I want to make sure I'm testing the exact same program you are using. Too many times in this forum the bug was found to be in the part that 'was left out for simplicity'.

When posting the new program also tell us what is wrong; what output do you expect and what are the results you see? How do you know these results are wrong? How did you measure this?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: tocki and timer1
PostPosted: Mon May 19, 2008 6:13 pm     Reply with quote

pokiko wrote:
When i setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 ) then 10us corresponds to 10000 counts where i expect 5000.
So where does this doubly occur. Is there something which scales timer1 count by 2.
I was looking at your original question again and am not sure if I understand what you mean.

You have configured Timer1 with a DIV_BY_8. So Timer1 ticks with:
16MHz / 4 / 8 = 1 tick every 2us.

Code:
CCP_2=CCP_1+10000;
Here you want to create a 10ms delay.

But 10.000 * 2us = 20ms.
Now what is the time you are measuring?
And what is your problem?
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

sorry,
PostPosted: Tue May 20, 2008 1:57 pm     Reply with quote

I am trying to write a rectifier program, controlling an 50hz ac signal. RA4/tocki input is connected to a
TLP-521 detects nearly zero cross point which is set to detect the signal's low to high point. As you mentioned,
2us*5000 counts have to correspond 10ms and 2us*10000 have to correspond 20us. But here i think 2us*10000 counts
coresponds to 10ms and 2us*20000 corresponds to 20us. Am i wrong?


Last edited by pokiko on Thu May 22, 2008 6:25 am; edited 3 times in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 20, 2008 2:35 pm     Reply with quote

ckielstra wrote:
Please post a small (max. 1 page) and complete program.
I'm wondering about the size of your pages... My pages contain 40, max 50 lines. Not over 340 lines.

I don't want to look into a large program like this, maybe I can post a small test program for you later this evening. If you are in a hurry you'll have to create a small test program yourself.
pokiko



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

PostPosted: Tue May 20, 2008 2:54 pm     Reply with quote

i am not in hurry. Thank you very much ckielstra.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 20, 2008 2:57 pm     Reply with quote

You appear to have identical code in many of the cases. You can greatly
reduce the size of your code by letting each identical case "fall through".
Example:
Code:
 switch(chKeyPad)
    {
         case '0':     
         case '1':     
         case '2':     
         case '3':     
         case '4':     
         case '5':     
         case '6':     
         case '7':     
         case '8':     
         case '9':     
            cursorValue[ind]=(int8)chKeyPad-'0';
            lcd_gotoxy(cursorPos[ind],1);
            printf(lcd_putc, "%c",chKeyPad );             
            printf(lcd_putc, "\b" );   
         break;
  }
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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