|
|
View previous topic :: View next topic |
Author |
Message |
Pekub
Joined: 20 Dec 2005 Posts: 16
|
PIC16F1824 Optimization error |
Posted: Mon Apr 04, 2011 3:13 am |
|
|
Compiler: 4.119
Hello,
I made a little larger program on PIC16F1824.
I use two struct
Code: |
struct TG
{
short ItWasErr;
int8 NoSignalErrCnt;
int8 LostSignalErrCnt;
int8 Filter;
int16 LastAvg;
int8 nnNextSpeed;
int16 SpeedBuff[16];
} Tg1, Tg2;
|
and I use interrupt from Timer2
Code: |
void MyFunc(struct TG *ptg)
{
}
#int_timer2
void timer2_isr()
{
setup_timer_2(T2_DIV_BY_16,249,10); // 1.0 ms overflow
Led_On();
}
|
In main() function I call MyFunc(&Tg1);
There are more problems:
1. Program jumps to interrupt routine and then resets
2. Function restart_cause returns 0x3F / this is not defined in file 16F1824.h /
What it means ?
3. When I use optimization level 0, program works fine.
4. When I define and use pointer to struct
struct TG *ptg;
ptg = &Tg1;
and then I call MyFunc(ptg)
the program works fine.
5. When I reduced size of program, the program works fine.
My program is too big to send it.
Where is the problem ? In compiler or in optimization or in my code ?
Please help me.
Thank's
Peter |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 04, 2011 11:43 am |
|
|
It's difficult to help you without a test program.
My suggestion is to use one or more of your work-arounds and
continue with the project. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Apr 05, 2011 1:57 am |
|
|
As PCM programmer states, it is almost impossible to help you without a test program but saying that I would say your problem is in the LED_On function ;)
I expect it is doing something it shouldn't. but without seeing what it does I have no idea. |
|
|
Pekub
Joined: 20 Dec 2005 Posts: 16
|
|
Posted: Tue Apr 05, 2011 5:17 am |
|
|
I am maximally simplify my program and all functions. The program now does not perform any function, but the problem remained.
The processor will be reset about every 2 sec.
Code: |
#case
#include <16F1824.h>
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOWDT //Watch Dog Timer
#FUSES NOPUT //Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //Brownout reset
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=16000000)
#use FAST_IO(A)
#use FAST_IO(C)
int8 RxBuff[32]; // when I remove this line, program works o.k.
#define IN_TG1 PIN_A4 // vstup upraveneho signalu z TG1
#define IN_TEST PIN_C2 // vstup - tlacidlo "Test" povodne PIN_A2
#define LED_TEST PIN_C4 // LED LD3 "Test"
#define TG_SPEED_BUFF_SIZE 16
struct TG
{
short IsSignal; // priznak signalu z TG
short IsBlocking; // priznak blokovania z TG
short NoSignalErr; // priznak chyby TG - "Nie je signal"
short LostSignalWarning; // priznak chyby TG - Varovanie "Mozna strata signalu"
short LostSignalErr; // priznak chyby TG - "Strata signalu"
short ItWasErr; // priznak chyby TG - "Uz bola chyba"
int8 NoSignalErrCnt; // citac poruchoveho stavu "TG - Nie je signal"
int8 LostSignalErrCnt; // citac poruchoveho stavu "TG - Strata signalu"
int8 Filter; // hodnota pre digitalne filtrovanie
int16 SpeedCnt; // citac pre urcenie rychlosti z TG
int16 ActualSpeed; // aktualna hodnota rychlosti z TG
int16 AvgSpeed; // priemerna hodnota rychlosti z TG
int16 LastAvg; // predosla priemerna rychlost z TG1 / pred podozrenim na stratu signalu /
int8 nnNextSpeed; // index pre buffer SpeedBuff pre nasledujucu hodnotu
int16 SpeedBuff[TG_SPEED_BUFF_SIZE]; // buffer rychlosti
} Tg1, Tg2;
//struct TG *ptg1 = &Tg1; // when I enable this line, program works o.k.
struct FILTERED_INPUT
{
short FiIn;
short RiEdge;
short FaEdge;
short Finish;
int8 LowCnt;
int8 HighCnt;
};
struct FILTERED_INPUT InTest, InRst, InTg1, InTg2;
// definicie makier
#define Led_TEST_On() (output_high(LED_TEST)) // zapnutie LED TEST
#define Led_TEST_Off() (output_low(LED_TEST)) // vypnutie LED TEST
#inline
void FIN_Read(struct FILTERED_INPUT *fio, short pinIn, int8 sampleCnt)
// pocet citani pinu = SampleCnt + 1
{
if(fio->Finish == FALSE)
fio->FiIn = pinIn;
if(pinIn == 0)
fio->HighCnt = 0; // nuluje citac "1-urovne"
}
#int_timer4
void timer4_isr()
{
setup_timer_4(T4_DIV_BY_4,9,10); //10.0 us overflow, 100.0 us interrupt
FIN_Read(&InTg1, input(IN_TG1), Tg1.Filter); // nacita vstup z TG1
}
void TG_Obsluha(struct TG *tg)
{
}
#zero_ram
void main()
{
// inicializacia
setup_oscillator(OSC_16MHZ|OSC_INTRC|OSC_PLL_OFF,0);
setup_adc_ports(ADC_OFF);
set_tris_a(0b11111010); // A0,A2=output, A1,A3-A5=input
set_tris_c(0b00000100); // C0,C1,C3-C5=output, C2=input
Led_TEST_On();
delay_ms(150);
Led_TEST_Off();
setup_timer_4(T4_DIV_BY_4,9,10); //10.0 us overflow, 100.0 us interrupt
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER4);
while(TRUE)
{
FIN_Read(&InTest, input(IN_TEST), 30); // when I remove this line, program works o.k.
TG_Obsluha(&Tg1); // when I remove this line, program works o.k.
//TG_Obsluha(ptg1);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 06, 2011 1:43 pm |
|
|
Does this program run correctly if you use "#opt 0" ? |
|
|
Pekub
Joined: 20 Dec 2005 Posts: 16
|
|
Posted: Thu Apr 07, 2011 4:56 am |
|
|
I identified it is not optimization error.
The program does not work with #opt 0 and even with #opt 9 - default value.
I still do not know what is wrong.
I'm going to change my application to another processor PIC18F14K22 and will wait for a new version of the compiler. |
|
|
|
|
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
|