Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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];

Status
Not open for further replies.

ana_cont

Junior Member level 2
Junior Member level 2
Joined
Jun 15, 2020
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
11
Activity points
128
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:

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 !
 
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
 

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
 

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
 

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
 

    ana_cont

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top