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

Delay_ms not stopping my code
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
anthory



Joined: 24 Jun 2013
Posts: 6

View user's profile Send private message

Delay_ms not stopping my code
PostPosted: Wed Oct 23, 2013 10:18 am     Reply with quote

Hello,

First off sorry for not posting my version of compiler but I can't seem to find where it tell me what version I have. Where is it located at?

I'm programming a pic18f46k80, I also don't have internet on the computer I am programming on so I going to type it out. If I take out the delay I can see it change on my oscope but once I put one in it never makes it to the second set_pwm.

main.h
Code:

#include <18F46K80.h>

#FUSES NOWDT
#FUSES WDT128
#FUSES NOXINST
#FUSES WDT_NOSLEEP

#use delay(clock=16000000)

main.c
Code:

#include<main.h>

void main()
{
setup_ccp5(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 255,1);

long duty;


  while(1)
  {
    duty=100;
    set_pwm5_duty(duty);
    delay_ms(1000);
    duty=200;
    set_pwm5_duty(duty);
    delay_ms(1000);
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 23, 2013 11:31 am     Reply with quote

Quote:
I can't seem to find where it tell me what version I have. Where is it located at?

Look at the top of the .LST file for your project. It will be in the project
directory after a successful compilation. Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo

Quote:

#include <18F46K80.h>

#FUSES NOWDT
#FUSES WDT128
#FUSES NOXINST
#FUSES WDT_NOSLEEP

#use delay(clock=16000000)

I also don't have internet on the computer I am programming on so I going to type it out.

You're missing the oscillator fuse.
anthory



Joined: 24 Jun 2013
Posts: 6

View user's profile Send private message

PostPosted: Wed Oct 23, 2013 11:59 am     Reply with quote

I added in the #FUSES LP and tried #FUSES HS neither it didnt work. It is still getting hung up on the delay_ms statements.

Also the link you posted brings me to what the software versions fixed not how to find out what version I have.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Wed Oct 23, 2013 12:11 pm     Reply with quote

The link he posted was an EXAMPLE of version numbers (what to look for). As he indicated, at the top of the list file it will list the compiler version number.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 23, 2013 12:25 pm     Reply with quote

Post the manufacturer and name of your PIC development board. Post a
link to it.

If you built the board yourself, describe the crystal or external oscillator
circuit (if any), that is connected to the 18F46K80's oscillator pins.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 1:03 am     Reply with quote

Let's take things very slowly:

1) As PCM programmer has explained, the compiler version number is in the very first line of the .lst file generated when you compile. Find it, and post it. There are several numbers in this line, so he has also posted a link showing you what the version number looks like.

2) We need to know something about your hardware. What oscillator have you got attached to the chip?. LP won't work except with a low power (perhaps 100KHz or slower crystal) attached, while HS won't work without a crystal between perhaps 5MHz, and 25MHz attached. What have you got?. Key thing in programming and electronics design in general is _precision_. The clock statement says you are meant to be using a 16MHz oscillator, and won't work right, till you _are_ using such an oscillator.

3) How fast is the PWM you see without the delay?.
anthory



Joined: 24 Jun 2013
Posts: 6

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 7:57 am     Reply with quote

Let's take things very slowly:

1) As PCM programmer has explained, the compiler version number is in the very first line of the .lst file generated when you compile. Find it, and post it. There are several numbers in this line, so he has also posted a link showing you what the version number looks like.

2) We need to know something about your hardware. What oscillator have you got attached to the chip?. LP won't work except with a low power (perhaps 100KHz or slower crystal) attached, while HS won't work without a crystal between perhaps 5MHz, and 25MHz attached. What have you got?. Key thing in programming and electronics design in general is _precision_. The clock statement says you are meant to be using a 16MHz oscillator, and won't work right, till you _are_ using such an oscillator.

3) How fast is the PWM you see without the delay?.



1) Sorry about that. I am quite new to programming. verision 4.135

2) The pic data sheet states it has three Internal Oscillators: LF-INTOSC (31 KHz),
MF-INTOSC (500 kHz) and HF-INTOSC (16 MHz).

http://ww1.microchip.com/downloads/en/DeviceDoc/39977f.pdf

3) #use delay(clock=16Mhz)
PWM=1.9kHz


#FUSES LP
PWM= 95-105Hz
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 8:17 am     Reply with quote

#fuses LP is not an alternative to #use delay(clock= 16M)

You have to specify both the type of oscillator as TTelmah has shown, and also the frequency with #use delay.
anthory



Joined: 24 Jun 2013
Posts: 6

View user's profile Send private message

reply
PostPosted: Thu Oct 24, 2013 8:55 am     Reply with quote

#fuses LP is not an alternative to #use delay(clock= 16M)

You have to specify both the type of oscillator as TTelmah has shown, and also the frequency with #use delay.



So if i specify #fuses LP i need to specify my clock to be #use (delay=31000) correct?

What do I use if I want the clock to be 16M? I dont see and #FUSES for it on this website http://www.ccsinfo.com/forum/viewtopic.php?t=31698
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 9:33 am     Reply with quote

Get your brain round a simple thing. Your _hardware_ has to match what you want to run.

If you want to run a crystal at 16MHz, you need to start with the crystal. Then HS, and clock=16MHz. LP, is saying to use a low power crystal, so again the crystal (typically a 32768Hz watch one), and clock=32768.

With your reference to 31KHz, I suspect you actually want to use the internal oscillator. In which case you need:

