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

PWM with a range of 9-12 Hz
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kieran



Joined: 28 Nov 2003
Posts: 39
Location: Essex UK

View user's profile Send private message

PostPosted: Thu Dec 09, 2004 6:51 am     Reply with quote

Quote:
When the solenoid says rated at 30 Hz,


Sounds like an AC coil? Why do you need a PWM signal?
The solenoid is either on or off!
Nick
Guest







PostPosted: Wed Dec 15, 2004 2:02 pm     Reply with quote

Code:


#include <16F876.h>
//set fuses
#fuses HS,NOWDT,NOPROTECT,PUT//,//BROWNOUT,NOLVP
#use delay(clock=20000000)// 20mhz clock


//timer interupt
#int_timer2
void blah()
{
static long bs =0;
static long switch1 =0;

bs++;
   if (bs ==3)
      {
      if (switch1 ==0 ) {
                           output_high(PIN_B1);
                           switch1 =1;
     
                        }
      else                       
      if (switch1 ==1 ) {
     
                       output_low(PIN_B1);
                       switch1 =0;

                        }
     
         bs =0;
      }
}



void main()
{
int bs=0;

setup_timer_2(T2_DIV_BY_16, 217, 16);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);


while (true)
{
bs =1; // give something to do??
}

}



My calculations tell me that the code above should be around 30.0019 Hertz. The scope says it is about half of that, 14.99. Does a osiliscope measure edges or waves?

Nick
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Dec 15, 2004 2:23 pm     Reply with quote

It depends on the scope. Put you finger to the probe tip and you should get a 50 Hz or 60 Hz signal depending on what your power lines are. Then see what the scope calls it.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Nick
Guest







PostPosted: Wed Dec 15, 2004 2:36 pm     Reply with quote

the scope said 60hz

Which means?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 15, 2004 3:52 pm     Reply with quote

Nick wrote:
Code:


#include <16F876.h>
//set fuses
#fuses HS,NOWDT,NOPROTECT,PUT//,//BROWNOUT,NOLVP
#use delay(clock=20000000)// 20mhz clock


//timer interupt
#int_timer2
void blah()
{
static long bs =0;
static long switch1 =0;

bs++;
   if (bs ==3)
      {
      if (switch1 ==0 ) {
                           output_high(PIN_B1);
                           switch1 =1;
     
                        }
      else                       
      if (switch1 ==1 ) {
     
                       output_low(PIN_B1);
                       switch1 =0;

                        }
     
         bs =0;
      }
}



void main()
{
int bs=0;

setup_timer_2(T2_DIV_BY_16, 217, 16);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);


while (true)
{
bs =1; // give something to do??
}

}



My calculations tell me that the code above should be around 30.0019 Hertz. The scope says it is about half of that, 14.99. Does a osiliscope measure edges or waves?

Nick


I guess you didn't understand any of my posts. Your calculations are off by a factor of 2! A signal has a high time and low time and you are only counting one of them.

20MHz / 4 = 5MHz is the clock.
5MHz/ 16 = 312.5KHz after prescaler
312.5KHz/ 16 = 19.5KHz after postscaler
19.5KHz/ 217 = 90Hz is how often timer2 ints
90Hz / 6 = 15Hz, the 6 is from 3 counts high + 3 counts low!
Nick
Guest







PostPosted: Wed Dec 15, 2004 4:47 pm     Reply with quote

now I understand. Thank you so much!!

Nick
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 Previous  1, 2
Page 2 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