![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
geeth9
Joined: 17 Mar 2010 Posts: 2
|
Generate a 50 Hz signal |
Posted: Sun Oct 31, 2010 12:20 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Sun Oct 31, 2010 2:39 pm |
|
|
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... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 31, 2010 2:55 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|