Author Topic: Problem with PIC12F675 simulation in Proteus  (Read 9721 times)

0 Members and 1 Guest are viewing this topic.

Offline fubar.grTopic starter

  • Supporter
  • ****
  • Posts: 366
  • Country: gr
    • Fubar.gr
Problem with PIC12F675 simulation in Proteus
« on: April 28, 2016, 04:23:25 pm »
I'm playing around with Proteus, so I made this circuit with the intention to control the blinking delay with a pot

The code is here:

Code: [Select]
#include <xc.h>
#define _XTAL_FREQ 4000000

unsigned int ADCRead()
{
   //ADON=1;  //switch on the adc module

   GO_DONE=1;  //Start conversion

   while(GO_DONE); //wait for the conversion to finish

   ADON=0;  //switch off adc

   return ADRESH;
}


void main(void)
 {
   
    TRISIO = 0b00111110;
    ADCON0 = 0b00000101;
    ANSEL  = 0b00010010;
    unsigned int zx = ADCRead();
   
   while (1){
      GPIO = 0b00000001;
      __delay_ms (500);
      GPIO = 0b00000000;
      __delay_ms (500);
     
}
 }
 
 
 

Everything works perfectly, and all the variables take the values they should, for example here's a screenshot with the pot set to 50%

But if I try to put the variable zx (ie the ADC result) into __delay_ms, then the code doesn't compile and the compiler error code is somewhat cryptic:

Code: [Select]
(1273) Omniscient Code Generation not available in Free mode (warning)
(908) exit status = 1
(908) exit status = 1
make: *** [Debug.cof] Error 1

Error code 2


Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Problem with PIC12F675 simulation in Proteus
« Reply #1 on: April 28, 2016, 06:02:00 pm »
Check to see if the delay routines are available under debug mode.

If not, write your own delay routines.
================================
https://dannyelectronics.wordpress.com/
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Problem with PIC12F675 simulation in Proteus
« Reply #2 on: April 29, 2016, 06:22:03 am »
they are not. they should be built-in macros.. the debugger gets grazy for a while when you have to step past them
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12849
Re: Problem with PIC12F675 simulation in Proteus
« Reply #3 on: April 29, 2016, 09:31:35 am »
XC8 built-in delay routines only support a literal constant or an expression composed of literal constants as a parameter.   If you need a variable delay, wrap a fixed delay (using the builtin routines) in a loop, with the desired delay as the loop count.

Stepping through delays of more than a few tens of instruction cycles is a PITA.  Put a breakpoint after the delay and run to it at full speed.


P.S. Your question has sweet F.A. to do with Proteus.  Why confuse the issue by mentioning it?
 

Offline hamdi.tn

  • Frequent Contributor
  • **
  • Posts: 623
  • Country: tn
Re: Problem with PIC12F675 simulation in Proteus
« Reply #4 on: April 29, 2016, 10:50:25 am »
i think delay_ms function don't take variable, just constant, the compiler add this delays in code.
Build your own delay function or just use PWM module (didn't check DS of this PIC, correct me if it does not have one) , you changing both delays value, so basically you changing the blinking frequency.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Problem with PIC12F675 simulation in Proteus
« Reply #5 on: April 29, 2016, 12:12:09 pm »
Quote
i think delay_ms function don't take variable, just constant, the compiler add this delays in code.

Easy to get around:

Code: [Select]
//using the factory delay_ms routine to delay a user-specified period of time
void mydelay_ms(int dly) {
  while (dly--) _delay_ms(1);
}


Put in the proper data types.
================================
https://dannyelectronics.wordpress.com/
 

Offline hamdi.tn

  • Frequent Contributor
  • **
  • Posts: 623
  • Country: tn
Re: Problem with PIC12F675 simulation in Proteus
« Reply #6 on: April 29, 2016, 12:26:10 pm »
Quote
i think delay_ms function don't take variable, just constant, the compiler add this delays in code.

Easy to get around:

Code: [Select]
//using the factory delay_ms routine to delay a user-specified period of time
void mydelay_ms(int dly) {
  while (dly--) _delay_ms(1);
}


Put in the proper data types.

yap  :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf