Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

rpm not displaied const wh_length=11;const pulse=36;const meter_pulse=(100/wh_length)*pulse;int meter=0;char speedshow[30];char RPMshow[30];

ana_cont

Newbie level 6
Joined
Jun 15, 2020
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
72
Code:
const wh_length=11;

const pulse=36;

const meter_pulse=(100/wh_length)*pulse;

int   meter=0;

char  speedshow[30];

char  RPMshow[30];

char  distanceshow[30];

int   count_puls=0;

int   speed ;

int   rpm=0;

void TMR0_init (void);

T1SE;

TF00;

   E11;

   GIE1;

unsigned  int_option_reg;

unsigned int_T1CKI;

void Interruption()

{



  if (TF00==1)

   {

    rpm = (1000/count_puls) * 60;

    speed = meter/count_puls;



   }



  TF00=0;



  if (TMR0IF_bit){

    TMR0IF_bit         = 0;

    TMR0  = 6;

    count_puls++;

  }



}

  void InitTimer0(){

  OPTION_REG         = 0x81;

  TMR0               = 6;

  INTCON             = 0xA0;



}





void main()

{

UART1_Init(115200);

trisb.b0=1;

trisd=0;

InitTimer0();

   t1con=0;



     while(1)



    {



    if (count_puls>=meter_pulse){

    meter++;

    count_puls=0;

    }

    sprinti(speedshow,"n0.val=%d",speed);

    UART1_Write_Text(speedshow);

    UART1_Write(0XFF);

    UART1_Write(0XFF);

    UART1_Write(0XFF);



    sprinti(RPMshow,"n1.val=%d",RPM);

    UART1_Write_Text(RPMshow);

    UART1_Write(0XFF);

    UART1_Write(0XFF);

    UART1_Write(0XFF);





    sprinti(distanceshow,"n2.val=%d",meter);

    UART1_Write_Text(distanceshow);

    UART1_Write(0XFF);

    UART1_Write(0XFF);

    UART1_Write(0XFF);









}

}
--- Updated ---

rpm compiled but not displaied
--- Updated ---

rpm compiled but not displaied
--- Updated ---

hi Ihave code compiled but not displaied.
const wh_length=11;

const pulse=36;

const meter_pulse=(100/wh_length)*pulse;

int meter=0;

char speedshow[30];

char RPMshow[30];

char distanceshow[30];

int count_puls=0;

int speed ;

int rpm=0;

void TMR0_init (void);

T1SE;

TF00;

E11;

GIE1;

unsigned int_option_reg;

unsigned int_T1CKI;

void Interruption()

{



if (TF00==1)

{

rpm = (1000/count_puls) * 60;

speed = meter/count_puls;



}



TF00=0;



if (TMR0IF_bit){

TMR0IF_bit = 0;

TMR0 = 6;

count_puls++;

}



}

void InitTimer0(){

OPTION_REG = 0x81;

TMR0 = 6;

INTCON = 0xA0;



}





void main()

