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

Program stopping in function #use delay ()
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jacktaylor



Joined: 02 Sep 2017
Posts: 70

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

Friends
PostPosted: Sun Jan 28, 2018 12:50 pm     Reply with quote

Hello friends. Someone ask me to explain why the program below does not pin the RA0 oscillate at zero and one?
Code:

#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
#use fast_io(a)


void main()
{
   

while(TRUE);
    {
       
   output_drive(PIN_A0);    // this will set the tris bit for that pin to 0 (input)
   output_low(PIN_A0);     
   
   delay_us(50500);

   output_float(PIN_A0);    // this will set the tris bit for that pin to 1
   (output)
   output_high(PIN_A0);
   delay_us(50500);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 13526

View user's profile Send private message

PostPosted: Sun Jan 28, 2018 1:02 pm     Reply with quote

It'll need a pull up resistor. It is only ever driven low.
Also 50.5 seconds between changes. Not exactly going to be rapid changes....

We are also back to incorrect comments:
Code:

output_float(PIN_A0); // this will set the tris bit for that pin to 1 (output)
//Input not output.
temtronic



Joined: 01 Jul 2010
Posts: 6249
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 28, 2018 2:53 pm     Reply with quote

Your original posting was about using the DS18B20 sensor, this last proram doesn't use it, so you should create a NEW posting about it.
As Mr T points out that pin requires a pullup resistor. A4 is a 'special' pin on the ancient 877. Typically a 4K7 can be used if running a VDD of 5V.
This is why it's important to read the datasheet, as not all pins are created equal.
Also you need to know what peripherals are available on a pin by pin basis and generaly speaking, you need to turn off (disable) any/all perhipherals you are not using.

As for your original post, there is working DS18B20 code in the 'code library'. Also if you search using the term 'ds18b20' you'll get several 'hits'.
Jay
jacktaylor



Joined: 02 Sep 2017
Posts: 70

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

Temtronic_ Program for DS18B20 pin does not oscillate
PostPosted: Mon Jan 29, 2018 8:15 am     Reply with quote

People for now do not want to use a library already ready. I need to understand the operation of the device and also the CCS program for this temperature sensor ... This code as I mentioned several times, has already run on another compiler that I believe can not quote or post his code here. I would like to make this program run on CCS, but I have difficulties with this. My original post is from DS18B20, and still, I did this test program but the code does not run because the output of the pin is not oscillating.
Code:

#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
#use fast_io(a)


void main()
{
   

while(TRUE);
    {
       
   output_drive(PIN_A0);    // this will set the tris bit for that pin to 0 
   output_low(PIN_A0);     
   
   delay_us(50500);

   output_float(PIN_A0);    // this will set the tris bit for that pin to 1
   (output)
   output_high(PIN_A0);
   delay_us(50500);
   }
}
I have used as already mentioned in comments above the datasheet of the component, and the Proteus oscilloscope connected in the output PIN_A4 the MPLAB IDE V8.92. In the design there is the 4.7K resistor defined in the datasheet of the DS18B20
Could someone help me understand why in the program below the output does not oscillate the PIN_A0. The pullup resistor takes the pin to high level and output_drive (PIN_A4); output_low (PIN_A4); takes PIN_A0 to low.

Code:
/* Library for DSb80b20 sensor. To start the reading and writing it is necessary to send 0 to the sensor data pin, this reset wakes the sensor and
and informs of the need for reading */

#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay(clock = 4000000)
#use fast_io(a)
#use fast_io(b)


void escreve_zero();
void escreve_um();
void reset();
char leitura();
void escreve_comando (unsigned int comando);
unsigned int ler_ler_memDS18();
unsigned int ler_tempDS18();

//Funcao de tempos Delays

void time15us();
void time70us();
void time500us(); //The minimum time stated in the datasheet is 480us
void time750ms();

void main()

{
    //set_tris_a(0x00);     
    set_tris_b(0x00); //TRISB = 0x00;
     set_tris_c(0x00); //TRISC = 0x00;
    output_b(0x00);
     output_c(0x00);
   
   while(1)
     {
          unsigned int temp = ler_tempDS18();
          output_b (temp);   //PORTB= temp;
          output_c(temp>>8); //PORTC= temp>>8;
     }
}

void escreve_zero() // write zero
{

   output_drive(PIN_A4);    // this will set the tris bit for that pin to 0 
   output_low(PIN_A4);     //PORTB_PIN_R4  = 0x00;         
   
   time70us();
   //delay_us(70);

   output_float(PIN_A4);    // this will set the tris bit for that pin to 1 (output)
 
 
   #asm NOP       // The function asm NOP spends one machine cycle each or 2us for 4Mhz crystal
   #endasm
   #asm NOP         
   #endasm
}

void escreve_um()

{
 OUTPUT_DRIVE(PIN_A4);    // THIS WILL SET THE TRIS BIT FOR THAT PIN TO 0 (OUTPUT)
 OUTPUT_LOW(PIN_A4);     //PORTB_PIN_R4  = 0X00;  // 
 #ASM GOTO AI;           
  AI:                   
 PINO=0
 #ENDASM

 OUTPUT_FLOAT(PIN_A4); // THIS WILL SET THE TRIS BIT FOR THAT PIN TO 1 (INPUT)
 time70us();
 //delay_us(70);
}

//*********Funções de tempo********

void time15us()
{
 int x = 0x00;
 while (x<1) x++;
}
void time70us()

{
 int x = 0x00;
 while (x<6) x++;
}
void time500us()
{
 int x = 0x00;
 while(x<49) x++;
}

void time750ms()
{
  for (unsigned int16 x=0 ; x<5; x++);
}

//******inicio funcao leitura***************

char leitura()  // lê bit 1 ou 0 na linha do sensor temperatura
{
 char valor;

 output_drive(PIN_A4);    // this will set the tris bit for that pin to 0 (output)
 output_low(PIN_A4);     //PORTB_PIN_R4  = 0x00;  // Escreve zero
 
 #asm NOP         
 #endasm
 
 output_float(PIN_A4);    // this will set the tris bit for that pin to 1 (input)
 delay_cycles(2);           // has the same NOP function, 2 machine cycles
 
funcao leitura
 
 valor = PIN_A4 ; // Read the pin with 0 or 1 and store in value.
 time70us();
 //delay_us(70);
 return valor;     

}// Fim funcao leitura


//******inicio funcao reset***************

void reset()
{
 output_drive(PIN_A4);    // this will set the tris bit for that pin to 0 (output)
 output_low(PIN_A4);// PORTB_PIN_R4  = 0x00;
 time500us();
 //delay_us(500);
 output_float(PIN_A4);    // this will set the tris bit for that pin to 1 (input)
 time15us();
 //delay_us(15);
 while( input(PIN_A4== 1)) ;// fica preso neste laço enquanto pino=1, qdo sensor responder ele envia para a linha a 0.
 time500us();
 //delay_us(500);
} //****Fim fucano reset


//******inicio funcao comando***************

void escreve_comando (unsigned int comando)

{
 int x = 0x00;
 while (x<8)                     // escreve o byte no sensor
 {
  if (comando & 1) escreve_um(); // a funcao and(&) 1+1=1, se primerio bit de comando é 1, entao escreve 1
   else escreve_zero();
   comando = comando >>1;        // desloca o bit para direita
   x++;
 }
}//****Fim funcao comando


unsigned int ler_memDS18()  // will read 2 bytes byte 0 and 1 of the temperature recorder
{
   unsigned int valor = 0x00;
   int x = 0x00;
    while(x <16)
      {
         if (leitura())    //if read has bit = 1, read a bit. performs value
            {
               valor = (valor  | (1 <<x));
            }
            x++;
      }
       
       reset();
       return valor;
} // **fim funcao comando

unsigned int ler_tempDS18()

   unsigned int resultado;
   reset(); // inicia o sensor
   escreve_comando(0xCC);  // Comando de inicio da memoria ROM
   escreve_comando(0x44);  // Inicia conversao da temperatura
   time750ms(); // tempo necsessario para conversao
   //delay_ms(750); //O compilador esta gerando erro na exucucao do progrma ao usar ms(750), nao gera erro ao usar us(750000)
   reset(); // inicia o sensor
   escreve_comando(0xCC);  // Comando de inicio da memoria ROM
   escreve_comando(0xBE);  // Comando de ler memoria do sensor
   resultado = ler_memDS18(); // Le os 2 primeros registradores
   return resultado;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 20385

View user's profile Send private message

PostPosted: Mon Jan 29, 2018 8:32 am     Reply with quote

Change it to this. Now you should see oscillation on PIN_A0:
Code:
#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
#use fast_io(a)


void main()
{
   

while(TRUE);
    {
   output_drive(PIN_A0);    // this will set the tris bit for that pin to 0 

   output_low(PIN_A0);     
   delay_us(500);

   output_high(PIN_A0);
   delay_us(500);
   }
}
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Temtronic_ Program for DS18B20 pin does not oscillate
PostPosted: Mon Jan 29, 2018 8:37 am     Reply with quote

jacktaylor wrote:
People for now do not want to use a library already ready.


Yes, people do. I do, or I would if I used this peripheral. You, on the otherhand, don't for your own reasons, and we've been through all that a number of times.

Code:

#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
#use fast_io(a)

void main()
{
   

while(TRUE);
    {
       
   output_drive(PIN_A0);    // this will set the tris bit for that pin to 0 
   output_low(PIN_A0);     
   
   delay_us(50500);

   output_float(PIN_A0);    // this will set the tris bit for that pin to 1
   (output)
   output_high(PIN_A0);
   delay_us(50500);
   }
}


This is your code. The rest as posted in your last post is not a driver, its a complete application, possibly an example. In other words nothing to do with the first code. No, it is not going to drive PIN_A0, or any pins on GPIO port A. That's because you have declared that you are going to use fast_io on that port, but have no set_tris call to actually set the pin to be an output. Remove the #use fast_io and your code might work. On real PIC hardware that is, I can neither say, nor care, whether it works on Proteus/ISIS.

As a general rule, only use fast io when there is a definite need for it, such as a hard requirement for very fast io timing. For almost all applications fast_io is a confusion, and has lead you in this case to code that doesn't do what you want/expect. Your comments show you expected tris to be set by the compiler, but with fast_io it won't be: that's your job. Its even got past several very good embedded engineers here. So, get rid of fast_io... totally, please!
Ttelmah



Joined: 11 Mar 2010
Posts: 13526

View user's profile Send private message

PostPosted: Mon Jan 29, 2018 8:58 am     Reply with quote

PCM programmer wrote:
Change it to this. Now you should see oscillation on PIN_A0:
Code:
#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
#use fast_io(a)


void main()
{
   

while(TRUE);
    {
   output_drive(PIN_A0);    // this will set the tris bit for that pin to 0 

   output_low(PIN_A0);     
   delay_us(500);

   output_high(PIN_A0);
   delay_us(500);
   }
}


This was the point of my post:

Quote:

output_float(PIN_A0); // this will set the tris bit for that pin to 1 (output)
//Input not output.


He seems blind to the actual effect of the commands being used... Sad
temtronic



Joined: 01 Jul 2010
Posts: 6249
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 29, 2018 9:02 am     Reply with quote

Yup, I'm one of 'them' that got quickly eductaed about fast_io(), more thna 2 decades ago ! The compiler does a great job at handling IO settings, so you either let it do it's job or YOU have to read and understand ALL of the implications of using options like fast_io().
As RF_D said it's very,very rare that you need it. I've only used it 2 or 3 times in 20+ years of 'playing with PICs'. In every case it was necessary for very tight timing requirements or codespace reduction. Since modern PICs run faster than 4MHz and have LOTS of codespace the need for fast_IO() has really not been necessary for 99.9999999% of the applications.

Jay
jacktaylor



Joined: 02 Sep 2017
Posts: 70

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

PCM PROGRAMMER
PostPosted: Mon Jan 29, 2018 10:52 am     Reply with quote

PCM Programmer I need the pin to oscillate with these commands below:
output_drive(PIN_A0); output_float(PIN_A0);

PCM programmer wrote:
Change it to this. Now you should see oscillation on PIN_A0:
[code]#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
#use fast_io(a)


output_drive(PIN_A0); // this will set the tris bit for that pin to 0 (input)
output_low(PIN_A0); //PORTB_PIN_R4 = 0x00; // Coloca zero no pino

time70us();
//delay_us(70);

output_float(PIN_A0); // this will set the tris bit for that pin to 1 (output)
output_high(PIN_A0);
//#asm ("NOP") uso em outro compilador xom parenteses e colchetes. Tempo de intervalo minimo 1us entre cada comando enviado pedido no manual DS18B20
#asm NOP // A funcao asm NOP gasta um ciclo de máquina cada uma ou 2us para cristal de 4Mhz
#endasm
#asm NOP
#endasm
PCM programmer



Joined: 06 Sep 2003
Posts: 20385

View user's profile Send private message

PostPosted: Mon Jan 29, 2018 10:57 am     Reply with quote

jacktaylor wrote:

I need the pin to oscillate with these commands below:
output_drive(PIN_A0); output_float(PIN_A0);

The output_float() line disconnects Pin A0 from external circuits. If you
use that line, you won't see any oscillation.

If you add a pullup resistor (say, 4.7K) to pin A0, then you would see
oscillation.
jacktaylor



Joined: 02 Sep 2017
Posts: 70

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

Re: PCM Prgramme_ RF_Developer pin does not oscillate
PostPosted: Mon Jan 29, 2018 12:34 pm     Reply with quote

RF_Developer
Yes I am using the pullup resistor on the pin. If it was oscillating I could see it on the Proteus oscilloscope. As I said before in other comments, I made this same code in another compiler and I can see the oscillation in the simulation with the Proteus using channel A of the oscilloscope. I removed fast_io (a) as our friend RF_Developer proposed, but the output of the pin is still not oscillating. Missing this for my program works on the CCS. Repeating: output_drive (PIN_A0); // this will set the tris bit for that pin to 0
output_low (PIN_A0);
output_float (PIN_A0); // this will set the tris bit for that pin to 1
Now the pullup resistor puts the pin in 1.
Simple but not working in CCS so far. This is problem I have in CCS in executing code created for the DS18B20.

RF_Developer wrote:
jacktaylor wrote:
People for now do not want to use a library already ready.


Yes, people do. I do, or I would if I used this peripheral. You, on the otherhand, don't for your own reasons, and we've been through all that a number of times.

Code:

#include <16f877a.h>
#fuses xt, nowdt, nolvp, put, brownout
#use delay (clock = 4000000)
//#use fast_io(a)

void main()
{
   

while(TRUE);
    {
       
   output_drive(PIN_A0);    // this will set the tris bit for that pin to 0 
   output_low(PIN_A0);     
   
   delay_us(50500);

   output_float(PIN_A0);    // this will set the tris bit for that pin to 1
 
   delay_us(50500);
   }
}


This is your code. The rest as posted in your last post is not a driver, its a complete application, possibly an example. In other words nothing to do with the first code. No, it is not going to drive PIN_A0, or any pins on GPIO port A. That's because you have declared that you are going to use fast_io on that port, but have no set_tris call to actually set the pin to be an output. Remove the #use fast_io and your code might work. On real PIC hardware that is, I can neither say, nor care, whether it works on Proteus/ISIS.

As a general rule, only use fast io when there is a definite need for it, such as a hard requirement for very fast io timing. For almost all applications fast_io is a confusion, and has lead you in this case to code that doesn't do what you want/expect. Your comments show you expected tris to be set by the compiler, but with fast_io it won't be: that's your job. Its even got past several very good embedded engineers here. So, get rid of fast_io... totally, please!
temtronic



Joined: 01 Jul 2010
Posts: 6249
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 29, 2018 1:10 pm     Reply with quote

re:
Quote:
If it was oscillating I could see it on the Proteus oscilloscope.

NO... you must understand that Proteus does NOT function 100% !!
It is full of bugs, errors, faulty DRCs and will NOT properly 'simulate' a PIC as if it's in the Real World. Proteus is a horrible chunk of code that does NOT work. If I had a dollar for every post about it here, not working I could retire. There isn't ONE single 'schematic' posted that will function in the Real World so really it's no wonder the 'code' portion fails.

You can buy a great 2nd hand scope, 2 chnl, 20MHz for less than $50. That will be the BEST investment you can make. Then delete, erase, wipe Proteus from your computer.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 13526

View user's profile Send private message

PostPosted: Tue Jan 30, 2018 12:55 am     Reply with quote

I wouldn't delete it. Proteus is a great PCB package. It is the Isis simulator that is foul. Even this, if you keep it to doing basic analog simulation works as well as something like PSpice, but repeat 50*, the ability of Isis to simulate PIC's is fundamentally flawed.

I've posted before that a company I worked for ran a 'cost benefit' analysis of the programs and hardware being used in the lab. The only item that came in with a massively 'negative' score was the Isis simulator. They basically reported that designs developed using this were taking longer and had a lower chance of success than those using other techniques.
jacktaylor



Joined: 02 Sep 2017
Posts: 70

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

Temtronic
PostPosted: Tue Jan 30, 2018 7:41 am     Reply with quote

Okay. So you mean my output is wobbling? and that I need to assemble the circuit physically to see it work? Okay. But I keep insisting that here, on my PC, I can see it working on Proteus, but with the program done in another compiler .... I managed to make this program run with this other compiler already 13 days ago and since then, I have tried without success in CCS.
The way I see it is to give up and get a library ready made in the CCS, because I could not make oscillate a pin using the directives already shown several times in the above doubts. Can you tell me a library?


temtronic wrote:
re:
Quote:
If it was oscillating I could see it on the Proteus oscilloscope.

NO... you must understand that Proteus does NOT function 100% !!
It is full of bugs, errors, faulty DRCs and will NOT properly 'simulate' a PIC as if it's in the Real World. Proteus is a horrible chunk of code that does NOT work. If I had a dollar for every post about it here, not working I could retire. There isn't ONE single 'schematic' posted that will function in the Real World so really it's no wonder the 'code' portion fails.

You can buy a great 2nd hand scope, 2 chnl, 20MHz for less than $50. That will be the BEST investment you can make. Then delete, erase, wipe Proteus from your computer.

Jay
temtronic



Joined: 01 Jul 2010
Posts: 6249
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 30, 2018 8:43 am     Reply with quote

re:
Quote:

But I keep insisting that here, on my PC, I can see it working on Proteus, but with the program done in another compiler .... I managed to make this program run with this other compiler already 13 days ago and since then, I have tried without success in CCS.

As I've said before Proteus (ISIS really) is busted. So they got the simulator portion OK for the other compiler BUT they got it WRONG for the CCS compiler. What I don't understand is why anyone has blind faith in a product that is known to be faulty, reminds me of the BSOD for certain Windows versions.

There is working DS18B20 code in the 'code forum' here and I know it works. I have a couple products running it for the past few years.
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 Previous  1, 2, 3  Next
Page 2 of 3

 
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