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

Generate a 50 Hz signal

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



Joined: 17 Mar 2010
Posts: 2

View user's profile Send private message

Generate a 50 Hz signal
PostPosted: Sun Oct 31, 2010 12:20 pm     Reply with quote

I am trying to generate a PWM sinal with a frequency of 46.5 HZ . I found a post in the forum which explains how to get that. I tried it and the code is:
Code:

#include<18f4520.h>      //Device Header
#fuses H4,NOPROTECT,NOWDT,PUT   // Set Fuses
#use delay(clock=2000000)   //20Mhz Clock
#use RS232 (baud=9600, parity = N, xmit = PIN_C6, rcv=PIN_C7)
 

#define PWM_PIN  PIN_E1

#define LOOPCNT 20

int8 width;

//-------------------------------
#INT_RTCC
void tick_interrupt(void);

//====================================
main()
{
width = 15;

setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
 
while(1);
}

//====================================
#INT_RTCC
void tick_interrupt(void)
{
static int8 loop = LOOPCNT;
static int8 pulse;

if(--loop == 0)
  {
   loop = LOOPCNT;
   pulse = width;
  }

if(pulse)
  {
   output_high(PWM_PIN);
   pulse--;
  }
else
  {
   output_low(PWM_PIN);
  }

}

The problem is that, it generates a 11.63 HZ signal and I am unable to increase the frequency.
Please suggest a solution. Thanks in advance.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 31, 2010 2:39 pm     Reply with quote

Your 11.64 hz is 1/4 that of the 46.5 that you want..so... it's probably in the 'fuses' configuration or setup that is wrong..off by a factor of 4.

I don't use the 18 series but others may know the corect config which may depend upon the version of the compiler...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 31, 2010 2:55 pm     Reply with quote

Quote:
#include<18f4520.h> //Device Header
#fuses H4,NOPROTECT,NOWDT,PUT // Set Fuses
#use delay(clock=2000000) //20Mhz Clock
#use RS232 (baud=9600, parity = N, xmit = PIN_C6, rcv=PIN_C7)

Your #use delay() statement doesn't have 20 MHz in it. It has a smaller
number. Also, the 'H4' fuse is normally used with a 10 MHz crystal to
run the PIC at 40 MHz. 'H4' means the 4x PLL is enabled in the PIC.
This is the maximum speed of the 18F452.

If you have a 20 MHz crystal and you want to run the PIC at 20 MHz,
then use the 'HS' fuse, and edit the #use delay() so it says 20 MHz.
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