Helpful ReplyHot!why 12f675 halt while delay_ms

Page: 123 > Showing page 1 of 3 - Powered by APG vNext Trial
Author
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
2018/02/20 06:43:52 (permalink)
0

why 12f675 halt while delay_ms

Hi guys 
i want to make five minutes delay so i used delay_ms built in function mikroC for pic compiler 

sbit triac at GP2_bit;
sbit led at GP4_bit;
unsigned int smokeLevel=0;
unsigned long int counter=0;
void main()
{
cmcon=7;
TRISIO2_bit=0;
TRISIO4_bit=0;
ANSEL.ANS0=1;
ANSEL.ANS2=0;
ANSEL.ANS3=0;
ADCON0.VCFG=0;
triac=0;
led=0;
delay_ms(300000); // wait five minutes
while(1)
{
smokeLevel=ADC_Read(0);
if(smokeLevel<300)
{
triac=1;
led=1;
}
else
{
triac=0;
led=0;
}
}
}

 
scrennshoot for the config register and settings https://ibb.co/kAjGyH
but it halt because after the delay end i try to make the ADC to be like 0 so the pin triac never goes 1 nothing changes 
so where is the problem 
#1
KTrenholm
Super Member
  • Total Posts : 410
  • Reward points : 0
  • Joined: 2012/08/08 14:04:23
  • Location: Connecticut, USA
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/20 09:30:49 (permalink)
+1 (1)
You may be out of range for what the delay_ms() function will accept.  In the MikroC documentation:
 
Creates a software delay in duration of time_in_ms milliseconds (a constant). Range of applicable constants depends on the oscillator frequency.
 
45,000,000 seems to be the limit in clock cycles, so you will have to derive what your maximum argument for delay_ms() is based on that information alongside what your oscillator frequency is.
 
delay_ms() calls delay_cyc(), which is basically a NOP.  The max is 45,000,000.
You're at 4MHz, so your cycle time is 0.00000025s
0.00000025s * 45,000,000 = 11.25s
So your maximum delay_ms() delay is 11.25s.
 
If you need a timer for 5 minutes, you'll probably either have to drop a bunch of calls to delay_ms() (would not recommend) or use a hardware timer alongside a counter and a flag to count up to 5 minutes.
 
See:
https://forum.mikroe.com/viewtopic.php?t=8717
post edited by KTrenholm - 2018/02/20 09:39:26
#2
jack@kksound
code tags!
  • Total Posts : 2575
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/20 09:59:35 (permalink)
+1 (1)
I suggest you try reducing the delay time (maybe something like 1000) to see if the rest of your program functions. This may help point you to the issues.
#3
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 13:06:03 (permalink)
0
ok i put this timer ode to read analog value after 10 SEC delay without using delay_ms
but the result is the same . nothing work . it never set the GPIO2 which i named here "triac" to be logic 1 even if i make the AN0 connected to logic 0

 
//4Mhz internal clock
 
 
 
sbit triac at GP2_bit;
sbit led at GP4_bit;
 
 
 
unsigned int smokeLevel1=0;
unsigned int smokeLevel2=0;
unsigned int smokeLevel=0;
unsigned int oneMinuteCounter=0;
unsigned int minutes=0;
volatile unsigned int flag=0;
 
 
 
void interrupt()
{
if (INTCON.TMR0IF==1)
{
oneMinuteCounter++;
if(oneMinuteCounter>=918){minutes++;oneMinuteCounter=0;}
if(minutes>=10){flag=1;minutes=0;}
INTCON.TMR0IF = 0;
}
}
 
 
 
void main()
{
cmcon=7;
TRISIO2_bit=0;
TRISIO4_bit=0;
TRISIO3_bit=0;
TRISIO0_bit=1;
 
 
 
ANSEL.ANS0=1;
ANSEL.ANS2=0;
ANSEL.ANS3=0;

ADCON0.CHS1=0;
ADCON0.CHS0=0;

ANSEL.ADCS0=1;
ANSEL.ADCS1=0;
ANSEL.ADCS2=1;

ADCON0.ADFM=0;
ADCON0.ADON=1;
ADCON0.VCFG=0;

TMR0=0;
OPTION_REG.T0CS=0;
OPTION_REG.PSA=0;
OPTION_REG.PS0=1;
OPTION_REG.PS1=1;
OPTION_REG.PS2=1;
INTCON.GIE=1;
INTCON.T0IE=1;
INTCON.PEIE=1;
 
 
 
triac=0;
Delay_ms(3);
led=0;
 
 
 

while(1)
{
if(flag==1)
{
ADCON0.B1=1;
while(ADCON0.B1==1){}
smokeLevel1=ADRESH;
smokeLevel2=ADRESL;
smokeLevel2=smokeLevel2>>6;
smokeLevel1=smokeLevel1<<2;
smokeLevel=smokeLevel1|smokeLevel2;
//smokeLevel=ADC_Read(0);
if(smokeLevel<500)
{
triac=1;
Delay_ms(3);
led=1;
}
else
{
triac=0;
Delay_ms(3);
led=0;
}
}
}
}
 
 
 

 
Where is the problem !!!!!!
post edited by ubuntuman - 2018/02/23 13:29:53
#4
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 13:12:47 (permalink)
0
jack@kksound
I suggest you try reducing the delay time (maybe something like 1000) to see if the rest of your program functions. This may help point you to the issues.


