View previous topic :: View next topic |
Author |
Message |
Kieran
Joined: 28 Nov 2003 Posts: 39 Location: Essex UK
|
|
Posted: Thu Dec 09, 2004 6:51 am |
|
|
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
|
|
Posted: Wed Dec 15, 2004 2:02 pm |
|
|
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
|
|
Posted: Wed Dec 15, 2004 2:23 pm |
|
|
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
|
|
Posted: Wed Dec 15, 2004 2:36 pm |
|
|
the scope said 60hz
Which means? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Dec 15, 2004 3:52 pm |
|
|
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
|
|
Posted: Wed Dec 15, 2004 4:47 pm |
|
|
now I understand. Thank you so much!!
Nick |
|
|
|