A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
Problem with C18 - arnajon - Apr 22 17:42:08 2006
Hi everyone,
I'm working on a project which includes a PIC18F4550. I'm using the
microchip C18 compiler and I'm having an odd problem. I'm using an
integer array of constants which I'm trying to reference using an
index which might not sound as a titanic task. Nontheless this does
not work.=20
This code works:
while(count <=3D points[0]);
but this does not:
int index =3D 0;
while(count <=3D points[0]);
the count variable is incremented via an interrupt.
Thanks up front!
Arnar B. J=F3nsson
Mechanical engineering student
University of Iceland
Here's the whole code if you're interested to help:
#include
/* for TRISB and PORTB declarations */
#include
#include
#pragma config FOSC =3D HS
#pragma config BOR =3D ON
#pragma config WDT =3D OFF
#pragma config MCLRE =3D OFF
unsigned int count =3D 0;
int points[28] =3D
{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,219,=
252,257,262,268,272,287};
void blinkLaser(void); /* prototype needed for 'goto' below */
#pragma code HIGH_INTERRUPT_VECTOR =3D 0x8
void high_ISR (void)
{
_asm
goto blinkLaser
_endasm
}
#pragma code /* allow the linker to locate the remaining code */
#pragma interrupt blinkLaser
void blinkLaser (void)
{=09
count++;
INTCONbits.INT0IF =3D 0; /* clear flag to avoid another interrupt */
}
void EnableHighInterrupts (void)
{
RCONbits.IPEN =3D 1; /* enable interrupt priority levels */
INTCONbits.GIEH =3D 1; /* enable all high priority interrupts */
}
void main (void)
{
//Breytur
int index =3D 0;
//Upphafsstillingar
TRISE =3D 0;=20
TRISD =3D 0;
TRISB =3D 0b00000111;=09
ADCON1 =3D 0b00001111;
TRISAbits.TRISA3 =3D 1;
OpenPWM1(0x23);
OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
FALLING_EDGE_INT);
EnableHighInterrupts();
//Stilla =FAtganga
PORTDbits.RD7 =3D 0; //Laser
PORTEbits.RE0 =3D 0; //D=ED=F3=F0a
SetDCPWM1(1000); //Hra=F0i =E1 m=F3tor
while(~PORTBbits.RB2); //b=ED=F0ur eftir index merki
//while(PORTAbits.RA3); //b=ED=F0ur eftir a=F0 =FDtt s=E9 =E1 takka
=09
while(1)
{
for(index =3D 0; index < 28;index++)
{
while(count <=3D points[index]);=09
PORTDbits.RD7 =3D ~PORTDbits.RD7;
}
=09
while(~PORTBbits.RB2);
count =3D 0;
}
}
to unsubscribe, go to http://www.yahoogroups.com and follow the instruction=
s=20
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com ) Re: Problem with C18 - dlc - Apr 22 23:37:12 2006
What "doesn't work" about the code? I've found C18 has numerous odd
things that can occur, it has gotten better in later revs though. I
have seen very odd behavior myself in a few different areas but by and
large C18 has been pretty solid.
DLC
arnajon wrote:
> Hi everyone,
>
> I'm working on a project which includes a PIC18F4550. I'm using the
> microchip C18 compiler and I'm having an odd problem. I'm using an
> integer array of constants which I'm trying to reference using an
> index which might not sound as a titanic task. Nontheless this does
> not work.
>
> This code works:
> while(count <= points[0]);
>
> but this does not:
> int index = 0;
> while(count <= points[0]);
>
> the count variable is incremented via an interrupt.
>
> Thanks up front!
> Arnar B. Jónsson
> Mechanical engineering student
> University of Iceland
>
> Here's the whole code if you're interested to help:
>
> #include
/* for TRISB and PORTB declarations */
> #include
> #include #pragma config FOSC = HS
> #pragma config BOR = ON
> #pragma config WDT = OFF
> #pragma config MCLRE = OFF
>
> unsigned int count = 0;
> int points[28] =
>
{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,219,252,257,262,268,272,287};
> void blinkLaser(void); /* prototype needed for 'goto' below */
>
> #pragma code HIGH_INTERRUPT_VECTOR = 0x8
> void high_ISR (void)
> {
> _asm
> goto blinkLaser
> _endasm
> }
> #pragma code /* allow the linker to locate the remaining code */
>
> #pragma interrupt blinkLaser
> void blinkLaser (void)
> {
> count++;
> INTCONbits.INT0IF = 0; /* clear flag to avoid another interrupt */
> }
>
> void EnableHighInterrupts (void)
> {
> RCONbits.IPEN = 1; /* enable interrupt priority levels */
> INTCONbits.GIEH = 1; /* enable all high priority interrupts */
> }
>
> void main (void)
> {
> //Breytur
> int index = 0;
>
> //Upphafsstillingar
> TRISE = 0;
> TRISD = 0;
> TRISB = 0b00000111;
> ADCON1 = 0b00001111;
> TRISAbits.TRISA3 = 1;
> OpenPWM1(0x23);
> OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
> FALLING_EDGE_INT);
> EnableHighInterrupts();
>
> //Stilla útganga
> PORTDbits.RD7 = 0; //Laser
> PORTEbits.RE0 = 0; //Díóða
> SetDCPWM1(1000); //Hraði á mótor
>
> while(~PORTBbits.RB2); //bíður eftir index merki
> //while(PORTAbits.RA3); //bíður eftir að ýtt sé á takka
>
> while(1)
> {
> for(index = 0; index < 28;index++)
> {
> while(count <= points[index]);
> PORTDbits.RD7 = ~PORTDbits.RD7;
> }
>
> while(~PORTBbits.RB2);
> count = 0;
> }
>
> }
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
>

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 - Harold Hallikainen - Apr 23 0:41:28 2006
I've also found C18 to be pretty reliable. When I've had very strange
problems, I've been able to fix it by making more room for the stack.
There's no warning that you've run out of stack space, stuff just starts
returning strange values.
One thing on a variable that's changed by an interrupt, I wonder if maybe
the variable should be made "volatile." This generally refers to stuff
like I/O that can change without the compilers knowledge (or the compiler
assumes it's the only thing that changes that variable). I've never needed
to use the volatile modifier, but I wonder if it would help here.
Harold
> What "doesn't work" about the code? I've found C18 has numerous odd
> things that can occur, it has gotten better in later revs though. I
> have seen very odd behavior myself in a few different areas but by and
> large C18 has been pretty solid.
>
> DLC
>
> arnajon wrote:
>> Hi everyone,
>>
>> I'm working on a project which includes a PIC18F4550. I'm using the
>> microchip C18 compiler and I'm having an odd problem. I'm using an
>> integer array of constants which I'm trying to reference using an
>> index which might not sound as a titanic task. Nontheless this does
>> not work.
>>
>> This code works:
>> while(count <= points[0]);
>>
>> but this does not:
>> int index = 0;
>> while(count <= points[0]);
>>
>> the count variable is incremented via an interrupt.
>>
>> Thanks up front!
>> Arnar B. Jónsson
>> Mechanical engineering student
>> University of Iceland
>>
>> Here's the whole code if you're interested to help:
>>
>> #include
/* for TRISB and PORTB declarations */
>> #include
>> #include
>>
>> #pragma config FOSC = HS
>> #pragma config BOR = ON
>> #pragma config WDT = OFF
>> #pragma config MCLRE = OFF
>>
>> unsigned int count = 0;
>> int points[28] =
>>
{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,219,252,257,262,268,272,287};
>> void blinkLaser(void); /* prototype needed for 'goto' below */
>>
>> #pragma code HIGH_INTERRUPT_VECTOR = 0x8
>> void high_ISR (void)
>> {
>> _asm
>> goto blinkLaser
>> _endasm
>> }
>> #pragma code /* allow the linker to locate the remaining code */
>>
>> #pragma interrupt blinkLaser
>> void blinkLaser (void)
>> {
>> count++;
>> INTCONbits.INT0IF = 0; /* clear flag to avoid another interrupt */
>> }
>>
>> void EnableHighInterrupts (void)
>> {
>> RCONbits.IPEN = 1; /* enable interrupt priority levels */
>> INTCONbits.GIEH = 1; /* enable all high priority interrupts */
>> }
>>
>> void main (void)
>> {
>> //Breytur
>> int index = 0;
>>
>> //Upphafsstillingar
>> TRISE = 0;
>> TRISD = 0;
>> TRISB = 0b00000111;
>> ADCON1 = 0b00001111;
>> TRISAbits.TRISA3 = 1;
>> OpenPWM1(0x23);
>> OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
>> FALLING_EDGE_INT);
>> EnableHighInterrupts();
>>
>> //Stilla útganga
>> PORTDbits.RD7 = 0; //Laser
>> PORTEbits.RE0 = 0; //Díóða
>> SetDCPWM1(1000); //Hraði á mótor
>>
>> while(~PORTBbits.RB2); //bíður eftir index merki
>> //while(PORTAbits.RA3); //bíður eftir að ýtt sé á takka
>>
>> while(1)
>> {
>> for(index = 0; index < 28;index++)
>> {
>> while(count <= points[index]);
>> PORTDbits.RD7 = ~PORTDbits.RD7;
>> }
>>
>> while(~PORTBbits.RB2);
>> count = 0;
>> }
>>
>> }
>>
>> to unsubscribe, go to http://www.yahoogroups.com and follow the
>> instructions
>>

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 - DLC - Apr 23 21:04:41 2006
The stack has been my experience too. It is one of Microchip's first
suggestions as well.
DLC
Harold Hallikainen wrote:
> I've also found C18 to be pretty reliable. When I've had very strange
> problems, I've been able to fix it by making more room for the stack.
> There's no warning that you've run out of stack space, stuff just starts
> returning strange values.
>
> One thing on a variable that's changed by an interrupt, I wonder if maybe
> the variable should be made "volatile." This generally refers to stuff
> like I/O that can change without the compilers knowledge (or the compiler
> assumes it's the only thing that changes that variable). I've never needed
> to use the volatile modifier, but I wonder if it would help here.
>
> Harold
>>What "doesn't work" about the code? I've found C18 has numerous odd
>>things that can occur, it has gotten better in later revs though. I
>>have seen very odd behavior myself in a few different areas but by and
>>large C18 has been pretty solid.
>>
>>DLC
>>
>>arnajon wrote:
>>
>>>Hi everyone,
>>>
>>>I'm working on a project which includes a PIC18F4550. I'm using the
>>>microchip C18 compiler and I'm having an odd problem. I'm using an
>>>integer array of constants which I'm trying to reference using an
>>>index which might not sound as a titanic task. Nontheless this does
>>>not work.
>>>
>>>This code works:
>>>while(count <= points[0]);
>>>
>>>but this does not:
>>>int index = 0;
>>>while(count <= points[0]);
>>>
>>>the count variable is incremented via an interrupt.
>>>
>>>Thanks up front!
>>>Arnar B. Jónsson
>>>Mechanical engineering student
>>>University of Iceland
>>>
>>>Here's the whole code if you're interested to help:
>>>
>>>#include
/* for TRISB and PORTB declarations */
>>>#include
>>>#include
>>>
>>>#pragma config FOSC = HS
>>>#pragma config BOR = ON
>>>#pragma config WDT = OFF
>>>#pragma config MCLRE = OFF
>>>
>>>unsigned int count = 0;
>>>int points[28] =
>>>{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,219,252,257,262,268,272,287};
>>>void blinkLaser(void); /* prototype needed for 'goto' below */
>>>
>>>#pragma code HIGH_INTERRUPT_VECTOR = 0x8
>>>void high_ISR (void)
>>>{
>>>_asm
>>>goto blinkLaser
>>>_endasm
>>>}
>>>#pragma code /* allow the linker to locate the remaining code */
>>>
>>>#pragma interrupt blinkLaser
>>>void blinkLaser (void)
>>>{
>>> count++;
>>> INTCONbits.INT0IF = 0; /* clear flag to avoid another interrupt */
>>>}
>>>
>>>void EnableHighInterrupts (void)
>>>{
>>> RCONbits.IPEN = 1; /* enable interrupt priority levels */
>>> INTCONbits.GIEH = 1; /* enable all high priority interrupts */
>>>}
>>>
>>>void main (void)
>>>{
>>>//Breytur
>>>int index = 0;
>>>
>>>//Upphafsstillingar
>>>TRISE = 0;
>>>TRISD = 0;
>>>TRISB = 0b00000111;
>>>ADCON1 = 0b00001111;
>>>TRISAbits.TRISA3 = 1;
>>>OpenPWM1(0x23);
>>>OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
>>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
>>> FALLING_EDGE_INT);
>>>EnableHighInterrupts();
>>>
>>>//Stilla útganga
>>>PORTDbits.RD7 = 0; //Laser
>>>PORTEbits.RE0 = 0; //Díóða
>>>SetDCPWM1(1000); //Hraði á mótor
>>>
>>>while(~PORTBbits.RB2); //bíður eftir index merki
>>>//while(PORTAbits.RA3); //bíður eftir að ýtt sé á takka
>>>
>>>while(1)
>>>{
>>> for(index = 0; index < 28;index++)
>>> {
>>> while(count <= points[index]);
>>> PORTDbits.RD7 = ~PORTDbits.RD7;
>>> }
>>>
>>> while(~PORTBbits.RB2);
>>> count = 0;
>>>}
>>>
>>>}
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>to unsubscribe, go to http://www.yahoogroups.com and follow the
>>>instructions
>>>

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 ..... and a new proble - arnajon - Apr 25 19:56:55 2006
I fixed the problem, and you were right: stack size.
BUT... I have a fresh problem. The project I'm working on involves
blinking a laser at frequencies of something like 10-20kHz. The
circuit diagram can be found here:
http://www.hi.is/~hrb/laser/schema.gif
This diagram does not show the 0.01uF cap between GND and +5V. As you
can see I connected the laser directly to an IO pin, since it drains
less tha 20mA of current. My problem is however that I can't blink the
laser fast enough. If I increase the on/off frequency to the laser it
fades away. First I thought the laser just could not handle the Hz,
but I tried connecting it to a raw NE555 circuit @ 20kHZ and the laser
handled it just fine, so I'm pretty certain the problem lies in the RC
constant of my PIC circuit, but I have no clue how to fix it. Does the
size of the +5V-GND cap matter?
Any ideas would be great.
PS. The project is a simple laser text projector. You can see our
current results here (the image actually flickers so the actual image
does not look as good as the picture) :
http://www.hi.is/~hrb/laser/abc.jpg
thank,
Arnar B.
--- In p...@yahoogroups.com, DLC
wrote:
>
> The stack has been my experience too. It is one of Microchip's first=20
> suggestions as well.
>=20
> DLC
>=20
> Harold Hallikainen wrote:
> > I've also found C18 to be pretty reliable. When I've had very strange
> > problems, I've been able to fix it by making more room for the stack.
> > There's no warning that you've run out of stack space, stuff just
starts
> > returning strange values.
> >=20
> > One thing on a variable that's changed by an interrupt, I wonder
if maybe
> > the variable should be made "volatile." This generally refers to stuff
> > like I/O that can change without the compilers knowledge (or the
compiler
> > assumes it's the only thing that changes that variable). I've
never needed
> > to use the volatile modifier, but I wonder if it would help here.
> >=20
> > Harold
> >=20
> >=20
> >>What "doesn't work" about the code? I've found C18 has numerous odd
> >>things that can occur, it has gotten better in later revs though. I
> >>have seen very odd behavior myself in a few different areas but by and
> >>large C18 has been pretty solid.
> >>
> >>DLC
> >>
> >>arnajon wrote:
> >>
> >>>Hi everyone,
> >>>
> >>>I'm working on a project which includes a PIC18F4550. I'm using the
> >>>microchip C18 compiler and I'm having an odd problem. I'm using an
> >>>integer array of constants which I'm trying to reference using an
> >>>index which might not sound as a titanic task. Nontheless this does
> >>>not work.
> >>>
> >>>This code works:
> >>>while(count <=3D points[0]);
> >>>
> >>>but this does not:
> >>>int index =3D 0;
> >>>while(count <=3D points[0]);
> >>>
> >>>the count variable is incremented via an interrupt.
> >>>
> >>>Thanks up front!
> >>>Arnar B. J=F3nsson
> >>>Mechanical engineering student
> >>>University of Iceland
> >>>
> >>>Here's the whole code if you're interested to help:
> >>>
> >>>#include /* for TRISB and PORTB declarations */
> >>>#include
> >>>#include
> >>>
> >>>#pragma config FOSC =3D HS
> >>>#pragma config BOR =3D ON
> >>>#pragma config WDT =3D OFF
> >>>#pragma config MCLRE =3D OFF
> >>>
> >>>unsigned int count =3D 0;
> >>>int points[28] =3D
>
>>>{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,2=
19,252,257,262,268,272,287};
> >>>void blinkLaser(void); /* prototype needed for 'goto' below */
> >>>
> >>>#pragma code HIGH_INTERRUPT_VECTOR =3D 0x8
> >>>void high_ISR (void)
> >>>{
> >>>_asm
> >>>goto blinkLaser
> >>>_endasm
> >>>}
> >>>#pragma code /* allow the linker to locate the remaining code */
> >>>
> >>>#pragma interrupt blinkLaser
> >>>void blinkLaser (void)
> >>>{
> >>> count++;
> >>> INTCONbits.INT0IF =3D 0; /* clear flag to avoid another interrupt */
> >>>}
> >>>
> >>>void EnableHighInterrupts (void)
> >>>{
> >>> RCONbits.IPEN =3D 1; /* enable interrupt priority levels */
> >>> INTCONbits.GIEH =3D 1; /* enable all high priority interrupts */
> >>>}
> >>>
> >>>void main (void)
> >>>{
> >>>//Breytur
> >>>int index =3D 0;
> >>>
> >>>//Upphafsstillingar
> >>>TRISE =3D 0;
> >>>TRISD =3D 0;
> >>>TRISB =3D 0b00000111;
> >>>ADCON1 =3D 0b00001111;
> >>>TRISAbits.TRISA3 =3D 1;
> >>>OpenPWM1(0x23);
> >>>OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0
interrupt */
> >>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
> >>> FALLING_EDGE_INT);
> >>>EnableHighInterrupts();
> >>>
> >>>//Stilla =FAtganga
> >>>PORTDbits.RD7 =3D 0; //Laser
> >>>PORTEbits.RE0 =3D 0; //D=ED=F3=F0a
> >>>SetDCPWM1(1000); //Hra=F0i =E1 m=F3tor
> >>>
> >>>while(~PORTBbits.RB2); //b=ED=F0ur eftir index merki
> >>>//while(PORTAbits.RA3); //b=ED=F0ur eftir a=F0 =FDtt s=E9 =E1 takka
> >>>
> >>>while(1)
> >>>{
> >>> for(index =3D 0; index < 28;index++)
> >>> {
> >>> while(count <=3D points[index]);
> >>> PORTDbits.RD7 =3D ~PORTDbits.RD7;
> >>> }
> >>>
> >>> while(~PORTBbits.RB2);
> >>> count =3D 0;
> >>>}
> >>>
> >>>}
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>to unsubscribe, go to http://www.yahoogroups.com and follow the
> >>>instructions
> >>>
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 ..... and a new proble - mikerey35475 - Apr 25 22:26:20 2006
How long are you leaving the laser turned on ? You will need to turn
the laser on then delay a few microseconds say 20 to 50, then turn it
off to allow time for it to fire. Otherwise the voltage supplied to
the laser will never reach the threshold to turn the it on.
Mike
--- In p...@yahoogroups.com, "arnajon"
wrote:
>
> I fixed the problem, and you were right: stack size.
>=20
> BUT... I have a fresh problem. The project I'm working on involves
> blinking a laser at frequencies of something like 10-20kHz. The
> circuit diagram can be found here:
>=20
> http://www.hi.is/~hrb/laser/schema.gif
>=20
> This diagram does not show the 0.01uF cap between GND and +5V. As you
> can see I connected the laser directly to an IO pin, since it drains
> less tha 20mA of current. My problem is however that I can't blink the
> laser fast enough. If I increase the on/off frequency to the laser it
> fades away. First I thought the laser just could not handle the Hz,
> but I tried connecting it to a raw NE555 circuit @ 20kHZ and the laser
> handled it just fine, so I'm pretty certain the problem lies in the RC
> constant of my PIC circuit, but I have no clue how to fix it. Does the
> size of the +5V-GND cap matter?
>=20
> Any ideas would be great.
>=20
> PS. The project is a simple laser text projector. You can see our
> current results here (the image actually flickers so the actual image
> does not look as good as the picture) :
>=20
> http://www.hi.is/~hrb/laser/abc.jpg
>=20
>=20
> thank,
> Arnar B.
>=20
> --- In p...@yahoogroups.com, DLC wrote:
> >
> > The stack has been my experience too. It is one of Microchip's first=20
> > suggestions as well.
> >=20
> > DLC
> >=20
> > Harold Hallikainen wrote:
> > > I've also found C18 to be pretty reliable. When I've had very
strange
> > > problems, I've been able to fix it by making more room for the
stack.
> > > There's no warning that you've run out of stack space, stuff just
> starts
> > > returning strange values.
> > >=20
> > > One thing on a variable that's changed by an interrupt, I wonder
> if maybe
> > > the variable should be made "volatile." This generally refers to
stuff
> > > like I/O that can change without the compilers knowledge (or the
> compiler
> > > assumes it's the only thing that changes that variable). I've
> never needed
> > > to use the volatile modifier, but I wonder if it would help here.
> > >=20
> > > Harold
> > >=20
> > >=20
> > >>What "doesn't work" about the code? I've found C18 has numerous odd
> > >>things that can occur, it has gotten better in later revs though. I
> > >>have seen very odd behavior myself in a few different areas but
by and
> > >>large C18 has been pretty solid.
> > >>
> > >>DLC
> > >>
> > >>arnajon wrote:
> > >>
> > >>>Hi everyone,
> > >>>
> > >>>I'm working on a project which includes a PIC18F4550. I'm using the
> > >>>microchip C18 compiler and I'm having an odd problem. I'm using an
> > >>>integer array of constants which I'm trying to reference using an
> > >>>index which might not sound as a titanic task. Nontheless this does
> > >>>not work.
> > >>>
> > >>>This code works:
> > >>>while(count <=3D points[0]);
> > >>>
> > >>>but this does not:
> > >>>int index =3D 0;
> > >>>while(count <=3D points[0]);
> > >>>
> > >>>the count variable is incremented via an interrupt.
> > >>>
> > >>>Thanks up front!
> > >>>Arnar B. J=F3nsson
> > >>>Mechanical engineering student
> > >>>University of Iceland
> > >>>
> > >>>Here's the whole code if you're interested to help:
> > >>>
> > >>>#include /* for TRISB and PORTB declarations */
> > >>>#include
> > >>>#include
> > >>>
> > >>>#pragma config FOSC =3D HS
> > >>>#pragma config BOR =3D ON
> > >>>#pragma config WDT =3D OFF
> > >>>#pragma config MCLRE =3D OFF
> > >>>
> > >>>unsigned int count =3D 0;
> > >>>int points[28] =3D
> >>>{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,2=
19,252,257,262,268,272,287};
> > >>>void blinkLaser(void); /* prototype needed for 'goto' below */
> > >>>
> > >>>#pragma code HIGH_INTERRUPT_VECTOR =3D 0x8
> > >>>void high_ISR (void)
> > >>>{
> > >>>_asm
> > >>>goto blinkLaser
> > >>>_endasm
> > >>>}
> > >>>#pragma code /* allow the linker to locate the remaining code */
> > >>>
> > >>>#pragma interrupt blinkLaser
> > >>>void blinkLaser (void)
> > >>>{
> > >>> count++;
> > >>> INTCONbits.INT0IF =3D 0; /* clear flag to avoid another interrupt *=
/
> > >>>}
> > >>>
> > >>>void EnableHighInterrupts (void)
> > >>>{
> > >>> RCONbits.IPEN =3D 1; /* enable interrupt priority levels */
> > >>> INTCONbits.GIEH =3D 1; /* enable all high priority interrupts */
> > >>>}
> > >>>
> > >>>void main (void)
> > >>>{
> > >>>//Breytur
> > >>>int index =3D 0;
> > >>>
> > >>>//Upphafsstillingar
> > >>>TRISE =3D 0;
> > >>>TRISD =3D 0;
> > >>>TRISB =3D 0b00000111;
> > >>>ADCON1 =3D 0b00001111;
> > >>>TRISAbits.TRISA3 =3D 1;
> > >>>OpenPWM1(0x23);
> > >>>OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0
> interrupt */
> > >>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
> > >>> FALLING_EDGE_INT);
> > >>>EnableHighInterrupts();
> > >>>
> > >>>//Stilla =FAtganga
> > >>>PORTDbits.RD7 =3D 0; //Laser
> > >>>PORTEbits.RE0 =3D 0; //D=ED=F3=F0a
> > >>>SetDCPWM1(1000); //Hra=F0i =E1 m=F3tor
> > >>>
> > >>>while(~PORTBbits.RB2); //b=ED=F0ur eftir index merki
> > >>>//while(PORTAbits.RA3); //b=ED=F0ur eftir a=F0 =FDtt s=E9 =E1 takka
> > >>>
> > >>>while(1)
> > >>>{
> > >>> for(index =3D 0; index < 28;index++)
> > >>> {
> > >>> while(count <=3D points[index]);
> > >>> PORTDbits.RD7 =3D ~PORTDbits.RD7;
> > >>> }
> > >>>
> > >>> while(~PORTBbits.RB2);
> > >>> count =3D 0;
> > >>>}
> > >>>
> > >>>}
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>to unsubscribe, go to http://www.yahoogroups.com and follow the
> > >>>instructions
> > >>>
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 ..... and a new proble - john - Apr 26 0:04:40 2006
It sounds like the laser is asking for more then 20mA. A PIC can only
source about 20mA but the NE555 can source 100mA (at 5V).
--- In p...@yahoogroups.com, "mikerey35475"
wrote:
>
> How long are you leaving the laser turned on ? You will need to turn
> the laser on then delay a few microseconds say 20 to 50, then turn it
> off to allow time for it to fire. Otherwise the voltage supplied to
> the laser will never reach the threshold to turn the it on.
>=20
> Mike
>=20
> --- In p...@yahoogroups.com, "arnajon" wrote:
> >
> > I fixed the problem, and you were right: stack size.
> >=20
> > BUT... I have a fresh problem. The project I'm working on involves
> > blinking a laser at frequencies of something like 10-20kHz. The
> > circuit diagram can be found here:
> >=20
> > http://www.hi.is/~hrb/laser/schema.gif
> >=20
> > This diagram does not show the 0.01uF cap between GND and +5V. As you
> > can see I connected the laser directly to an IO pin, since it drains
> > less tha 20mA of current. My problem is however that I can't blink the
> > laser fast enough. If I increase the on/off frequency to the laser it
> > fades away. First I thought the laser just could not handle the Hz,
> > but I tried connecting it to a raw NE555 circuit @ 20kHZ and the laser
> > handled it just fine, so I'm pretty certain the problem lies in the RC
> > constant of my PIC circuit, but I have no clue how to fix it. Does the
> > size of the +5V-GND cap matter?
> >=20
> > Any ideas would be great.
> >=20
> > PS. The project is a simple laser text projector. You can see our
> > current results here (the image actually flickers so the actual image
> > does not look as good as the picture) :
> >=20
> > http://www.hi.is/~hrb/laser/abc.jpg
> >=20
> >=20
> > thank,
> > Arnar B.
> >=20
> > --- In p...@yahoogroups.com, DLC wrote:
> > >
> > > The stack has been my experience too. It is one of Microchip's
first=20
> > > suggestions as well.
> > >=20
> > > DLC
> > >=20
> > > Harold Hallikainen wrote:
> > > > I've also found C18 to be pretty reliable. When I've had very
> strange
> > > > problems, I've been able to fix it by making more room for the
> stack.
> > > > There's no warning that you've run out of stack space, stuff just
> > starts
> > > > returning strange values.
> > > >=20
> > > > One thing on a variable that's changed by an interrupt, I wonder
> > if maybe
> > > > the variable should be made "volatile." This generally refers to
> stuff
> > > > like I/O that can change without the compilers knowledge (or the
> > compiler
> > > > assumes it's the only thing that changes that variable). I've
> > never needed
> > > > to use the volatile modifier, but I wonder if it would help here.
> > > >=20
> > > > Harold
> > > >=20
> > > >=20
> > > >>What "doesn't work" about the code? I've found C18 has
numerous odd
> > > >>things that can occur, it has gotten better in later revs
though. I
> > > >>have seen very odd behavior myself in a few different areas but
> by and
> > > >>large C18 has been pretty solid.
> > > >>
> > > >>DLC
> > > >>
> > > >>arnajon wrote:
> > > >>
> > > >>>Hi everyone,
> > > >>>
> > > >>>I'm working on a project which includes a PIC18F4550. I'm
using the
> > > >>>microchip C18 compiler and I'm having an odd problem. I'm
using an
> > > >>>integer array of constants which I'm trying to reference using an
> > > >>>index which might not sound as a titanic task. Nontheless
this does
> > > >>>not work.
> > > >>>
> > > >>>This code works:
> > > >>>while(count <=3D points[0]);
> > > >>>
> > > >>>but this does not:
> > > >>>int index =3D 0;
> > > >>>while(count <=3D points[0]);
> > > >>>
> > > >>>the count variable is incremented via an interrupt.
> > > >>>
> > > >>>Thanks up front!
> > > >>>Arnar B. J=F3nsson
> > > >>>Mechanical engineering student
> > > >>>University of Iceland
> > > >>>
> > > >>>Here's the whole code if you're interested to help:
> > > >>>
> > > >>>#include /* for TRISB and PORTB declarations */
> > > >>>#include
> > > >>>#include
> > > >>>
> > > >>>#pragma config FOSC =3D HS
> > > >>>#pragma config BOR =3D ON
> > > >>>#pragma config WDT =3D OFF
> > > >>>#pragma config MCLRE =3D OFF
> > > >>>
> > > >>>unsigned int count =3D 0;
> > > >>>int points[28] =3D
> > >
> >>>{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,2=
19,252,257,262,268,272,287};
> > > >>>void blinkLaser(void); /* prototype needed for 'goto' below */
> > > >>>
> > > >>>#pragma code HIGH_INTERRUPT_VECTOR =3D 0x8
> > > >>>void high_ISR (void)
> > > >>>{
> > > >>>_asm
> > > >>>goto blinkLaser
> > > >>>_endasm
> > > >>>}
> > > >>>#pragma code /* allow the linker to locate the remaining code */
> > > >>>
> > > >>>#pragma interrupt blinkLaser
> > > >>>void blinkLaser (void)
> > > >>>{
> > > >>> count++;
> > > >>> INTCONbits.INT0IF =3D 0; /* clear flag to avoid another
interrupt */
> > > >>>}
> > > >>>
> > > >>>void EnableHighInterrupts (void)
> > > >>>{
> > > >>> RCONbits.IPEN =3D 1; /* enable interrupt priority levels */
> > > >>> INTCONbits.GIEH =3D 1; /* enable all high priority interrupts */
> > > >>>}
> > > >>>
> > > >>>void main (void)
> > > >>>{
> > > >>>//Breytur
> > > >>>int index =3D 0;
> > > >>>
> > > >>>//Upphafsstillingar
> > > >>>TRISE =3D 0;
> > > >>>TRISD =3D 0;
> > > >>>TRISB =3D 0b00000111;
> > > >>>ADCON1 =3D 0b00001111;
> > > >>>TRISAbits.TRISA3 =3D 1;
> > > >>>OpenPWM1(0x23);
> > > >>>OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0
> > interrupt */
> > > >>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
> > > >>> FALLING_EDGE_INT);
> > > >>>EnableHighInterrupts();
> > > >>>
> > > >>>//Stilla =FAtganga
> > > >>>PORTDbits.RD7 =3D 0; //Laser
> > > >>>PORTEbits.RE0 =3D 0; //D=ED=F3=F0a
> > > >>>SetDCPWM1(1000); //Hra=F0i =E1 m=F3tor
> > > >>>
> > > >>>while(~PORTBbits.RB2); //b=ED=F0ur eftir index merki
> > > >>>//while(PORTAbits.RA3); //b=ED=F0ur eftir a=F0 =FDtt s=E9 =E1 takk=
a
> > > >>>
> > > >>>while(1)
> > > >>>{
> > > >>> for(index =3D 0; index < 28;index++)
> > > >>> {
> > > >>> while(count <=3D points[index]);
> > > >>> PORTDbits.RD7 =3D ~PORTDbits.RD7;
> > > >>> }
> > > >>>
> > > >>> while(~PORTBbits.RB2);
> > > >>> count =3D 0;
> > > >>>}
> > > >>>
> > > >>>}
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>to unsubscribe, go to http://www.yahoogroups.com and follow the
> > > >>>instructions
> > > >>>
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )RE: Re: Problem with C18 ..... and a new problem - Alan Marconett - Apr 26 11:14:30 2006
Hi Arnar,
How about using a small transistor or an I.C. gate to switch the current?
Alan KM6VV
>
> It sounds like the laser is asking for more then 20mA. A PIC can only
> source about 20mA but the NE555 can source 100mA (at 5V).
>
> --- In p...@yahoogroups.com, "mikerey35475"
wrote:
> >
> > How long are you leaving the laser turned on ? You will need to turn
> > the laser on then delay a few microseconds say 20 to 50, then turn it
> > off to allow time for it to fire. Otherwise the voltage supplied to
> > the laser will never reach the threshold to turn the it on.
> >
> > Mike
> >
> > --- In p...@yahoogroups.com, "arnajon" wrote:
> > >
> > >
> > > I tried connecting it to a raw NE555 circuit @ 20kHZ and the laser
> > > handled it just fine, so I'm pretty certain the problem lies in the RC
> > > constant of my PIC circuit, but I have no clue how to fix it. Does the
> > > size of the +5V-GND cap matter?
> > >
> > > Any ideas would be great.
> > >
> > > thank,
> > > Arnar B.
> > >
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 ..... and a new proble - rtstofer - Apr 26 12:18:23 2006
In fact, if you look at the datasheet, you may find that the PIC can't
source much of anything while maintaining voltage. I don't use the
PIC18 series but for the PIC16F877A, spec D090 says the device can
source 3.0 mA while maintaining 4.3V of output.
In other words, they can't source anything. They can only sink 8.5 mA
while maintaining an output voltage of 0.6V. See spec D080 for the
16F877A.
Richard
--- In p...@yahoogroups.com, "john"
wrote:
>
> It sounds like the laser is asking for more then 20mA. A PIC can only
> source about 20mA but the NE555 can source 100mA (at 5V).
>=20
>=20
> --- In p...@yahoogroups.com, "mikerey35475" wrote:
> >
> > How long are you leaving the laser turned on ? You will need to turn
> > the laser on then delay a few microseconds say 20 to 50, then turn it
> > off to allow time for it to fire. Otherwise the voltage supplied to
> > the laser will never reach the threshold to turn the it on.
> >=20
> > Mike
> >=20
> > --- In p...@yahoogroups.com, "arnajon" wrote:
> > >
> > > I fixed the problem, and you were right: stack size.
> > >=20
> > > BUT... I have a fresh problem. The project I'm working on involves
> > > blinking a laser at frequencies of something like 10-20kHz. The
> > > circuit diagram can be found here:
> > >=20
> > > http://www.hi.is/~hrb/laser/schema.gif
> > >=20
> > > This diagram does not show the 0.01uF cap between GND and +5V.
As you
> > > can see I connected the laser directly to an IO pin, since it drains
> > > less tha 20mA of current. My problem is however that I can't
blink the
> > > laser fast enough. If I increase the on/off frequency to the
laser it
> > > fades away. First I thought the laser just could not handle the Hz,
> > > but I tried connecting it to a raw NE555 circuit @ 20kHZ and the
laser
> > > handled it just fine, so I'm pretty certain the problem lies in
the RC
> > > constant of my PIC circuit, but I have no clue how to fix it.
Does the
> > > size of the +5V-GND cap matter?
> > >=20
> > > Any ideas would be great.
> > >=20
> > > PS. The project is a simple laser text projector. You can see our
> > > current results here (the image actually flickers so the actual
image
> > > does not look as good as the picture) :
> > >=20
> > > http://www.hi.is/~hrb/laser/abc.jpg
> > >=20
> > >=20
> > > thank,
> > > Arnar B.
> > >=20
> > > --- In p...@yahoogroups.com, DLC wrote:
> > > >
> > > > The stack has been my experience too. It is one of Microchip's
> first=20
> > > > suggestions as well.
> > > >=20
> > > > DLC
> > > >=20
> > > > Harold Hallikainen wrote:
> > > > > I've also found C18 to be pretty reliable. When I've had very
> > strange
> > > > > problems, I've been able to fix it by making more room for the
> > stack.
> > > > > There's no warning that you've run out of stack space, stuff
just
> > > starts
> > > > > returning strange values.
> > > > >=20
> > > > > One thing on a variable that's changed by an interrupt, I wonder
> > > if maybe
> > > > > the variable should be made "volatile." This generally refers to
> > stuff
> > > > > like I/O that can change without the compilers knowledge (or the
> > > compiler
> > > > > assumes it's the only thing that changes that variable). I've
> > > never needed
> > > > > to use the volatile modifier, but I wonder if it would help
here.
> > > > >=20
> > > > > Harold
> > > > >=20
> > > > >=20
> > > > >>What "doesn't work" about the code? I've found C18 has
> numerous odd
> > > > >>things that can occur, it has gotten better in later revs
> though. I
> > > > >>have seen very odd behavior myself in a few different areas but
> > by and
> > > > >>large C18 has been pretty solid.
> > > > >>
> > > > >>DLC
> > > > >>
> > > > >>arnajon wrote:
> > > > >>
> > > > >>>Hi everyone,
> > > > >>>
> > > > >>>I'm working on a project which includes a PIC18F4550. I'm
> using the
> > > > >>>microchip C18 compiler and I'm having an odd problem. I'm
> using an
> > > > >>>integer array of constants which I'm trying to reference
using an
> > > > >>>index which might not sound as a titanic task. Nontheless
> this does
> > > > >>>not work.
> > > > >>>
> > > > >>>This code works:
> > > > >>>while(count <=3D points[0]);
> > > > >>>
> > > > >>>but this does not:
> > > > >>>int index =3D 0;
> > > > >>>while(count <=3D points[0]);
> > > > >>>
> > > > >>>the count variable is incremented via an interrupt.
> > > > >>>
> > > > >>>Thanks up front!
> > > > >>>Arnar B. J=F3nsson
> > > > >>>Mechanical engineering student
> > > > >>>University of Iceland
> > > > >>>
> > > > >>>Here's the whole code if you're interested to help:
> > > > >>>
> > > > >>>#include /* for TRISB and PORTB declarations */
> > > > >>>#include
> > > > >>>#include
> > > > >>>
> > > > >>>#pragma config FOSC =3D HS
> > > > >>>#pragma config BOR =3D ON
> > > > >>>#pragma config WDT =3D OFF
> > > > >>>#pragma config MCLRE =3D OFF
> > > > >>>
> > > > >>>unsigned int count =3D 0;
> > > > >>>int points[28] =3D
> > > >
> > >
> >>>{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,2=
19,252,257,262,268,272,287};
> > > > >>>void blinkLaser(void); /* prototype needed for 'goto' below */
> > > > >>>
> > > > >>>#pragma code HIGH_INTERRUPT_VECTOR =3D 0x8
> > > > >>>void high_ISR (void)
> > > > >>>{
> > > > >>>_asm
> > > > >>>goto blinkLaser
> > > > >>>_endasm
> > > > >>>}
> > > > >>>#pragma code /* allow the linker to locate the remaining
code */
> > > > >>>
> > > > >>>#pragma interrupt blinkLaser
> > > > >>>void blinkLaser (void)
> > > > >>>{
> > > > >>> count++;
> > > > >>> INTCONbits.INT0IF =3D 0; /* clear flag to avoid another
> interrupt */
> > > > >>>}
> > > > >>>
> > > > >>>void EnableHighInterrupts (void)
> > > > >>>{
> > > > >>> RCONbits.IPEN =3D 1; /* enable interrupt priority levels */
> > > > >>> INTCONbits.GIEH =3D 1; /* enable all high priority interrupts *=
/
> > > > >>>}
> > > > >>>
> > > > >>>void main (void)
> > > > >>>{
> > > > >>>//Breytur
> > > > >>>int index =3D 0;
> > > > >>>
> > > > >>>//Upphafsstillingar
> > > > >>>TRISE =3D 0;
> > > > >>>TRISD =3D 0;
> > > > >>>TRISB =3D 0b00000111;
> > > > >>>ADCON1 =3D 0b00001111;
> > > > >>>TRISAbits.TRISA3 =3D 1;
> > > > >>>OpenPWM1(0x23);
> > > > >>>OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0
> > > interrupt */
> > > > >>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for input */
> > > > >>> FALLING_EDGE_INT);
> > > > >>>EnableHighInterrupts();
> > > > >>>
> > > > >>>//Stilla =FAtganga
> > > > >>>PORTDbits.RD7 =3D 0; //Laser
> > > > >>>PORTEbits.RE0 =3D 0; //D=ED=F3=F0a
> > > > >>>SetDCPWM1(1000); //Hra=F0i =E1 m=F3tor
> > > > >>>
> > > > >>>while(~PORTBbits.RB2); //b=ED=F0ur eftir index merki
> > > > >>>//while(PORTAbits.RA3); //b=ED=F0ur eftir a=F0 =FDtt s=E9 =E1 ta=
kka
> > > > >>>
> > > > >>>while(1)
> > > > >>>{
> > > > >>> for(index =3D 0; index < 28;index++)
> > > > >>> {
> > > > >>> while(count <=3D points[index]);
> > > > >>> PORTDbits.RD7 =3D ~PORTDbits.RD7;
> > > > >>> }
> > > > >>>
> > > > >>> while(~PORTBbits.RB2);
> > > > >>> count =3D 0;
> > > > >>>}
> > > > >>>
> > > > >>>}
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>to unsubscribe, go to http://www.yahoogroups.com and follow the
> > > > >>>instructions
> > > > >>>
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 ..... and a new proble - arnajon - Apr 27 14:24:34 2006
Adding a transistor made a huge difference. Thanks for the help.
--- In p...@yahoogroups.com, "rtstofer"
wrote:
>
>=20
> In fact, if you look at the datasheet, you may find that the PIC can't
> source much of anything while maintaining voltage. I don't use the
> PIC18 series but for the PIC16F877A, spec D090 says the device can
> source 3.0 mA while maintaining 4.3V of output.
>=20
> In other words, they can't source anything. They can only sink 8.5 mA
> while maintaining an output voltage of 0.6V. See spec D080 for the
> 16F877A.
>=20
> Richard
>=20
> --- In p...@yahoogroups.com, "john" wrote:
> >
> > It sounds like the laser is asking for more then 20mA. A PIC can only
> > source about 20mA but the NE555 can source 100mA (at 5V).
> >=20
> >=20
> > --- In p...@yahoogroups.com, "mikerey35475" wrote:
> > >
> > > How long are you leaving the laser turned on ? You will need to turn
> > > the laser on then delay a few microseconds say 20 to 50, then
turn it
> > > off to allow time for it to fire. Otherwise the voltage supplied to
> > > the laser will never reach the threshold to turn the it on.
> > >=20
> > > Mike
> > >=20
> > > --- In p...@yahoogroups.com, "arnajon" wrote:
> > > >
> > > > I fixed the problem, and you were right: stack size.
> > > >=20
> > > > BUT... I have a fresh problem. The project I'm working on involves
> > > > blinking a laser at frequencies of something like 10-20kHz. The
> > > > circuit diagram can be found here:
> > > >=20
> > > > http://www.hi.is/~hrb/laser/schema.gif
> > > >=20
> > > > This diagram does not show the 0.01uF cap between GND and +5V.
> As you
> > > > can see I connected the laser directly to an IO pin, since it
drains
> > > > less tha 20mA of current. My problem is however that I can't
> blink the
> > > > laser fast enough. If I increase the on/off frequency to the
> laser it
> > > > fades away. First I thought the laser just could not handle
the Hz,
> > > > but I tried connecting it to a raw NE555 circuit @ 20kHZ and the
> laser
> > > > handled it just fine, so I'm pretty certain the problem lies in
> the RC
> > > > constant of my PIC circuit, but I have no clue how to fix it.
> Does the
> > > > size of the +5V-GND cap matter?
> > > >=20
> > > > Any ideas would be great.
> > > >=20
> > > > PS. The project is a simple laser text projector. You can see our
> > > > current results here (the image actually flickers so the actual
> image
> > > > does not look as good as the picture) :
> > > >=20
> > > > http://www.hi.is/~hrb/laser/abc.jpg
> > > >=20
> > > >=20
> > > > thank,
> > > > Arnar B.
> > > >=20
> > > > --- In p...@yahoogroups.com, DLC wrote:
> > > > >
> > > > > The stack has been my experience too. It is one of Microchip's
> > first=20
> > > > > suggestions as well.
> > > > >=20
> > > > > DLC
> > > > >=20
> > > > > Harold Hallikainen wrote:
> > > > > > I've also found C18 to be pretty reliable. When I've had very
> > > strange
> > > > > > problems, I've been able to fix it by making more room for the
> > > stack.
> > > > > > There's no warning that you've run out of stack space, stuff
> just
> > > > starts
> > > > > > returning strange values.
> > > > > >=20
> > > > > > One thing on a variable that's changed by an interrupt, I
wonder
> > > > if maybe
> > > > > > the variable should be made "volatile." This generally
refers to
> > > stuff
> > > > > > like I/O that can change without the compilers knowledge
(or the
> > > > compiler
> > > > > > assumes it's the only thing that changes that variable). I've
> > > > never needed
> > > > > > to use the volatile modifier, but I wonder if it would help
> here.
> > > > > >=20
> > > > > > Harold
> > > > > >=20
> > > > > >=20
> > > > > >>What "doesn't work" about the code? I've found C18 has
> > numerous odd
> > > > > >>things that can occur, it has gotten better in later revs
> > though. I
> > > > > >>have seen very odd behavior myself in a few different
areas but
> > > by and
> > > > > >>large C18 has been pretty solid.
> > > > > >>
> > > > > >>DLC
> > > > > >>
> > > > > >>arnajon wrote:
> > > > > >>
> > > > > >>>Hi everyone,
> > > > > >>>
> > > > > >>>I'm working on a project which includes a PIC18F4550. I'm
> > using the
> > > > > >>>microchip C18 compiler and I'm having an odd problem. I'm
> > using an
> > > > > >>>integer array of constants which I'm trying to reference
> using an
> > > > > >>>index which might not sound as a titanic task. Nontheless
> > this does
> > > > > >>>not work.
> > > > > >>>
> > > > > >>>This code works:
> > > > > >>>while(count <=3D points[0]);
> > > > > >>>
> > > > > >>>but this does not:
> > > > > >>>int index =3D 0;
> > > > > >>>while(count <=3D points[0]);
> > > > > >>>
> > > > > >>>the count variable is incremented via an interrupt.
> > > > > >>>
> > > > > >>>Thanks up front!
> > > > > >>>Arnar B. J=F3nsson
> > > > > >>>Mechanical engineering student
> > > > > >>>University of Iceland
> > > > > >>>
> > > > > >>>Here's the whole code if you're interested to help:
> > > > > >>>
> > > > > >>>#include /* for TRISB and PORTB declarations */
> > > > > >>>#include
> > > > > >>>#include
> > > > > >>>
> > > > > >>>#pragma config FOSC =3D HS
> > > > > >>>#pragma config BOR =3D ON
> > > > > >>>#pragma config WDT =3D OFF
> > > > > >>>#pragma config MCLRE =3D OFF
> > > > > >>>
> > > > > >>>unsigned int count =3D 0;
> > > > > >>>int points[28] =3D
> > > > >
> > > >
> > >
> >>>{0,5,10,15,20,35,63,68,73,78,88,93,126,141,151,156,189,194,199,204,214,2=
19,252,257,262,268,272,287};
> > > > > >>>void blinkLaser(void); /* prototype needed for 'goto'
below */
> > > > > >>>
> > > > > >>>#pragma code HIGH_INTERRUPT_VECTOR =3D 0x8
> > > > > >>>void high_ISR (void)
> > > > > >>>{
> > > > > >>>_asm
> > > > > >>>goto blinkLaser
> > > > > >>>_endasm
> > > > > >>>}
> > > > > >>>#pragma code /* allow the linker to locate the remaining
> code */
> > > > > >>>
> > > > > >>>#pragma interrupt blinkLaser
> > > > > >>>void blinkLaser (void)
> > > > > >>>{
> > > > > >>> count++;
> > > > > >>> INTCONbits.INT0IF =3D 0; /* clear flag to avoid another
> > interrupt */
> > > > > >>>}
> > > > > >>>
> > > > > >>>void EnableHighInterrupts (void)
> > > > > >>>{
> > > > > >>> RCONbits.IPEN =3D 1; /* enable interrupt priority levels */
> > > > > >>> INTCONbits.GIEH =3D 1; /* enable all high priority
interrupts */
> > > > > >>>}
> > > > > >>>
> > > > > >>>void main (void)
> > > > > >>>{
> > > > > >>>//Breytur
> > > > > >>>int index =3D 0;
> > > > > >>>
> > > > > >>>//Upphafsstillingar
> > > > > >>>TRISE =3D 0;
> > > > > >>>TRISD =3D 0;
> > > > > >>>TRISB =3D 0b00000111;
> > > > > >>>ADCON1 =3D 0b00001111;
> > > > > >>>TRISAbits.TRISA3 =3D 1;
> > > > > >>>OpenPWM1(0x23);
> > > > > >>>OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0
> > > > interrupt */
> > > > > >>> PORTB_PULLUPS_OFF & /* configure the RB0 pin for
input */
> > > > > >>> FALLING_EDGE_INT);
> > > > > >>>EnableHighInterrupts();
> > > > > >>>
> > > > > >>>//Stilla =FAtganga
> > > > > >>>PORTDbits.RD7 =3D 0; //Laser
> > > > > >>>PORTEbits.RE0 =3D 0; //D=ED=F3=F0a
> > > > > >>>SetDCPWM1(1000); //Hra=F0i =E1 m=F3tor
> > > > > >>>
> > > > > >>>while(~PORTBbits.RB2); //b=ED=F0ur eftir index merki
> > > > > >>>//while(PORTAbits.RA3); //b=ED=F0ur eftir a=F0 =FDtt s=E9 =E1 =
takka
> > > > > >>>
> > > > > >>>while(1)
> > > > > >>>{
> > > > > >>> for(index =3D 0; index < 28;index++)
> > > > > >>> {
> > > > > >>> while(count <=3D points[index]);
> > > > > >>> PORTDbits.RD7 =3D ~PORTDbits.RD7;
> > > > > >>> }
> > > > > >>>
> > > > > >>> while(~PORTBbits.RB2);
> > > > > >>> count =3D 0;
> > > > > >>>}
> > > > > >>>
> > > > > >>>}
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>>to unsubscribe, go to http://www.yahoogroups.com and
follow the
> > > > > >>>instructions
> > > > > >>>
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Re: Problem with C18 ..... and a new problem - David Duley - Apr 27 17:07:47 2006
Here is a chip that I have used in the past.
http://www.ichaus.de/productgroup.php?grp=Laser_Drivers
regards
Dave
On Wed, 26 Apr 2006 08:02:02 -0700, you wrote:
>Hi Arnar,
>
>How about using a small transistor or an I.C. gate to switch the current?
>
>Alan KM6VV
>
>>
>> It sounds like the laser is asking for more then 20mA. A PIC can only
>> source about 20mA but the NE555 can source 100mA (at 5V).
>>
>> --- In p...@yahoogroups.com, "mikerey35475"
wrote:
>> >
>> > How long are you leaving the laser turned on ? You will need to turn
>> > the laser on then delay a few microseconds say 20 to 50, then turn it
>> > off to allow time for it to fire. Otherwise the voltage supplied to
>> > the laser will never reach the threshold to turn the it on.
>> >
>> > Mike
>> >
>> > --- In p...@yahoogroups.com, "arnajon" wrote:
>> > >
>> > >
>> > > I tried connecting it to a raw NE555 circuit @ 20kHZ and the laser
>> > > handled it just fine, so I'm pretty certain the problem lies in the RC
>> > > constant of my PIC circuit, but I have no clue how to fix it. Does the
>> > > size of the +5V-GND cap matter?
>> > >
>> > > Any ideas would be great.
>> > >
>> > > thank,
>> > > Arnar B.
>> > >to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
>

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Problem with C18 ..... and a new proble - Vasile Surducan - May 20 2:45:14 2006
--- In p...@yahoogroups.com, "arnajon"
wrote:
>
> I fixed the problem, and you were right: stack size.
>=20
> BUT... I have a fresh problem. The project I'm working on involves
> blinking a laser at frequencies of something like 10-20kHz. The
> circuit diagram can be found here:
>=20
> http://www.hi.is/~hrb/laser/schema.gif
>=20
> This diagram does not show the 0.01uF cap between GND and +5V. As=20
you
> can see I connected the laser directly to an IO pin, since it drains
> less tha 20mA of current. My problem is however that I can't blink=20
the
> laser fast enough. If I increase the on/off frequency to the laser=20
it
> fades away. First I thought the laser just could not handle the Hz,
> but I tried connecting it to a raw NE555 circuit @ 20kHZ and the=20
laser
> handled it just fine, so I'm pretty certain the problem lies in the=20
RC
> constant of my PIC circuit, but I have no clue how to fix it. Does=20
the
> size of the +5V-GND cap matter?
It's matter just for killing the noise made by your PIC which is=20
switching.
Modulating ON-OFF a laser using the supply of the laser is a problem=20
of current flow and response time of the laser. If it works at 20KHz=20
(btw how did you check your laser light was indeed mosulated at 20KHz?
have you used a photodiode and a scope ?) than it must works from PIC=20
too.
Vasile
=20
to unsubscribe, go to http://www.yahoogroups.com and follow the instruction=
s=20
=20

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )