View previous topic :: View next topic |
Author |
Message |
souyirouh
Joined: 13 Aug 2013 Posts: 2
|
Help me with a TMR0 PWM ADC problem |
Posted: Tue Aug 13, 2013 11:45 am |
|
|
I'm trying to do a PWM control for a servo so i end up doing it with the TMR0 cause in my opinion is the most exactly but i don't know exactly what is the problem with my program. It doesn't show any error and the logic behind it is good or at least i think so, anyway when i try to simulate it in Proteus it doesn't send the PWM signal, the TMR0 interrupt should appear each 0.1 that's why i put set_timer0(6) . I hope someone could help me here.
Code: |
#include <16f877.h>
#device adc=10
#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP,NOBROWNOUT,NOWRT
#use delay(clock=20000000)
#define MAX_VALUE 200
#int_TIMER0
int pulse_max=0;
int16 adc=0,pulse_top=10; //min
void TIMER0_isr(void) {
if (pulse_max<=pulse_top)
output_high(PIN_B0);
else
output_low(PIN_B0);
if (pulse_max>=MAX_VALUE)
pulse_max=0;
pulse_max++;
set_timer0(6);
}
void main(){
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
set_timer0(6);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
for(;;){
set_adc_channel(0);
delay_us(20);
adc=read_adc();
pulse_top=(10*adc+10230)/1023;
//x= (max-min)adc + 1023*min )/1023
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
souyirouh
Joined: 13 Aug 2013 Posts: 2
|
|
Posted: Tue Aug 13, 2013 12:58 pm |
|
|
GOD BLESS YOU MAN !!!!!
|
|
|
|