Code:

#FUSES INTRC_LP
#use delay(CLOCK=31000)
//For 31KHz

//or.....
#FUSES INTRC_HP
#use delay(CLOCK=16MHz)
//for 16MHz


You always need to start with the data sheet. Work out what oscillator you want, and what the configuration has to be for that oscillator (both hardware and software). Then refer to the list 'fuses.txt' in the compiler directory to work out what CCS fuse name corresponds to the fuses you need.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 2:17 pm     Reply with quote

One of the simplest (and best) pieces of test equipment is the simple LED on the board. put a routine to flash it at a 1 hz rate. If it isn't flashing at 1 HZ, then you don't have the oscillator configured correctly and everything else is going to be screwed up that uses timing. If you don't have an LED on the board, just a spare pin configured to change state at 1hz is good too. Without the clock right, you are just wasting your time on the rest of the stuff.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
anthory



Joined: 24 Jun 2013
Posts: 6

View user's profile Send private message

reply
PostPosted: Thu Oct 24, 2013 2:46 pm     Reply with quote

Quote:
Get your brain round a simple thing. Your _hardware_ has to match what you want to run.

If you want to run a crystal at 16MHz, you need to start with the crystal. Then HS, and clock=16MHz. LP, is saying to use a low power crystal, so again the crystal (typically a 32768Hz watch one), and clock=32768.

With your reference to 31KHz, I suspect you actually want to use the internal oscillator. In which case you need:

Code:

#FUSES INTRC_LP
#use delay(CLOCK=31000)
//For 31KHz

//or.....
#FUSES INTRC_HP
#use delay(CLOCK=16MHz)
//for 16MHz



You always need to start with the data sheet. Work out what oscillator you want, and what the configuration has to be for that oscillator (both hardware and software). Then refer to the list 'fuses.txt' in the compiler directory to work out what CCS fuse name corresponds to the fuses you need.



Ok thanks. I didnt realize I needed the INTRC in front of the HP or LP.
So I have tried them both out and both will work. Now my problems how to calculate the delays with each.

Also does the frequency of the pulse need to be synced up with the 110V 60hz light I'm trying to control?

Quote:
One of the simplest (and best) pieces of test equipment is the simple LED on the board. put a routine to flash it at a 1 hz rate. If it isn't flashing at 1 HZ, then you don't have the oscillator configured correctly and everything else is going to be screwed up that uses timing. If you don't have an LED on the board, just a spare pin configured to change state at 1hz is good too. Without the clock right, you are just wasting your time on the rest of the stuff.


I will try this as well. Thanks!

Also Im having trouble submiting my reply's....I have to hit submit a bunch of times before it will actually submit.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 3:58 pm     Reply with quote

This is the first mention of trying to control a light - if you are trying to do phase control of the light (dimmer) then you need to work the problem of using a zero crossing detector to sync up. If you are simply flashing a light or something like that, that is different. Phase control is a different critter and needs to by sync'd to the AC line frequency unless you want really strange effects (although Halloween is coming up shortly ... )

If you are trying to implement a dimmer, do a search here or globally for "phase control" or "dimmer" for more info.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Oct 25, 2013 1:29 am     Reply with quote

Also, you are not going to get very far with a CPU clock of 31000Hz, for anything involving phase control.

31000Hz = 7750 instruction/second.

Remember these are machine instruction, not C instructions. A simple C line line a=b*c, using int16, will take 236 machine instructions. 3 hundredths of a second. If trying to work with mains at 50 Hz, then you get a zero crossing every hundredth of a second, while at 60Hz, every 120th second. So just this one multiplication would take over three half cycles of the mains.....

The low speed clock, is designed for ultra low power operation, for things where being 'slow' doesn't matter. Not for anything that needs to work quickly.

Best Wishes
anthory



Joined: 24 Jun 2013
Posts: 6

View user's profile Send private message

reply
PostPosted: Fri Oct 25, 2013 9:35 am     Reply with quote

Quote:
Posted: Thu Oct 24, 2013 3:58 pm Post subject:

--------------------------------------------------------------------------------

This is the first mention of trying to control a light - if you are trying to do phase control of the light (dimmer) then you need to work the problem of using a zero crossing detector to sync up. If you are simply flashing a light or something like that, that is different. Phase control is a different critter and needs to by sync'd to the AC line frequency unless you want really strange effects (although Halloween is coming up shortly ... )

If you are trying to implement a dimmer, do a search here or globally for "phase control" or "dimmer" for more info.

mikey


I know this is the first I have mentioned lighting control but was just trying to get a simple delay working first. I will do more research on phase control or dimmer.

Quote:
Posted: Fri Oct 25, 2013 1:29 am Post subject:

--------------------------------------------------------------------------------

Also, you are not going to get very far with a CPU clock of 31000Hz, for anything involving phase control.

31000Hz = 7750 instruction/second.

Remember these are machine instruction, not C instructions. A simple C line line a=b*c, using int16, will take 236 machine instructions. 3 hundredths of a second. If trying to work with mains at 50 Hz, then you get a zero crossing every hundredth of a second, while at 60Hz, every 120th second. So just this one multiplication would take over three half cycles of the mains.....

The low speed clock, is designed for ultra low power operation, for things where being 'slow' doesn't matter. Not for anything that needs to work quickly.

Best Wishes


I plan on using the fastest clock speed of 16Mhz. Thanks for the info.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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