EEVblog Electronics Community Forum
Electronics => PCB/EDA/CAD => Proteus => Topic started by: fubar.gr 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:
#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:
(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
-
Check to see if the delay routines are available under debug mode.
If not, write your own delay routines.
-
they are not. they should be built-in macros.. the debugger gets grazy for a while when you have to step past them
-
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?
-
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.
-
i think delay_ms function don't take variable, just constant, the compiler add this delays in code.
Easy to get around:
//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.
-
i think delay_ms function don't take variable, just constant, the compiler add this delays in code.
Easy to get around:
//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 :-+