when the delay is small like 1 sec it works 
#5
qɥb
Monolothic Member
  • Total Posts : 2621
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: why 12f675 halt while delay_ms 2018/02/23 13:54:36 (permalink)
+2 (2)
ubuntuman
...
scrennshoot for the config register and settings https://ibb.co/kAjGyH

Are you sure these config settings are getting programmed into the PIC?
I've never used mikroC, so I don't know what is involved, but your symptoms sound a lot like the WDT triggering.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#6
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 15:16:03 (permalink)
0
i will check it
qɥb
ubuntuman
...
scrennshoot for the config register and settings https://ibb.co/kAjGyH

Are you sure these config settings are getting programmed into the PIC?
I've never used mikroC, so I don't know what is involved, but your symptoms sound a lot like the WDT triggering.
 




#7
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 18:46:10 (permalink)
0
deleted
post edited by ubuntuman - 2018/02/23 19:38:29
#8
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 18:51:54 (permalink)
0
it is so simple program to read ADC pin after certain number of minutes and make a decision with logic 1 or logic 0 !!! .. i dont believe that i have troubles with that !!
#9
qɥb
Monolothic Member
  • Total Posts : 2621
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: why 12f675 halt while delay_ms 2018/02/23 19:00:49 (permalink)
+1 (1)
It doesn't matter how simple your program is if the WDT is enabled, and you're not regularly resetting it.
Unless you really know why you need it, you should always have it disabled.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#10
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 19:02:59 (permalink)
0
qɥb
It doesn't matter how simple your program is if the WDT is enabled, and you're not regularly resetting it.
Unless you really know why you need it, you should always have it disabled.
 


check the screenshoot 
u will find in the pic kit programmer the config register is loaded with 0x0194 which means WDT is disabled 
MCLR is disabled https://ibb.co/nE5SAx
post edited by ubuntuman - 2018/02/23 19:04:12
#11
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 19:16:32 (permalink)
0
There is a sentence in the datasheet that says
"5: When MCLR is asserted in INTOSC or RC mode, the internal clock oscillator is disabled." 
what does that mean ? 
#12
qɥb
Monolothic Member
  • Total Posts : 2621
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: why 12f675 halt while delay_ms 2018/02/23 19:34:30 (permalink)
+1 (1)
It means that driving the MCLR pin low will stop the clock.
Do you have a schematic of your board?
Is the MCLR pin pulled high?
Do you have bypass capacitors between your VSS and VDD pins?
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#13
qɥb
Monolothic Member
  • Total Posts : 2621
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: why 12f675 halt while delay_ms 2018/02/23 19:34:30 (permalink)
0
-- delete double post

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#14
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 19:41:07 (permalink)
0
qɥb
It means that driving the MCLR pin low will stop the clock.
Do you have a schematic of your board?
Is the MCLR pin pulled high?
Do you have bypass capacitors between your VSS and VDD pins?
 


i make the MCLR pin as input it isn't connected to anything in the schematic in config register the MCLRE pin is 0 so MCLR is disabled 
 
yes i have capacitor
#15
qɥb
Monolothic Member
  • Total Posts : 2621
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: why 12f675 halt while delay_ms 2018/02/23 19:43:01 (permalink) ☄ Helpfulby ubuntuman 2018/02/24 17:52:38
+2 (2)
Don't leave the MCLR pin floating.
Even if you disable the MCLR function, if it can float up to a high voltage, it can trigger programming mode, which looks just like a reset.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#16
PStechPaul
Super Member
  • Total Posts : 1835
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/23 21:44:11 (permalink)
0
Some newer devices have a weak pullup on the MCLR pin. But not on the PIC12F675.

 
#17
ubuntuman
Super Member
  • Total Posts : 224
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/24 03:30:12 (permalink)
0
what if i make all unused pins as output and make them all to generate logic 1 ? will be better ? 
 
#18
qɥb
Monolothic Member
  • Total Posts : 2621
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: online
Re: why 12f675 halt while delay_ms 2018/02/24 03:57:07 (permalink)
+1 (1)
Better yes, you should never have floating input pins.
However, you cannot make the MCLR pin an output, it is input only, so you can't avoid the need to fit a pullup resistor to that pin.

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#19
1and0
Access is Denied
  • Total Posts : 7996
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: why 12f675 halt while delay_ms 2018/02/24 04:13:31 (permalink)
+1 (1)
ubuntuman
what if i make all unused pins as output and make them all to generate logic 1 ? will be better ? 

Generally it's a bit better to set them logic 0 output, because the on resistance of the N channel transistor on the low side is lower than that of the P channel transistor on the high side.
 
Anyway, set unused pins to output logic 0 or 1, or leave them as inputs connecting to Vdd or Vss by a resistor.
post edited by 1and0 - 2018/02/24 04:15:03
#20
Page: 123 > Showing page 1 of 3 - Powered by APG vNext Trial
Jump to:
© 2018 APG vNext Trial Version 4.5