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

pulsout 0.1-5 Hz

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



Joined: 28 Dec 2004
Posts: 6

View user's profile Send private message

pulsout 0.1-5 Hz
PostPosted: Mon Jan 10, 2005 3:05 am     Reply with quote

Hi,
How can I generate pulse between 0.1-5hz in background.
Ttelmah
Guest







Re: pulsout 0.1-5 Hz
PostPosted: Mon Jan 10, 2005 6:51 am     Reply with quote

sword wrote:
Hi,
How can I generate pulse between 0.1-5hz in background.

What chip?.
What clock rate?.
Square wave, or will any pulse width work?.
Generally, this sort of frequency, can be produced by the PWM modules, but the clock rate will need to be fairly low to handle the slowest frequency required (max will be just over 400KHz). If the system frequency is too high, then instead an external divider will have to be added, and fed from the PWM output.

Best Wishes
sword



Joined: 28 Dec 2004
Posts: 6

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 7:12 am     Reply with quote

16f877a (20MHz)
Pulsout-on/off(square)
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 8:32 am     Reply with quote

This worked for me. I did not put it on the scope.....
Toggles output in interrupt....

Code:
#include "header.h"
int freq,incnt;


#int_TIMER1
TIMER1_isr()
{

incnt++;
if (incnt >= freq) {
   incnt = 0;
   output_toggle(pin_b4);
}   
set_timer1(3036); //makes for even .05s interrupts (10 Hz)
// freq = 1, b4 (yellow led on CCS board) flashes at 10Hz
// freq = 200, b4 flashes at .1 Hz
}



void main()
{

   setup_adc(ADC_CLOCK_INTERNAL  );
   setup_adc_ports(AN0);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_timer1(3036);//makes for even .05s interrupts (10 Hz)
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);


//  Do whatever you want below here....
   set_adc_channel(0);

while (1)  {

   delay_ms( 100 );

   freq = read_adc();
   if (freq == 0) freq = 1;
}



}
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 10:06 am     Reply with quote

I noticed the resolution of the above is not that great.
Freq = 1 = 10Hz
Freq = 2 = 5Hz
etc...

What kind of resolution do you need? The timer and constant can be modified to get better resolutions....
sword



Joined: 28 Dec 2004
Posts: 6

View user's profile Send private message

PostPosted: Tue Jan 11, 2005 1:07 am     Reply with quote

Hi,
I'm newbe, the value is variable.For example

out(5Hz) = setpoint-adread //(1)
out(1Hz) = setpoint-adread //(4)
out(0.5Hz) = setpoint-adread //(9)
etc...
Resolution must be between 5-0.2 Hz
Thanks
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