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

how anticipate the good time on overflow interrupt with good

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







how anticipate the good time on overflow interrupt with good
PostPosted: Thu Jan 30, 2003 12:42 pm     Reply with quote

Hello,

I note this with overflow on timer0.
overflow measure theory set_timer0
262s 302s RTCC/2 131 count
65.5ms 33ms RTCC/128 256 count
512s 552s RTCC/2 256 count
8.2ms 8.2ms RTCC/32 256 count
4.2ms 4.26ms RTCC/32 131 count

quartz 4Mhz
theory=((4000000)/4/prescalair)*Xcount

how anticipate the good time on overflow interrupt with good frequency quartz
___________________________
This message was ported from CCS's old forum
Original Post ID: 11136
PCM programmer



Joined: 06 Sep 2003
Posts: 20140

View user's profile Send private message

Re: how anticipate the good time on overflow interrupt....
PostPosted: Thu Jan 30, 2003 12:51 pm     Reply with quote

:=Hello,
:=
:=I note this with overflow on timer0.
:=overflow measure theory set_timer0
:=262s 302s RTCC/2 131 count
:=65.5ms 33ms RTCC/128 256 count
:=512s 552s RTCC/2 256 count
:=8.2ms 8.2ms RTCC/32 256 count
:=4.2ms 4.26ms RTCC/32 131 count
:=
:=quartz 4Mhz
:=theory=((4000000)/4/prescalair)*Xcount
----------------------------------------------------

Please post your C code that shows how you measured this.

Also, did you measure the pulse interval with an oscilloscope
or logic analyzer.

I ask these questions because I will then try to test
your results.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11137
nanard-bis
Guest







Re: how anticipate the good time on overflow interrupt....
PostPosted: Fri Jan 31, 2003 5:17 am     Reply with quote

Another measure,

with timer1 16 bit quartz 4MHz.
set_timer1(32678)
measure:0.5s theory:0.263s
set_timer1(65410)
measure:1ms theory:1ms
set_timer1(53035)
measure:0.108 theory:0.1s

with this code:
/*****************************************************************************/
/*Cration d'horloge*/
/*timer0 fixe le rapport cyclique */
/*timer1 fixe la periode*/
/*16F877 RC 4MHz*/
/*******************/

#include <16F877.H>
#device PIC16F877 10 bit ADC=10/*declaration pour lire ADRESH et ADRESL*/
#use delay (clock=4000000)/*declaration du quartz du c*/
#byte trisb = 0x86
#byte portb = 0x06
#byte option_reg = 0x81
#byte intcon = 0x0b
#bit toif = 0x0b.2
#byte tmr0 = 0x01
#byte trisc = 0x87
#byte portc = 0x07
#byte MSB = 0x7A/*adresse registre resultat tempon MSB de l'ADC*/
#byte LSB = 0x7B/*adresse registre resultat tempon LSB de l'ADC*/
#bit RC0 = 0x07.0
#bit RC1 = 0x07.1
#bit RC2 = 0x07.2
#bit RC3 = 0x07.3
#bit RC4 = 0x07.4
#bit RC5 = 0x07.5
#bit RC7 = 0x07.7/*pin RX*/
#bit RC6 = 0x07.6/*pin TX*/

#INT_TIMER1
void wave_timer(){
RC1 = 1;/*flag interrupt for scope*/
set_timer1(32678);
delay_us(260);
RC1 = 0;
}

int T16;
int T;
main()
{
TRISC = 0x00;/*Port C en OUT*/
PORTC = 0x00;/*initialise le portC*/
T16 = 32678;
T = 125;
set_timer1(T16);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
do
{
}
while( 1 );
}

measure in the first E-mail:

I note this with overflow on timer0.
overflow measure theory set_timer0
262s 302s RTCC/2 131 count
65.5ms 33ms RTCC/128 256 count
512s 552s RTCC/2 256 count
8.2ms 8.2ms RTCC/32 256 count
4.2ms 4.26ms RTCC/32 131 count

with this code:

/*****************************************************************************/
/*Cration d'horloge*/
/*timer0 fixe le rapport cyclique */
/*timer1 fixe la periode*/
/*16F876 RC 4MHz*/
/*******************/

#include <16F876.H>
#device PIC16F877 10 bit ADC=10/*declaration pour lire ADRESH et ADRESL*/
#use delay (clock=1000000)/*declaration du quartz du c*/
#byte trisb = 0x86
#byte portb = 0x06
#byte option_reg = 0x81
#byte intcon = 0x0b
#bit toif = 0x0b.2
#byte tmr0 = 0x01
#byte trisc = 0x87
#byte portc = 0x07
#byte MSB = 0x7A/*adresse registre resultat tempon MSB de l'ADC*/
#byte LSB = 0x7B/*adresse registre resultat tempon LSB de l'ADC*/
#bit RC0 = 0x07.0
#bit RC1 = 0x07.1
#bit RC2 = 0x07.2
#bit RC3 = 0x07.3
#bit RC4 = 0x07.4
#bit RC5 = 0x07.5
#bit RC7 = 0x07.7/*pin RX*/
#bit RC6 = 0x07.6/*pin TX*/

#int_rtcc
isr(){
RC0 = 1;
set_timer0(125);
RC0 = 0;
}

main()
{
TRISC = 0x00;/*Port C en OUT*/
PORTC = 0x00;/*initialise le portC*/
set_timer0(125);
setup_timer_0(RTCC_DIV_32|RTCC_INTERNAL);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
do
{
}
while( 1 );
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11150
R.J.Hamlett
Guest







Re: how anticipate the good time on overflow interrupt....
PostPosted: Fri Jan 31, 2003 7:10 am     Reply with quote

:=Another measure,
:=
:=with timer1 16 bit quartz 4MHz.
:=set_timer1(32678)
:=measure:0.5s theory:0.263s
:=set_timer1(65410)
:=measure:1ms theory:1ms
:=set_timer1(53035)
:=measure:0.108 theory:0.1s
:=
:=with this code:
:=/*****************************************************************************/
:=/*Cration d'horloge*/
:=/*timer0 fixe le rapport cyclique */
:=/*timer1 fixe la periode*/
:=/*16F877 RC 4MHz*/
:=/*******************/
:=
:=#include <16F877.H>
:=#device PIC16F877 10 bit ADC=10/*declaration pour lire ADRESH et ADRESL*/
:=#use delay (clock=4000000)/*declaration du quartz du c*/
:=#byte trisb = 0x86
:=#byte portb = 0x06
:=#byte option_reg = 0x81
:=#byte intcon = 0x0b
:=#bit toif = 0x0b.2
:=#byte tmr0 = 0x01
:=#byte trisc = 0x87
:=#byte portc = 0x07
:=#byte MSB = 0x7A/*adresse registre resultat tempon MSB de l'ADC*/
:=#byte LSB = 0x7B/*adresse registre resultat tempon LSB de l'ADC*/
:=#bit RC0 = 0x07.0
:=#bit RC1 = 0x07.1
:=#bit RC2 = 0x07.2
:=#bit RC3 = 0x07.3
:=#bit RC4 = 0x07.4
:=#bit RC5 = 0x07.5
:=#bit RC7 = 0x07.7/*pin RX*/
:=#bit RC6 = 0x07.6/*pin TX*/
:=
:=#INT_TIMER1
:=void wave_timer(){
:=RC1 = 1;/*flag interrupt for scope*/
:=set_timer1(32678);
:=delay_us(260);
:=RC1 = 0;
:=}
:=
:=int T16;
:=int T;
:=main()
:={
:=TRISC = 0x00;/*Port C en OUT*/
:=PORTC = 0x00;/*initialise le portC*/
:=T16 = 32678;
:=T = 125;
:=set_timer1(T16);
:=setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
:=enable_interrupts(GLOBAL);
:=enable_interrupts(INT_TIMER1);
:=do
:={
:=}
:=while( 1 );
:=}
:=
:=measure in the first E-mail:
:=
:=I note this with overflow on timer0.
:=overflow measure theory set_timer0
:=262s 302s RTCC/2 131 count
:=65.5ms 33ms RTCC/128 256 count
:=512s 552s RTCC/2 256 count
:=8.2ms 8.2ms RTCC/32 256 count
:=4.2ms 4.26ms RTCC/32 131 count
:=
:=with this code:
:=
:=/*****************************************************************************/
:=/*Cration d'horloge*/
:=/*timer0 fixe le rapport cyclique */
:=/*timer1 fixe la periode*/
:=/*16F876 RC 4MHz*/
:=/*******************/
:=
:=#include <16F876.H>
:=#device PIC16F877 10 bit ADC=10/*declaration pour lire ADRESH et ADRESL*/
:=#use delay (clock=1000000)/*declaration du quartz du c*/
:=#byte trisb = 0x86
:=#byte portb = 0x06
:=#byte option_reg = 0x81
:=#byte intcon = 0x0b
:=#bit toif = 0x0b.2
:=#byte tmr0 = 0x01
:=#byte trisc = 0x87
:=#byte portc = 0x07
:=#byte MSB = 0x7A/*adresse registre resultat tempon MSB de l'ADC*/
:=#byte LSB = 0x7B/*adresse registre resultat tempon LSB de l'ADC*/
:=#bit RC0 = 0x07.0
:=#bit RC1 = 0x07.1
:=#bit RC2 = 0x07.2
:=#bit RC3 = 0x07.3
:=#bit RC4 = 0x07.4
:=#bit RC5 = 0x07.5
:=#bit RC7 = 0x07.7/*pin RX*/
:=#bit RC6 = 0x07.6/*pin TX*/
:=
:=#int_rtcc
:=isr(){
:=RC0 = 1;
:=set_timer0(125);
:=RC0 = 0;
:=}
:=
:=main()
:={
:=TRISC = 0x00;/*Port C en OUT*/
:=PORTC = 0x00;/*initialise le portC*/
:=set_timer0(125);
:=setup_timer_0(RTCC_DIV_32|RTCC_INTERNAL);
:=enable_interrupts(GLOBAL);
:=enable_interrupts(INT_TIMER0);
:=do
:={
:=}
:=while( 1 );
:=}

As I have allready pointed out to you, when you asked this question before, using 'set_timer', inside the interrupt, does not occur, till _after_ the interrupt hardware latency, and the time needed for the int_global routine to save all the registers (probably about 25 instruction times).
This is why your times differ by a small amount.
Add the offset you require to the timer register, don't use the direct 'set' like this.
The odd result on 32768, is unexpected. The compiler does correctly load 0x8000 int the timer registers with this. I'd try again, or look at the assembler code, and verify that the compiler is correctly taking the constant as a long (the behaviour you have, is roughly what I'd expect, if it was treating the constant as a short, and then expanding the low byte as a zero, into both the timer registers...).
You are doing a very dangerous thing, by using 'delay_us', inside the interrupt. If you need this sort of delayed pulse response, have a monitor outside the interrupt loop, and change the pulse there (using any routine inside the interrupt, implies that this routine, may have interrupts disabled if called outside the interrupt, resulting in massive delays in interrupt response...).
You also should recognise that your measured times will probably not be accurate. If you are using a digital storage scope, these will be in error, by up to one bit time (at the sampling speed of the scope, for the timebase selected).

