|
|
View previous topic :: View next topic |
Author |
Message |
JeffLewcock
Joined: 10 Apr 2007 Posts: 29
|
Weird Problem with Const's |
Posted: Mon May 07, 2007 3:57 am |
|
|
Hi All
I am a NEWB programmer so please forgive me if the solution is real obvious!
I am writing some code that controls a VFD display via SPI
(see attached code)
I have some large-ish arrays that have quickly filled my RAM up, so am trying to put these into ROM
I have tried this according to the manual by making them CONST's
However when I do this the SPI fails just outputting a 18khz squarewave on the clock line
The line "const int A[2]=120,123;" does not cause this to happen (it is a test dummy)
The line "const int ClearGain[10] = {166,32,32,32,32,32,32,32,32,32};" DOES cause this to happen
remove the const and all is OK
CCS Compiler V4.033
Any Help would be appreciated
===========================================
Code: |
#include <16F874A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES BROWNOUT //Reset when brownout detected
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
int pos;
int WarmupMute[17] = {175,13,21,20, 5, 4,45,23, 1,18,13, 9,14, 7,32,21,16};
int RealTimePreamp[17] = {175,18, 5, 1,12,32,20, 9,13, 5,32,16,18, 5, 1,13,16};
int Mark3D[17] = {175,32,32,32,32,13, 1,18,11,32,51,32, 4,32,32,32,32};
int ClearAll[17] = {175,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32};
int SourceCD[9] = {175, 3, 4,32,32,32,32,32,32};
int SourcePhono[9] = {175,16, 8,15,14,15,32,32,32};
int SourceTuner[9]= {175,20,21,14, 5,18,32,32,32};
int SourceTape[9] = {175,20, 1,16, 5,32,32,32,32};
int SourceAux1[9] = {175, 1,21,24,32,49,32,32,32};
int SourceAux2[9] = {175, 1,21,24,32,50,32,32,32};
int Mute[10] = {166,32,32,32,32,13,21,20, 5, 4};
int Gain[10] = {166, 7, 1, 9,14,45,32,32, 4, 2};
const int ClearGain[] = {166,32,32,32,32,32,32,32,32,32};
const int A[2] = {120,123};
//#int_RB
//void RB_isr(void)
//{
//}
void PowerOnReset()
{
//output_low(pin_c0);
delay_ms(1000);
output_high(pin_c0);
delay_us(200);
output_low(pin_c0);
delay_ms(10);
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_64);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
// ===========================Start User Code==============================
start:
PowerOnReset();
spi_write(255);
delay_us(50);
spi_write(RealTimePreamp[0]);
for(pos=1; pos<=16; ++pos) {
delay_us(50);
spi_write(RealTimePreamp[pos]);
}
delay_ms(1000);
spi_write(Mark3D[0]);
for(pos=1; pos<=16; ++pos) {
delay_us(50);
spi_write(Mark3D[pos]);
}
delay_ms(1000);
spi_write(WarmupMute[0]);
for(pos=1; pos<=16; ++pos) {
delay_us(50);
spi_write(WarmupMute[pos]);
}
delay_ms(1000);
spi_write(ClearGain[0]);
for(pos=1; pos<=9; ++pos) {
delay_us(50);
spi_write(ClearGain[pos]);
}
delay_us(50);
spi_write(SourceCD[0]);
for(pos=1; pos<=4; ++pos) {
delay_us(50);
spi_write(SourceCD[pos]);
}
delay_ms(1000);
spi_write(SourcePhono[0]);
for(pos=1; pos<=8; ++pos) {
delay_us(50);
spi_write(SourcePhono[pos]);
}
delay_ms(1000);
spi_write(SourceTuner[0]);
for(pos=1; pos<=8; ++pos) {
delay_us(50);
spi_write(SourceTuner[pos]);
}
delay_ms(1000);
spi_write(SourceTape[0]);
for(pos=1; pos<=8; ++pos) {
delay_us(50);
spi_write(SourceTape[pos]);
}
delay_ms(1000);
spi_write(SourceAux1[0]);
for(pos=1; pos<=8; ++pos) {
delay_us(50);
spi_write(SourceAux1[pos]);
}
delay_ms(1000);
spi_write(SourceAux2[0]);
for(pos=1; pos<=8; ++pos) {
delay_us(50);
spi_write(SourceAux2[pos]);
}
delay_ms(1000);
spi_write(Mute[0]);
for(pos=1; pos<=9; ++pos) {
delay_us(50);
spi_write(Mute[pos]);
}
delay_us(50);
delay_ms(1000);
spi_write(Gain[0]);
for(pos=1; pos<=9; ++pos) {
delay_us(50);
spi_write(Gain[pos]);
}
delay_us(50);
goto start;
} |
Any Help would be appreciated
Jeff
Last edited by JeffLewcock on Mon May 07, 2007 5:27 am; edited 1 time in total |
|
|
RossJ
Joined: 25 Aug 2004 Posts: 66
|
|
Posted: Mon May 07, 2007 4:50 am |
|
|
Hi Jeff,
In the future, please post code as a
so it retains it's formatting
What you are trying with the const should work. I didn't know the compiler would accept the syntax without {} as you have done. As a rule I would suggest you always enclose the initialisation of arrays with braces. But that doesn't seem to be the cause of your problem as both const and non-const versions seem to work ok.
I built your file (with 4.033) and simulated it with MPLAB. The arrays (both const and non-const) seem to be passed to write_spi() ok. I did however substitute a replacement for that method, since I had no hardware. Perhaps your problem is more to do with the SPI module, than it is the arrays?
A suggestion (perhaps a personal preference) is not to specify the array size in this case since it will automatically be dimensioned for the data you provide. Then in the loops, use the sizeof() function which return the number of bytes occupied by a variable or type. This makes it clearer and a little more robust.
/Cheers, Ross. |
|
|
JeffLewcock
Joined: 10 Apr 2007 Posts: 29
|
|
Posted: Mon May 07, 2007 5:34 am |
|
|
Hi Ross
Thanks for the input
I have reposted the code using code block - Sorry about that !
I have now tried putting the array in parenthesis and leaving it undimensioned neither work
So it looks like a compiler or SPI module error as the array values ARE being passed ?
Also thanks for the "Sizeof" tip, this is what I was going to do once I'd made some RAM room. I had not looked into HOW I was going to do it - Now I know ! It was quick and dirty at the moment (I needed to debug the VFD comms)
Thanks again
Jeff |
|
|
Ttelmah Guest
|
|
Posted: Mon May 07, 2007 12:33 pm |
|
|
The obvious thing here that will cause problems, is that you enable INT_RB, but have the handler 'remmed' out. This _will_ cause problems, and it is possible/probable, that the effect is being changed by the arrays. Put back a handler, or leave the interrupt disabled, and see if the problems go away.
Best Wishes |
|
|
JeffLewcock
Joined: 10 Apr 2007 Posts: 29
|
|
Posted: Mon May 07, 2007 12:59 pm |
|
|
Thanks Ttelmah
That seems to cure the problem !!
Kinda saved me from some embarasment there I was just about to put a bugreport in to CCS, Having tried to find this problem all day !!
Many thanks
Jef |
|
|
|
|
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
|