|
|
View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
How to calculate process time? |
Posted: Mon Jun 30, 2003 1:43 pm |
|
|
Hi there,
I wrote a firmware for pic but i cant calculate right time.I need to send a string to computer via COM2 *10* times per second.But i cant find (or fix it to send 10 tps) the solution.
So can you advice me how to do it? Should i calculate all calculation times of all commands ???
No_Fear
#include <16F877A.h>
#include <string.h>
#use delay(clock=4000000)
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main() {
int v1,v2,v3,v4,v5,v6;
char ON;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x00);
ON = 1;
printf("3A75D5FA\r\n");
while (1)
{
set_adc_channel( 0 );delay_us(10);v1 = read_adc();
set_adc_channel( 1 );delay_us(10);v2 = read_adc();
set_adc_channel( 4 );delay_us(10);v3 = read_adc();
set_adc_channel( 5 );delay_us(10);v4 = read_adc();
set_adc_channel( 6 );delay_us(10);v5 = read_adc();
set_adc_channel( 7 );delay_us(10);v6 = read_adc();
printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
delay_ms(????); //I know i should change this to rite value
// but how to do this? What is the best value for 10 times per
//second????
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515654 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: How to calculate process time? |
Posted: Mon Jun 30, 2003 2:07 pm |
|
|
<font face="Courier New" size=-1>:=Hi there,
:=
:=I wrote a firmware for pic but i cant calculate right time.I need to send a string to computer via COM2 *10* times per second.But i cant find (or fix it to send 10 tps) the solution.
:=So can you advice me how to do it? Should i calculate all calculation times of all commands ???
:=
:=No_Fear
:=
:=#include <16F877A.h>
:=#include <string.h>
:=#use delay(clock=4000000)
:=#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=
:=
:=void main() {
:=
:=int v1,v2,v3,v4,v5,v6;
:=char ON;
:=
:= setup_adc_ports(ALL_ANALOG);
:= setup_adc(ADC_CLOCK_INTERNAL);
:= setup_psp(PSP_DISABLED);
:= setup_spi(FALSE);
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:= setup_timer_1(T1_DISABLED);
:= setup_timer_2(T2_DISABLED,0,1);
:= setup_comparator(NC_NC_NC_NC);
:= setup_vref(FALSE);
:= set_tris_d(0x00);
:= ON = 1;
:=
:=printf("3A75D5FA\r\n");
:=
:=while (1)
:={
:=
:= set_adc_channel( 0 );delay_us(10);v1 = read_adc();
:= set_adc_channel( 1 );delay_us(10);v2 = read_adc();
:= set_adc_channel( 4 );delay_us(10);v3 = read_adc();
:= set_adc_channel( 5 );delay_us(10);v4 = read_adc();
:= set_adc_channel( 6 );delay_us(10);v5 = read_adc();
:= set_adc_channel( 7 );delay_us(10);v6 = read_adc();
:=
:= printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
:=
:= if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
:=
:= v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
:= delay_ms(????); //I know i should change this to rite value
:=// but how to do this? What is the best value for 10 times per
:=//second????
:=
:=}
:=
:=}
First assign the location of Timer_Interupt_Flag
#bit Timer_Interupt_Flag = xxx.x
Forget about using delay_mS. Computation times can vary. Setup one of the timers to overflow every .1 seconds. The project wizard is good way to solve timer settings. Then where you want to put delay_mS put this
while(!Timer_Interupt_Flag);
Timer_Interupt_Flag=0;
This will gate your program on a 100mS time base.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515655 |
|
|
No_Fear Guest
|
Re: How to calculate process time? |
Posted: Mon Jun 30, 2003 2:47 pm |
|
|
Thanks for your reply, but i couldnt see Timer_Interrupt_Flag in ccs compiler?? Is it TOIF? If so i havent got any idea how it works?Could you show it in my code please? I will search how to use TOIF on code.
By the way sometimes pic sends garbage characters with this code it send 0xUF for example.I check all of things which is described on CCS Manual Page 185 everything is ok but still sends garbage characters (especially adc input changes fastly)
No_Fear
:=<font face="Courier New" size=-1>:=Hi there,
:=:=
:=:=I wrote a firmware for pic but i cant calculate right time.I need to send a string to computer via COM2 *10* times per second.But i cant find (or fix it to send 10 tps) the solution.
:=:=So can you advice me how to do it? Should i calculate all calculation times of all commands ???
:=:=
:=:=No_Fear
:=:=
:=:=#include <16F877A.h>
:=:=#include <string.h>
:=:=#use delay(clock=4000000)
:=:=#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
:=:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=:=
:=:=
:=:=void main() {
:=:=
:=:=int v1,v2,v3,v4,v5,v6;
:=:=char ON;
:=:=
:=:= setup_adc_ports(ALL_ANALOG);
:=:= setup_adc(ADC_CLOCK_INTERNAL);
:=:= setup_psp(PSP_DISABLED);
:=:= setup_spi(FALSE);
:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:= setup_timer_1(T1_DISABLED);
:=:= setup_timer_2(T2_DISABLED,0,1);
:=:= setup_comparator(NC_NC_NC_NC);
:=:= setup_vref(FALSE);
:=:= set_tris_d(0x00);
:=:= ON = 1;
:=:=
:=:=printf("3A75D5FA\r\n");
:=:=
:=:=while (1)
:=:={
:=:=
:=:= set_adc_channel( 0 );delay_us(10);v1 = read_adc();
:=:= set_adc_channel( 1 );delay_us(10);v2 = read_adc();
:=:= set_adc_channel( 4 );delay_us(10);v3 = read_adc();
:=:= set_adc_channel( 5 );delay_us(10);v4 = read_adc();
:=:= set_adc_channel( 6 );delay_us(10);v5 = read_adc();
:=:= set_adc_channel( 7 );delay_us(10);v6 = read_adc();
:=:=
:=:= printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
:=:=
:=:= if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
:=:=
:=:= v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
:=:= delay_ms(????); //I know i should change this to rite value
:=:=// but how to do this? What is the best value for 10 times per
:=:=//second????
:=:=
:=:=}
:=:=
:=:=}
:=First assign the location of Timer_Interupt_Flag
:=#bit Timer_Interupt_Flag = xxx.x
:=
:=Forget about using delay_mS. Computation times can vary. Setup one of the timers to overflow every .1 seconds. The project wizard is good way to solve timer settings. Then where you want to put delay_mS put this
:=
:=while(!Timer_Interupt_Flag);
:=Timer_Interupt_Flag=0;
:=
:=This will gate your program on a 100mS time base.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515657 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: How to calculate process time? |
Posted: Mon Jun 30, 2003 3:13 pm |
|
|
<font face="Courier New" size=-1>:=Thanks for your reply, but i couldnt see Timer_Interrupt_Flag in ccs compiler?? Is it TOIF? If so i havent got any idea how it works?Could you show it in my code please? I will search how to use TOIF on code.
:=
:=By the way sometimes pic sends garbage characters with this code it send 0xUF for example.I check all of things which is described on CCS Manual Page 185 everything is ok but still sends garbage characters (especially adc input changes fastly)
:=
:=No_Fear
:=
:=:=<font face="Courier New" size=-1>:=Hi there,
:=:=:=
:=:=:=I wrote a firmware for pic but i cant calculate right time.I need to send a string to computer via COM2 *10* times per second.But i cant find (or fix it to send 10 tps) the solution.
:=:=:=So can you advice me how to do it? Should i calculate all calculation times of all commands ???
:=:=:=
:=:=:=No_Fear
:=:=:=
:=:=:=#include <16F877A.h>
:=:=:=#include <string.h>
:=:=:=#use delay(clock=4000000)
:=:=:=#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
:=:=:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=:=:=
:=:=:=
:=:=:=void main() {
:=:=:=
:=:=:=int v1,v2,v3,v4,v5,v6;
:=:=:=char ON;
:=:=:=
:=:=:= setup_adc_ports(ALL_ANALOG);
:=:=:= setup_adc(ADC_CLOCK_INTERNAL);
:=:=:= setup_psp(PSP_DISABLED);
:=:=:= setup_spi(FALSE);
:=:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:=:= setup_timer_1(T1_DISABLED);
:=:=:= setup_timer_2(T2_DISABLED,0,1);
:=:=:= setup_comparator(NC_NC_NC_NC);
:=:=:= setup_vref(FALSE);
:=:=:= set_tris_d(0x00);
:=:=:= ON = 1;
:=:=:=
:=:=:=printf("3A75D5FA\r\n");
:=:=:=
:=:=:=while (1)
:=:=:={
:=:=:=
:=:=:= set_adc_channel( 0 );delay_us(10);v1 = read_adc();
:=:=:= set_adc_channel( 1 );delay_us(10);v2 = read_adc();
:=:=:= set_adc_channel( 4 );delay_us(10);v3 = read_adc();
:=:=:= set_adc_channel( 5 );delay_us(10);v4 = read_adc();
:=:=:= set_adc_channel( 6 );delay_us(10);v5 = read_adc();
:=:=:= set_adc_channel( 7 );delay_us(10);v6 = read_adc();
:=:=:=
:=:=:= printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
:=:=:=
:=:=:= if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
:=:=:=
:=:=:= v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
:=:=:= delay_ms(????); //I know i should change this to rite value
:=:=:=// but how to do this? What is the best value for 10 times per
:=:=:=//second????
:=:=:=
:=:=:=}
:=:=:=
:=:=:=}
:=:=First assign the location of Timer_Interupt_Flag
:=:=#bit Timer_Interupt_Flag = xxx.x
:=:=
:=:=Forget about using delay_mS. Computation times can vary. Setup one of the timers to overflow every .1 seconds. The project wizard is good way to solve timer settings. Then where you want to put delay_mS put this
:=:=
:=:=while(!Timer_Interupt_Flag);
:=:=Timer_Interupt_Flag=0;
:=:=
:=:=This will gate your program on a 100mS time base.</font>
Look at the chart on page 56 of the data sheet. TMR1IF is the bit you should watch for. It means the timer has overflowed. Thats why you have to clear it when it overflows.
#bit Timer1_Interupt_Flag = 0C.0
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
This will work on a time base of 131mS as timer 1 is set up with a crystle of 4mHz.
Right after clearing the overflow this
set_timer1(15508);
Will advance the counter and make it just right on the .1S interval.
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515658 |
|
|
No_Fear Guest
|
Re: How to calculate process time? |
Posted: Mon Jun 30, 2003 3:59 pm |
|
|
I noticed that i told my problem wrongly.Because I only want to send string in every 100 ms to pc.So i want device to read adc channels continously but send "printf ........" in every 100 ms.I couldnt compile the line
#bit Timer1_Interupt_Flag = 0C.0 By the way, i told that i have no experience with ccs c compiler+handle interrupts, i cant understand it.So can you please show it with real code instead of pseudo code? Or better could you edit my code? I'm sorry i shouldnt want you to do it but i'm very bad at handling interrupts.
No_Fear
:=<font face="Courier New" size=-1>:=Thanks for your reply, but i couldnt see Timer_Interrupt_Flag in ccs compiler?? Is it TOIF? If so i havent got any idea how it works?Could you show it in my code please? I will search how to use TOIF on code.
:=:=
:=:=By the way sometimes pic sends garbage characters with this code it send 0xUF for example.I check all of things which is described on CCS Manual Page 185 everything is ok but still sends garbage characters (especially adc input changes fastly)
:=:=
:=:=No_Fear
:=:=
:=:=:=<font face="Courier New" size=-1>:=Hi there,
:=:=:=:=
:=:=:=:=I wrote a firmware for pic but i cant calculate right time.I need to send a string to computer via COM2 *10* times per second.But i cant find (or fix it to send 10 tps) the solution.
:=:=:=:=So can you advice me how to do it? Should i calculate all calculation times of all commands ???
:=:=:=:=
:=:=:=:=No_Fear
:=:=:=:=
:=:=:=:=#include <16F877A.h>
:=:=:=:=#include <string.h>
:=:=:=:=#use delay(clock=4000000)
:=:=:=:=#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
:=:=:=:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=:=:=:=
:=:=:=:=
:=:=:=:=void main() {
:=:=:=:=
:=:=:=:=int v1,v2,v3,v4,v5,v6;
:=:=:=:=char ON;
:=:=:=:=
:=:=:=:= setup_adc_ports(ALL_ANALOG);
:=:=:=:= setup_adc(ADC_CLOCK_INTERNAL);
:=:=:=:= setup_psp(PSP_DISABLED);
:=:=:=:= setup_spi(FALSE);
:=:=:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:=:=:= setup_timer_1(T1_DISABLED);
:=:=:=:= setup_timer_2(T2_DISABLED,0,1);
:=:=:=:= setup_comparator(NC_NC_NC_NC);
:=:=:=:= setup_vref(FALSE);
:=:=:=:= set_tris_d(0x00);
:=:=:=:= ON = 1;
:=:=:=:=
:=:=:=:=printf("3A75D5FA\r\n");
:=:=:=:=
:=:=:=:=while (1)
:=:=:=:={
:=:=:=:=
:=:=:=:= set_adc_channel( 0 );delay_us(10);v1 = read_adc();
:=:=:=:= set_adc_channel( 1 );delay_us(10);v2 = read_adc();
:=:=:=:= set_adc_channel( 4 );delay_us(10);v3 = read_adc();
:=:=:=:= set_adc_channel( 5 );delay_us(10);v4 = read_adc();
:=:=:=:= set_adc_channel( 6 );delay_us(10);v5 = read_adc();
:=:=:=:= set_adc_channel( 7 );delay_us(10);v6 = read_adc();
:=:=:=:=
:=:=:=:= printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
:=:=:=:=
:=:=:=:= if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
:=:=:=:=
:=:=:=:= v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
:=:=:=:= delay_ms(????); //I know i should change this to rite value
:=:=:=:=// but how to do this? What is the best value for 10 times per
:=:=:=:=//second????
:=:=:=:=
:=:=:=:=}
:=:=:=:=
:=:=:=:=}
:=:=:=First assign the location of Timer_Interupt_Flag
:=:=:=#bit Timer_Interupt_Flag = xxx.x
:=:=:=
:=:=:=Forget about using delay_mS. Computation times can vary. Setup one of the timers to overflow every .1 seconds. The project wizard is good way to solve timer settings. Then where you want to put delay_mS put this
:=:=:=
:=:=:=while(!Timer_Interupt_Flag);
:=:=:=Timer_Interupt_Flag=0;
:=:=:=
:=:=:=This will gate your program on a 100mS time base.</font>
:=
:=
:=Look at the chart on page 56 of the data sheet. TMR1IF is the bit you should watch for. It means the timer has overflowed. Thats why you have to clear it when it overflows.
:=
:=#bit Timer1_Interupt_Flag = 0C.0
:=
:=setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
:=
:=This will work on a time base of 131mS as timer 1 is set up with a crystle of 4mHz.
:=
:=Right after clearing the overflow this
:=
:=set_timer1(15508);
:=
:=Will advance the counter and make it just right on the .1S interval.
:=
:=</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515665 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: How to calculate process time? |
Posted: Tue Jul 01, 2003 8:21 am |
|
|
This should work
Fear
#include <16F877A.h>
#include
#use delay(clock=4000000)
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#bit Timer1_Interupt_Flag = 0x0C.0
void main() {
int v1,v2,v3,v4,v5,v6;
char ON;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x00);
ON = 1;
printf("3A75D5FA\r\n");
while (1)
{
set_adc_channel( 0 );delay_us(10);v1 = read_adc();
set_adc_channel( 1 );delay_us(10);v2 = read_adc();
set_adc_channel( 4 );delay_us(10);v3 = read_adc();
set_adc_channel( 5 );delay_us(10);v4 = read_adc();
set_adc_channel( 6 );delay_us(10);v5 = read_adc();
set_adc_channel( 7 );delay_us(10);v6 = read_adc();
while(!Timer1_Interupt_Flag );
Timer1_Interupt_Flag =0;
set_timer1(15508);
printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515682 |
|
|
No_Fear Guest
|
Re: How to calculate process time? |
Posted: Fri Jul 04, 2003 2:25 pm |
|
|
:=This should work
:=
:=Fear
:=
:=#include <16F877A.h>
:=#include
:=#use delay(clock=4000000)
Excuse me, i am a bit late to thank you for your help. :)
No_Fear
:=#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=#bit Timer1_Interupt_Flag = 0x0C.0
:=
:=
:=
:=void main() {
:=
:=int v1,v2,v3,v4,v5,v6;
:=char ON;
:=
:=setup_adc_ports(ALL_ANALOG);
:=setup_adc(ADC_CLOCK_INTERNAL);
:=setup_psp(PSP_DISABLED);
:=setup_spi(FALSE);
:=setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
:=setup_timer_2(T2_DISABLED,0,1);
:=setup_comparator(NC_NC_NC_NC);
:=setup_vref(FALSE);
:=set_tris_d(0x00);
:=ON = 1;
:=
:=printf("3A75D5FA\r\n");
:=
:=while (1)
:={
:=
:=set_adc_channel( 0 );delay_us(10);v1 = read_adc();
:=set_adc_channel( 1 );delay_us(10);v2 = read_adc();
:=set_adc_channel( 4 );delay_us(10);v3 = read_adc();
:=set_adc_channel( 5 );delay_us(10);v4 = read_adc();
:=set_adc_channel( 6 );delay_us(10);v5 = read_adc();
:=set_adc_channel( 7 );delay_us(10);v6 = read_adc();
:=
:=
:=while(!Timer1_Interupt_Flag );
:=Timer1_Interupt_Flag =0;
:=set_timer1(15508);
:=
:=printf("Value:\%2X/\%2X/\%2X/\%2X/\%2X/\%2X!",v1,v2,v3,v4,v5,v6);
:=
:=if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}
:=
:=v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
:=
:=}
:=
:=}
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515742 |
|
|
|
|
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
|