Try:

int16 timer_counter;
#locate timer_counter=0x0E

#bit RC0 = 0x07.0
#bit RC1 = 0x07.1

#INT_TIMER1
void wave_timer(){
RC1 = 1;/*flag interrupt for scope*/
timer_counter+=53037l;
//Calculated value to add, is (65536-(time/8E-6))+1 (to allow for the clock
//increment that will occur during the addition.
RC1 = 0;
}

void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
set_timer1(65530l);
while(1)
;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11155
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: how anticipate the good time on overflow interrupt with
PostPosted: Fri Jan 31, 2003 12:36 pm     Reply with quote

:=Hello,
:=
:=I note this with overflow on timer0.
:=overflow measure theory set_timer0
:=262s 302s RTCC/2 131 count
:=65.5ms 33ms RTCC/128 256 count
:=512s 552s RTCC/2 256 count
:=8.2ms 8.2ms RTCC/32 256 count
:=4.2ms 4.26ms RTCC/32 131 count
:=
:=quartz 4Mhz
:=theory=((4000000)/4/prescalair)*Xcount
:=
:=how anticipate the good time on overflow interrupt with good frequency quartz

For maximum accuracy you can do something like this from main. This should be accurate to a few instruction cycles.

Toggel test pin
set_timer1( ChanAtimeout );
bit_clear( *0xF9E, 0 );

Then wait for the interupt flag to be set from timer overflow

while(bit_Test( *0xF9E, 0 )==0);

toggel test pin
___________________________
This message was ported from CCS's old forum
Original Post ID: 11169
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