View previous topic :: View next topic |
Author |
Message |
Dario Guest
|
Simple LED loop |
Posted: Thu Nov 03, 2005 2:22 pm |
|
|
For some reason the delay_ms does not seem to be working. I have the osc1 pin hooked to a function generator at 4 000 000Hz from 0-5V sin wave. afetr programming, the output pin A0 will pulse on for 600us and off for 200us. Could anyone tell me if there is something wrong with my code or if this is a sign that my programmer or CCS or MPLAB are not working properly. Thanks. Dario
------------------------------------------------------------------------------
#include <16F873A.h>
#device adc=8
#fuses NOWDT,HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, LVP, NOCPD, NOWRT
#use delay(clock=4000000)
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
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);
set_tris_a(0x00);
while(TRUE)
{
output_high(PIN_A0);
delay_ms(1500);
output_low(PIN_A0);
delay_ms(1000);
}
} |
|
![](templates/subSilver/images/spacer.gif) |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Nov 03, 2005 2:40 pm |
|
|
First suggestion will be to change LVP to NOLVP.
Experts will probably find more....
Good luck,
John |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Nov 03, 2005 3:34 pm |
|
|
..
edited... nice catch cmdrdan. ???sin wave???
Last edited by treitmey on Thu Nov 03, 2005 3:56 pm; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
cmdrdan
Joined: 08 Apr 2005 Posts: 25 Location: Washington
|
Re: Simple LED loop |
Posted: Thu Nov 03, 2005 3:46 pm |
|
|
Dario wrote: | For some reason the delay_ms does not seem to be working. I have the osc1 pin hooked to a function generator at 4 000 000Hz from 0-5V sin wave. } |
What happens when you use a square wave instead of a sine wave?? |
|
![](templates/subSilver/images/spacer.gif) |
Dario Guest
|
Simple LED |
Posted: Thu Nov 03, 2005 5:06 pm |
|
|
Changing to a square wave makes no differerence,
thanks for the advice. |
|
![](templates/subSilver/images/spacer.gif) |
neil
Joined: 08 Sep 2003 Posts: 128
|
Round waves into square holes!! |
Posted: Thu Nov 03, 2005 6:07 pm |
|
|
I was going to reply to this sooner, but got sidetracked...
Don't be misled by a sinewave seeming odd on a digital device. The CLKOUT pin drives the crystal with a (square?) wave to set it into oscillation, but the xtal 'rings' with a sinewave at its fundamental frequency. The xtal's oscillation is fed back into the CLKIN pin, which will be converted to a squarewave internally (probably by a schmitt trigger, I have not looked at the datasheet at this point!) to form the clock source for the pic. So, you have two options ,when specifying a xtal oscillator; you can use a crystal (or resonator) to self oscillate, or feed a logic level waveform into the CLKIN pin from a 'canned oscillator' or a signal generator, or anything you like and ignore the CLKOUT signal from the pic.
Because of the squaring done by the (schmitt?) you can probably feed in any periodic signal within the allowed thresholds and it will work as a reliable clock source. |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Nov 03, 2005 6:55 pm |
|
|
Change the HS fuse to XT _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
Dario Guest
|
LEDs |
Posted: Thu Nov 03, 2005 8:00 pm |
|
|
Thanks guys,
the NOLVP solution was it!!
Sin wave works fine. |
|
![](templates/subSilver/images/spacer.gif) |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Nov 03, 2005 8:07 pm |
|
|
YES! Newbie, knucklehead gets one right!
Gloatingly,
John |
|
![](templates/subSilver/images/spacer.gif) |
|