{

UART1_Init(115200);

trisb.b0=1;

trisd=0;

InitTimer0();

t1con=0;



while(1)



{



if (count_puls>=meter_pulse){

meter++;

count_puls=0;

}

sprinti(speedshow,"n0.val=%d",speed);

UART1_Write_Text(speedshow);

UART1_Write(0XFF);

UART1_Write(0XFF);

UART1_Write(0XFF);



sprinti(RPMshow,"n1.val=%d",RPM);

UART1_Write_Text(RPMshow);

UART1_Write(0XFF);

UART1_Write(0XFF);

UART1_Write(0XFF);





sprinti(distanceshow,"n2.val=%d",meter);

UART1_Write_Text(distanceshow);

UART1_Write(0XFF);

UART1_Write(0XFF);

UART1_Write(0XFF);









}
 
Last edited:

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,416
Helped
286
Reputation
572
Reaction score
273
Trophy points
1,363
Location
France 01800
Activity points
9,918
hello,


what means this ?
T1SE;
TF00;
E11;
GIE1;

const wh_length=11;
const pulse=36;
const meter_pulse=(100/wh_length)*pulse;
// if all integer => result =324
// error (327.72-324)/324 => 1.15%

// define size ! of constant
Code:
const int wh_length=11;
const int pulse=36;
// a better arangement // (100*pulse)/wh_length  ;
const int meter_pulse= 327; //    327.72 if result in float format!
//error 0.22% if using  integer !
 

ana_cont

Newbie level 6
Joined
Jun 15, 2020
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
72
hello,


what means this ?
T1SE;
TF00;
E11;
GIE1;



// if all integer => result =324
// error (327.72-324)/324 => 1.15%

// define size ! of constant
Code:
const int wh_length=11;
const int pulse=36;
// a better arangement // (100*pulse)/wh_length  ;
const int meter_pulse= 327; //    327.72 if result in float format!
//error 0.22% if using  integer !
hi iam new in mikro c and not forget to say thank you for answer but still need help please
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,225
Helped
374
Reputation
748
Reaction score
370
Trophy points
83
Activity points
13,303
I'm not sure I understand what your question really is.
However, if you update a variable in an ISR but use it in the non-IST code, then it should be marked as 'volatile' - that tells the compiler that it is being altered somewhere else and don't try to cache its value.
You set 'count_puls' to zero but also have 'rpm = (1000/count_puls)*60;' which, under the right circumstances, will give you a 'divide by zero' error.
Also be very careful with integer division - as you saw in the first reply in this thread you can get some very unexpected results. In the code I quoted just above, if 'count_puls' is any value above 500, then 'rpm' will be zero. Any value from 251 to 500 will give 'rpm' the value 120; any value from 126 to 250 will have 'rpm' set to 240. I suspect that you need to either use floating point values or make that expression '60000/count_puls' but that has it's own dangers if you are using 16-bit signed integers - which for some microcontroller compilers is the default (as 60000 cannot be represented - it can as an unsigned 16-bit integer but that may well require a cast).
Susan
 

ana_cont

Newbie level 6
Joined
Jun 15, 2020
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
72
Hi I will try it thank you
hello,


what means this ?
T1SE;
TF00;
E11;
GIE1;



// if all integer => result =324
// error (327.72-324)/324 => 1.15%

// define size ! of constant
Code:
const int wh_length=11;
const int pulse=36;
// a better arangement // (100*pulse)/wh_length  ;
const int meter_pulse= 327; //    327.72 if result in float format!
//error 0.22% if using  integer !
hi i will try and be back
I'm not sure I understand what your question really is.
However, if you update a variable in an ISR but use it in the non-IST code, then it should be marked as 'volatile' - that tells the compiler that it is being altered somewhere else and don't try to cache its value.
You set 'count_puls' to zero but also have 'rpm = (1000/count_puls)*60;' which, under the right circumstances, will give you a 'divide by zero' error.
Also be very careful with integer division - as you saw in the first reply in this thread you can get some very unexpected results. In the code I quoted just above, if 'count_puls' is any value above 500, then 'rpm' will be zero. Any value from 251 to 500 will give 'rpm' the value 120; any value from 126 to 250 will have 'rpm' set to 240. I suspect that you need to either use floating point values or make that expression '60000/count_puls' but that has it's own dangers if you are using 16-bit signed integers - which for some microcontroller compilers is the default (as 60000 cannot be represented - it can as an unsigned 16-bit integer but that may well require a cast).
Susan
i will try floating for devision and be back thank you
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,225
Helped
374
Reputation
748
Reaction score
370
Trophy points
83
Activity points
13,303
Be careful about using floating point on some of the smaller MCUs that do all floating point operations using library functions - these can be considerably slower than the alternative I mention. You are probably better off using 'int32_t' (or whatever your compiler has) for variables and constants written as '60000ul' (again however your compiler expresses 32-bit constants).
Also think through the implications of whichever approach you go for. Use pencil and paper go through the full domain (especially edge cases) of values and also read up on exactly when and how your compiler promotes integers so that you can be sure that you are getting results as you expect.
Susan
 

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top