|
|
|
| I may be mere steel but my heart melts when you're around. |
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
||||
|
||||
|
Re: EEPROM Code
It risks getting caught in an infinite loop waiting for the queue and breaks the comm sync on the controller?
|
|
#17
|
|||
|
|||
|
Re: EEPROM Code
Quote:
Code:
// wait, if necessary, for a free slot on the circular queue while(EEPROM_Queue_Free_Space() == 0); |
|
#18
|
||||
|
||||
|
Re: EEPROM Code
Quote:
|
|
#19
|
|||
|
|||
|
Re: EEPROM Code
Kevin,
I haven't tried this, but from the PIC documentation, it looks like you only have to disable the interrupts during the period that you call "pre-write sequence" and "execute the write" in the EEPROM_Write_Handler routine. You should be able to re-enable the interrupts after these 3 lines (from the 39609b Microchip document, section 7.4) rather than waiting until the 2ms write is complete. This may also eliminate the code error by allowing the high priority interrupts to mostly go on schedule. Mike |
|
#20
|
||||
|
||||
|
Re: EEPROM Code
Quote:
-Kevin |
|
#21
|
||||
|
||||
|
Re: EEPROM Code
Quote:
Quote:
-Kevin |
|
#22
|
||||
|
||||
|
Re: EEPROM Code
On a slightly different topic, does the addressing go from 0 to 1023 or 1 to 1024?
i.e. can I write to 0? |
|
#23
|
||||
|
||||
|
Re: EEPROM Code
Quote:
-Kevin |
|
#24
|
||||
|
||||
|
Re: EEPROM Code
Thanks, this makes it perfect for recording tables
If you want (say) a table with the five attributes in each row 0, 5, 10, . . . = attribute a 1, 6, 11, . . . = attribute b 2, 7, 12, . . . = attribute c 3, 8, 13, . . . = attribute d 4, 9, 14, . . . = attribute e Then to find a specific row number, you would take the row number, multiply by 5 and subtract five, and then start reading values? |
|
#25
|
||||
|
||||
|
Re: EEPROM Code
Quote:
![]() |
|
#26
|
||||
|
||||
|
Re: EEPROM Code
I have met one or two systems which did not, and not having a controller with me at the moment to test it out, I figured I might as well ask.
|
|
#27
|
||||
|
||||
|
Re: EEPROM Code
I just wrote and tested some quick-n-dirty trig table code. Grab a copy of the EEPROM code here and add the code below. I only create a table covering zero to ninety degrees because sin(x) in the other three quadrants can be derived using sin(x) data in quadrant one (exercise left to the student). I'll release a more polished version at a later time.
This code creates the table: Code:
#include <math.h>
#include "printf_lib.h"
#include "eeprom.h"
/*******************************************************************************
*
* FUNCTION: Sine_Table()
*
* PURPOSE: Creates a sine table in EEPROM
*
* CALLED FROM:
*
* PARAMETERS: Unsigned int containing the address.
*
* RETURNS: 1 when finished creating table, 0 otherwise
*
* COMMENTS:
*
*******************************************************************************/
unsigned char Sine_Table(unsigned int address)
{
static unsigned char angle = 0;
static unsigned char done_flag = 0;
static unsigned char sine;
if(EEPROM_Queue_Free_Space() > 0 && done_flag == 0)
{
// calculate normalized sine value
sine = (unsigned char)255.0 * sin((float)angle * 3.14159265 / 180.0);
// write the angle and sine value to EEPROM
EEPROM_Write(address + angle, sine);
// send diagnostic information to the terminal
printf("writing x=%u sin(x)=%u\r", (unsigned int)angle, (unsigned int)sine);
// are we done?
if(angle == 90)
{
done_flag = 1;
printf("Finished!\r\n");
}
else
{
angle++;
}
}
return(done_flag);
}
Code:
/*******************************************************************************
*
* FUNCTION: Verify_Sine_Table()
*
* PURPOSE: Creates a sine table in EEPROM
*
* CALLED FROM:
*
* PARAMETERS: Unsigned int containing the address.
*
* RETURNS: 1 when finished creating table, 0 otherwise
*
* COMMENTS:
*
*******************************************************************************/
unsigned char Verify_Sine_Table(unsigned int address)
{
static unsigned char angle = 0;
static unsigned char done_flag = 0;
if(done_flag == 0)
{
if(EEPROM_Read(address+angle) == (unsigned char)(255.0 * sin((float)angle * 3.14159265 / 180.0)))
{
printf("angle=%u verified\r", (unsigned int)angle);
}
else
{
printf("angle=%u failed\r\n", (unsigned int)angle);
}
if(angle == 90)
{
done_flag = 1;
printf("Finished!\r");
}
else
{
angle++;
}
}
return(done_flag);
}
Code:
if(Sine_Table(0) == 1)
{
Verify_Sine_Table(0);
}
EEPROM_Write_Handler();
|
|
#28
|
||||
|
||||
|
Re: EEPROM Code
Quote:
I've got a question about EEPROM_Write(). Code:
unsigned char EEPROM_Write(unsigned int address, unsigned char data)
{
unsigned char return_value;
// return error flag if the queue is full
if(eeprom_queue_full == FALSE)
{
// put the byte and its address on their respective circular queues
eeprom_queue_data[eeprom_queue_write_index] = data;
eeprom_queue_address[eeprom_queue_write_index] = address;
// increment the queue byte count
eeprom_queue_count++;
|
|
#29
|
||||
|
||||
|
Re: EEPROM Code
Quote:
-Kevin |
|
#30
|
||||
|
||||
|
Re: EEPROM Code
Quote:
-Kevin |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Out of the Box Camera Code | russell | Programming | 9 | 21-10-2009 05:28 |
| Code suddenly fails to initialize | miketwalker | Programming | 11 | 19-02-2005 15:23 |
| Team THRUST - Kevin's Code and Camera Code Combine | Chris_Elston | Programming | 3 | 31-01-2005 22:28 |
| Sourceforge for Code Repository and other stuff | SilverStar | Programming | 9 | 15-01-2005 21:16 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |