CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Codeloader and reeding EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

Codeloader and reeding EEPROM
PostPosted: Wed Jan 25, 2006 8:02 pm     Reply with quote

I'm using CCS PCH C Compiler, Version 3.212 and just loaded the CodeLoader bootloader. My program starts up and reads some locations in EEPROM (locations 0-9) and then reboots and starts over. when I don't use the bootloader I don't have this problem. Is there something I need to put in my program different because I'm using the bootloader? I have WDT disabled in the bootloader and the regular code, and the fuses in both are exactly the same.

Thanks,
Ringo
_________________
Ringo Davis
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Wed Jan 25, 2006 8:24 pm     Reply with quote

Here is what comes out of hyperterminal

reading eeprom baud = 3 Enc = 0
Done setting baud rate
Done READING pid

>reading eeprom baud = 3 Enc = 0
Done setting baud rate
Done READING pid

.... over and over

Here is my code;

#include "18f452.h"
#fuses hs,nowdt,noprotect,put,lvp
#device *=16
#device adc=10
#use delay(clock=20000000)
#define LED1_PIN PIN_B6
#define LED2_PIN PIN_B7
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7,errors,bits=8,parity=N)

///Macros
#define LED1_ON output_high(LED1_PIN)
#define LED2_ON output_high(LED2_PIN)
#define LED1_OFF output_low(LED1_PIN)
#define LED2_OFF output_low(LED2_PIN)


int kVp,kVi,kVd,loops; // PID gain constants for velocity
int kPp,kPi,kPd; // PID gain constants for Pos
int encoder_type;
int heartbeat_counter=0;
int toggle=0;
void init_PIC();
void BlinkLeds();
void SetupNewEEPROM();
void ReadAllEEPROM();
void heartbeat();

/***************************************************************************
void main() --
****************************************************************************/
void main()
{
int data1;
init_PIC();
BlinkLeds();

LED1_OFF;
LED2_OFF;

data1 = read_EEPROM (0);
//printf("The EEPROM is %d\r\n",data1);

if ((data1==255) ||(data1==0)) //blank eeprom
SetupNewEEPROM();
else
ReadAllEEPROM();

enable_interrupts(GLOBAL);
printf("\r\n>");

while (1)
{
heartbeat();
}//end while
}//end main

///////////////////////////////////////////////////////////////////////
void ReadAllEEPROM(void)
{
int address,baud;
address=1;//baudrate
baud = read_EEPROM (address);

address=2;//encoder type
encoder_type= read_EEPROM (address);
printf("reading eeprom baud = %d Enc = %d\r\n",baud,encoder_type);

switch (baud)
{

case 0:
set_uart_speed(2400);
break;
case 1:
set_uart_speed(4800);
break;
case 2:
set_uart_speed(9600);
break;
case 3:
set_uart_speed(19200);
break;
case 4:
set_uart_speed(57600);
break;
case 5:
set_uart_speed(115200);
break;
}
printf("Done setting baud rate\r\n");

address=3;
kVp= read_EEPROM (address);
address=4;
kVi= read_EEPROM (address);

address=5;
kVd= read_EEPROM (address);

address=6;
loops= read_EEPROM (address);

kPp=read_EEPROM (7);
kPi=read_EEPROM (8);
kPd=read_EEPROM (9);
printf("Done READING pid\r\n");

}

/**********************************************************************
void write_PID(void)
**********************************************************************/

void write_PID(void)
{
int data, address;
write_EEPROM (3,kVp);
write_EEPROM (4,kVi);
write_EEPROM (5,kVd);
write_EEPROM (6,loops);
write_EEPROM (7,kPp);
write_EEPROM (8,kPi);
write_EEPROM (9,kPd);


}


///////////////////////////////////////////////////////////////////////
void SetupNewEEPROM(void)
{
int address=0;//1 = blank eeprom test
int data=1;
//printf("Setting up new eeprom\r\n");
write_EEPROM (address,data);
//printf("data at location %d = %d\r\n",address,data);

address=1;//baudrate
data=3;//0=2400,2=9600,3=19200,4=57600,5=115200
write_EEPROM (address,data);
//printf("setting up data %d at location %d \r\n",data,address);
printf("\r\n");

address=2;//Encoder style
data=0;// 0=single. 1 = quad
write_EEPROM (address,data);
//printf("data at location %d = %d\r\n",address,data);
//printf("\r\n");

kVp=10;
kVi=0;
kVd=0;
kPp=1;
kPi=0;
kPd=0;

loops=250;
write_PID();
}

/***************************************************************************
void BlinkLeds (void)
****************************************************************************/
void BlinkLeds (void)
{
int i;
for(i=0;i<5;i++)
{
LED1_ON;
led2_ON;
delay_ms(200);
LED1_OFF;
LED2_OFF;
delay_ms(200);
}
}


/*********************************************************************
void heartbeat()
*********************************************************************/
void heartbeat()
{
heartbeat_counter++;
if (heartbeat_counter >= 50000)
{
heartbeat_counter=0;
Toggle=1-Toggle;
if ( Toggle==1)
{
LED1_on;
led2_off;
}
else
{
LED1_OFF;
led2_on;
}
}
}


/***************************************************************************
void init_PIC() -- Initializes variables
****************************************************************************/
void init_PIC()
{
int i;
short int dummy_variable;
// set up PWM at 19.531 Khz 0-512
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
// PWM_MAX=512;
setup_adc_ports(All_ANALOG);
setup_adc( ADC_CLOCK_INTERNAL );
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_timer_2(T2_DIV_BY_4,128,16);// 18.6 khz 0-512 int every 8ms //


//enable_interrupts(INT_TIMER2);
enable_interrupts(INT_RDA);
enable_interrupts(INT_EXT);
enable_interrupts(INT_RB);
enable_interrupts(INT_TIMER2);

// enable_interrupts(GLOBAL);

// stop_motors();
dummy_variable=input(PIN_A0);
dummy_variable=input(PIN_A1);
dummy_variable=input(PIN_A2);
dummy_variable=input(PIN_A3);
dummy_variable=input(PIN_A4);
dummy_variable=input(PIN_A5);
dummy_variable=input(PIN_B5);
dummy_variable=input(PIN_C0);
dummy_variable=input(PIN_E0);
dummy_variable=input(PIN_B0);//motor encoder inputs
dummy_variable=input(PIN_B1);//motor encoder inputs

output_low(PIN_E1);
output_low(PIN_E2);

output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B6);
output_low(PIN_B7);
output_low(PIN_C1);
output_low(PIN_C2);
output_low(PIN_C3);
output_low(PIN_C4);
output_low(PIN_C5);
output_low(PIN_C6);
//output_low(PIN_C7);RX
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
output_low(PIN_D4);
output_low(PIN_D5);
output_low(PIN_D6);
output_low(PIN_D7);

}
_________________
Ringo Davis
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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