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

Help me with a TMR0 PWM ADC problem

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



Joined: 13 Aug 2013
Posts: 2

View user's profile Send private message

Help me with a TMR0 PWM ADC problem
PostPosted: Tue Aug 13, 2013 11:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 13, 2013 12:35 pm     Reply with quote

Quote:

#int_TIMER0
int pulse_max=0;
int16 adc=0,pulse_top=10; //min
void TIMER0_isr(void) {

Read this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=46477&start=4
souyirouh



Joined: 13 Aug 2013
Posts: 2

View user's profile Send private message

PostPosted: Tue Aug 13, 2013 12:58 pm     Reply with quote

GOD BLESS YOU MAN !!!!!

PCM programmer wrote:
Quote:

#int_TIMER0
int pulse_max=0;
int16 adc=0,pulse_top=10; //min
void TIMER0_isr(void) {

Read this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=46477&start=4
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