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

PWM with 18F4431

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



Joined: 04 Apr 2014
Posts: 7
Location: Viet Nam

View user's profile Send private message

PWM with 18F4431
PostPosted: Mon Jun 09, 2014 9:29 pm     Reply with quote

I have 2 motor. I use PWM with PIC18F4431. but I use Proteus for simulation. It not run. Help me with problem.
Code:
#include "D:\Do line\main.h"
#fuses hs, nowdt, noprotect, nowrt, nolvp, hpol_low
#use delay(clock=20000000)

#byte porta=0xf80
#byte portb=0xf81
#byte portc=0xf82
#byte portd=0xf83
#byte porte=0xf84
/////////////
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)

#bit dk0 = portb.5
#bit dk2 = portb.2
#bit start = portd.0
#bit stop = portd.1
#bit cb0 = porta.0
#bit cb1 = porta.1
#bit cb2 = porta.2
#bit cb3 = porta.3
#bit cb4 = porta.4
#bit cb5 = porta.5


int1 flag = 0;
void button(void)
{
   if(start == 0 && stop == 1)/// && flag == 0)
   {flag = 1;}
   if(start == 1 && stop == 0)// && flag == 1)
   {flag = 0;}
}
void main()
{
      SET_TRIS_A (0xFF);
      SET_TRIS_B (0X00);
      SET_TRIS_C (0X00);
      SET_TRIS_D (0X0F);
      SET_TRIS_E (0B111);
      SETUP_POWER_PWM_PINS(PWM_ODD_ON,PWM_ODD_ON,PWM_ODD_ON,PWM_ODD_ON);
      SETUP_POWER_PWM(PWM_CLOCK_DIV_64|PWM_FREE_RUN,1,0,250,0,1,0); //15kHz--333
      SETUP_TIMER_2(T2_DIV_BY_1,255,1);
      dk0 = 0;
      dk2 = 0;
      set_power_pwm0_duty(0);
      set_power_pwm2_duty(0);   
      while(true)
      {
      button();
      if(flag == 1)
      {
         dk0 = dk2 = 1;
         delay_ms(70);
         set_power_pwm0_duty(700);
         set_power_pwm2_duty(700);
      }
      if(flag == 0)
      {
         dk0 = dk2 = 0;
         delay_ms(70);
         set_power_pwm0_duty(0);
         set_power_pwm2_duty(0);
      }
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 09, 2014 9:32 pm     Reply with quote

There are working examples in the forum archives. Search for them
and use them. Here is one:
http://www.ccsinfo.com/forum/viewtopic.php?t=37206
tien168bn



Joined: 04 Apr 2014
Posts: 7
Location: Viet Nam

View user's profile Send private message

PostPosted: Mon Jun 09, 2014 9:44 pm     Reply with quote

PCM programmer wrote:
There are working examples in the forum archives. Search for them
and use them. Here is one:
http://www.ccsinfo.com/forum/viewtopic.php?t=37206

I use module PWM of 18F4431. but It not run. Have something wrong? This code, in last year, it run with my robot. and now, it not run :(. both simulation and in the circuit
tien168bn



Joined: 04 Apr 2014
Posts: 7
Location: Viet Nam

View user's profile Send private message

PostPosted: Mon Jun 09, 2014 9:49 pm     Reply with quote

The signal in RB5(PWM5) not change.@@
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 10, 2014 12:36 am     Reply with quote

Quote:
The signal in RB5(PWM5) not change

The PWM5 signal does not come out on pin RB5. It comes out on pin RB4.

I ran the program in my link (in hardware) and I can see PWM pulses on:
PWM1 - pin 34 - RB1
PWM3 - pin 36 - RB3
PWM5 - pin 37 - RB4
PWM7 - pin 30 - RD7

This is with the 40-pin DIP package of the 18F4431.
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