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 CCS Technical Support

Simple LED loop

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







Simple LED loop
PostPosted: Thu Nov 03, 2005 2:22 pm     Reply with quote

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);
}
}
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Thu Nov 03, 2005 2:40 pm     Reply with quote

First suggestion will be to change LVP to NOLVP.

Experts will probably find more....

Good luck,

John
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 03, 2005 3:34 pm     Reply with quote

..
edited... nice catch cmdrdan. ???sin wave???


Last edited by treitmey on Thu Nov 03, 2005 3:56 pm; edited 2 times in total
cmdrdan



Joined: 08 Apr 2005
Posts: 25
Location: Washington

View user's profile Send private message

Re: Simple LED loop
PostPosted: Thu Nov 03, 2005 3:46 pm     Reply with quote

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??
Dario
Guest







Simple LED
PostPosted: Thu Nov 03, 2005 5:06 pm     Reply with quote

Changing to a square wave makes no differerence,

thanks for the advice.
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

Round waves into square holes!!
PostPosted: Thu Nov 03, 2005 6:07 pm     Reply with quote

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.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Nov 03, 2005 6:55 pm     Reply with quote

Change the HS fuse to XT
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Dario
Guest







LEDs
PostPosted: Thu Nov 03, 2005 8:00 pm     Reply with quote

Thanks guys,

the NOLVP solution was it!!

Sin wave works fine.
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Thu Nov 03, 2005 8:07 pm     Reply with quote

Very Happy


YES! Newbie, knucklehead gets one right!


Gloatingly,

John
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