View previous topic :: View next topic |
Author |
Message |
sword
Joined: 28 Dec 2004 Posts: 6
|
pulsout 0.1-5 Hz |
Posted: Mon Jan 10, 2005 3:05 am |
|
|
Hi,
How can I generate pulse between 0.1-5hz in background. |
|
|
Ttelmah Guest
|
Re: pulsout 0.1-5 Hz |
Posted: Mon Jan 10, 2005 6:51 am |
|
|
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
|
|
Posted: Mon Jan 10, 2005 7:12 am |
|
|
16f877a (20MHz)
Pulsout-on/off(square) |
|
|
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Mon Jan 10, 2005 8:32 am |
|
|
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
|
|
Posted: Mon Jan 10, 2005 10:06 am |
|
|
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
|
|
Posted: Tue Jan 11, 2005 1:07 am |
|
|
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 |
|
|
|