View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
Can't debug 12F683 : SOLVED |
Posted: Sat Jan 28, 2017 6:28 am |
|
|
Hi All,
Have a funny problem which I can't sort out.
Compiler 5.024
12f683
If I download the program for debugging using the ICD_U40, I get an error message that the oscillator settings are wrong.
Here are the header VCS_I1.h
Code: | #include <12F683.h>
#case
#DEVICE adc=8
#FUSES INTRC_IO, NOWDT, NOMCLR, NOPROTECT, PUT, BROWNOUT, NOIESO, NOFCMEN
#USE delay(clock=4M)
#DEFINE VMeas sAN3
#DEFINE VCh1 3
#DEFINE SW_OnLimit 60
#DEFINE SW_OffLimit 80
#DEFINE ON_TIMER 10 //(0.1 * 60.0/0.262) //0.262 = timer1 overflow of 262ms
#DEFINE OFF_TIMER 20 //(0.1 * 60.0/0.262)
#DEFINE CHRG_ON PIN_A2
|
Main file VCS_I1.c
Code: | unsigned int16 OnTimer=ON_TIMER, OffTimer=OFF_TIMER;
unsigned int16 ADCvalue;
void main(void) {
setup_adc_ports(VMeas);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel(VCh1); //Set to 1st Fan channel
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //262 ms overflow
//Switch output off
output_high(CHRG_ON);
delay_ms(1000);
while(TRUE) {
}
} |
However if I download another project to the same board as they use the same PIC I do not get the debug error and the PIC runs. I am using the same hardware, obviously the program does not perform right as everything is not correct on the pins.
ACFan.h
Code: | #include <12F683.h>
#case
#DEVICE adc=8
#FUSES INTRC_IO, NOWDT, NOMCLR, NOPROTECT, PUT, BROWNOUT, NOIESO, NOFCMEN
#USE delay(clock=4M)
#DEFINE IMeas1A sAN3
#DEFINE ICh1 3
#define NO_OF_SAMPLES 70
#if (SMALL_FAN)
#DEFINE LowILimit 60
#DEFINE HighILimit 80
#else
#DEFINE LowILimit 45
#DEFINE HighILimit 70
#endif
#DEFINE LED1R PIN_A2 //High on pin and low on LED1R will give Green
#DEFINE LED1G PIN_A5 //High on pin and low on LED1G will give Red
|
AcFan.c
Code: | #define SMALL_FAN 0
#include "ACFan.h"
unsigned int16 Timer;
unsigned int8 ADCvalue,Sample[NO_OF_SAMPLES],max,min;
int1 Fan1OK;
void main(void) {
unsigned int8 i;
setup_adc_ports(IMeas1A);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel(ICh1); //Set to 1st Fan channel
while(TRUE) {
//Take 30 samples to determine max and min
//A period are 20ms if taking a sample every 100us then need 200 samples
//Lack of RAM limit samples to 70 so take in 3 batches thus 210 samples
min=0xff;
max=0;
for (i=0; i<NO_OF_SAMPLES; i++) {
//Meas Imeas1A
Sample[i] = read_adc(); //Read 1st Fan Current
delay_us(100);
}
if (Fan1OK) output_high(AllOKPLC);
else output_low(AllOKPLC);
}
} |
Probably something small that I keep overlooking. Hopefully somebody can spot it or point me in the right direction.
Regards
Last edited by alan on Sat Jan 28, 2017 8:43 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Jan 28, 2017 6:48 am |
|
|
well I don't see anything....but I don't use the ICD either. Perhaps there's a 'setting' IN the ICD that is in conflict with the code 'fuses'?
I know in MPLAB you can build either a 'debug' or a 'release' version and no way will the 'debug' version WORK in the real world !
Since 2nd program works and has same fuses, I suspect it's an ICD config issue....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Jan 28, 2017 7:07 am |
|
|
You've omitted the stuff in the VCS_I1.c that you have posted showing how it includes the .h file.
Post files that we can compile. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Jan 28, 2017 7:10 am |
|
|
Thanks for the answer Jay.
I am using the same compiler and same ICD for both programs on the same hardware.
And I believe the debug warning of the oscillator as I can not get the chip to work with a basic LED Flash, that is why I tried to use the debug feature too see if I can find the fault.
Regards |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Jan 28, 2017 7:12 am |
|
|
Sorry Ttelmah, I missed the include file when copying.
Code: | #include "VCS_I1.h"
unsigned int16 OnTimer=ON_TIMER, OffTimer=OFF_TIMER;
unsigned int16 ADCvalue;
void main(void) {
setup_adc_ports(VMeas);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel(VCh1); //Set to 1st Fan channel
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //262 ms overflow
//Switch output off
output_high(CHRG_ON);
delay_ms(1000);
while(TRUE) {
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Jan 28, 2017 8:09 am |
|
|
Code: |
#include <12F683.h>
#case
#DEVICE adc=8
#FUSES INTRC_IO, NOWDT, NOMCLR, NOPROTECT, PUT, BROWNOUT, NOIESO, NOFCMEN
#USE delay(clock=4M)
#DEFINE VMeas sAN3
#DEFINE VCh1 3
#DEFINE SW_OnLimit 60
#DEFINE SW_OffLimit 80
#DEFINE ON_TIMER 10 //(0.1 * 60.0/0.262) //0.262 = timer1 overflow of 262ms
#DEFINE OFF_TIMER 20 //(0.1 * 60.0/0.262)
#DEFINE CHRG_ON PIN_A2
unsigned int16 OnTimer=ON_TIMER, OffTimer=OFF_TIMER;
unsigned int16 ADCvalue;
void main(void) {
setup_adc_ports(VMeas);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel(VCh1); //Set to 1st Fan channel
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //262 ms overflow
//Switch output off
output_high(CHRG_ON);
delay_ms(1000);
while(TRUE) {
}
} |
Above your .h + .c combined, compiled fine for me.....
so something is 'funny', still think ICD settings ??
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Jan 28, 2017 8:43 am |
|
|
One 'lateral' thought. Have you tried pasting your own code back in, and seeing how this behaves?.
I'm thinking something like the old problem where there is a hidden 'non printable' character accidentally in the text somewhere. Code looks fine but then won't work.
Assuming you have the 14pin ICD header chip?.
How is the system powered?. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Jan 28, 2017 8:45 am |
|
|
Thanks to all who tried to help.
U40 can program part but not debug. I were lucky that it worked with one program, if I add or delete a line it stopped working.
Regards
Alan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 28, 2017 11:18 am |
|
|
But you didn't answer, do you have the special ICD header board
that is required to do debugging on the 12F683 ? You can't debug
without it. You can buy it from Microchipdirect.com or other sources.
Look up the part number in the MPLAB help. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Jan 28, 2017 11:30 am |
|
|
I just saw that you need the special header. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 28, 2017 11:38 am |
|
|
One option is to debug your program on a larger PIC that does have
built-in debugging features. Then load it into a 12F683 when you're done.
This thread explains (at the end) how to use #org statements to reduce
the memory available on a larger PIC so it will "look like" a smaller PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=43086 |
|
|
|