caramoan tour package

caramoan tour package

Author Topic: PWM using CCS and Proteus  (Read 1789 times)

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
PWM using CCS and Proteus
« on: October 17, 2009, 04:20:12 PM »
I have been trying to create a PWM in CCS using PIC16F648A, natry ako mag simulate sa proteus pero wala lumalabas sa RB3.

INTRC ang gamit ko, may nakapagtry na ba gumawa ng PWM using the builtin hardware ng PIC.

Thanks.

Philippine Electronics Forum

PWM using CCS and Proteus
« on: October 17, 2009, 04:20:12 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: PWM using CCS and Proteus
« Reply #1 on: October 17, 2009, 04:40:00 PM »
I have been trying to create a PWM in CCS using PIC16F648A, natry ako mag simulate sa proteus pero wala lumalabas sa RB3.

INTRC ang gamit ko, may nakapagtry na ba gumawa ng PWM using the builtin hardware ng PIC.

Thanks.

glen, nahirapan din akong gawin yan sa CCS C. di ko nga nagawa talga... ilang beses na namin yan kinulit ni Rafft. di talga...

I ended up using HitechC. para lang mapagana ang PWM ng PIC16F628A.

Subukan ko kayan register to register ang usapan... heheh ;D
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: PWM using CCS and Proteus
« Reply #1 on: October 17, 2009, 04:40:00 PM »

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6130
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: PWM using CCS and Proteus
« Reply #2 on: October 17, 2009, 04:43:52 PM »
glen, nahirapan din akong gawin yan sa CCS C. di ko nga nagawa talga... ilang beses na namin yan kinulit ni Rafft. di talga...

I ended up using HitechC. para lang mapagana ang PWM ng PIC16F628A.

Subukan ko kayan register to register ang usapan... heheh ;D


ibig sabihin parang may problem yung CCS pagdating jan? nainvenstigate ba yung disassembly listing?
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Philippine Electronics Forum

Re: PWM using CCS and Proteus
« Reply #2 on: October 17, 2009, 04:43:52 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: PWM using CCS and Proteus
« Reply #3 on: October 17, 2009, 05:04:53 PM »
eto... its working! based lahat sa datasheet... heheh ;D
dinifine ko lahat!

Code: [Select]
#include <16F648A.h>

#FUSES NOWDT,INTRC_IO,NOPUT,NOPROTECT,NOBROWNOUT,MCLR,NOLVP,NOCPD     

#BYTE CCP1CON=0x17
#BYTE T2CON=0x12
#BYTE PR2=0x92
#BYTE CCPR1L=0x15

#bit  OSCF=0x8E.3
#bit  TRISB3=0x86.3

#bit  CCP1X=CCP1CON.5
#bit  CCP1Y=CCP1CON.4
#bit  CCP1M3=CCP1CON.3
#bit  CCP1M2=CCP1CON.2
#bit  CCP1M1=CCP1CON.1
#bit  CCP1M0=CCP1CON.0

#bit  TOUTPS3=T2CON.6
#bit  TOUTPS2=T2CON.5
#bit  TOUTPS1=T2CON.4
#bit  TOUTPS0=T2CON.3
#bit  TMR2ON=T2CON.2
#bit  T2CKPS1=T2CON.1
#bit  T2CKPS0=T2CON.0



void main()
{
   
   OSCF = 1;         //4MHZ internal oscillator

   CCP1M3 = 1; CCP1M2 = 1;      //CCP PWM mode   
   
   T2CKPS1 = 0; T2CKPS0 = 1;   //prescale 1:4
   
   //given: 5Khz PWM
   //PWM period = [PR2 + 1]*4*Tosc*TMR2prescale   
   //1/5k = (PR2+1)*4*(1/4M)*4
   //PR2 + 1 = 4000000/(5000*4*4)
   //PR2 = 49
   PR2 = 49;
   
   //duty cycle = 50%; PR2 *2 = 98 = 0b1100010
   CCPR1L = 0b00011000;
   CCP1X = 1; CCP1Y = 0;

   TRISB3 = 0;               //RB3 as output
   
   TMR2ON = 1;                //timer2 ON
   
   while(TRUE);

}


di ako marunong masyado magbasa ng LST... papano ba sis?
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: PWM using CCS and Proteus
« Reply #3 on: October 17, 2009, 05:04:53 PM »

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Re: PWM using CCS and Proteus
« Reply #4 on: October 17, 2009, 05:09:59 PM »
Kabwisit nga eh, kanina pa ako kakaisip kung ano diprensa ng code ko!

Kahit yung sa CCS forums na example na-try ko na using PIC16F877A eh wala pa rin!

Code ko sa PIC16F877A

Code: [Select]
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,124,1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(512);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   
   while(1);

}

Code sa CCS C forum, both not working!

Code: [Select]
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

main()
{
output_low(PIN_C1);   // Set CCP2 output low
output_low(PIN_C2);   // Set CCP1 output low

setup_ccp1(CCP_PWM);  // Configure CCP1 as a PWM
setup_ccp2(CCP_PWM);  // Configure CCP2 as a PWM

setup_timer_2(T2_DIV_BY_16, 124, 1);  // 500 Hz     
set_pwm1_duty(31);                    // 25% duty cycle on pin C2
set_pwm2_duty(62);                    // 50% duty cycle on pin C1

while(1);  // Prevent PIC from going to sleep  (Important !)
}

Philippine Electronics Forum

Re: PWM using CCS and Proteus
« Reply #4 on: October 17, 2009, 05:09:59 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: PWM using CCS and Proteus
« Reply #5 on: October 17, 2009, 05:13:37 PM »
pero try mo same code sa ibang PIC16F its working. ;D

library issue lang naman siguro.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Re: PWM using CCS and Proteus
« Reply #6 on: October 17, 2009, 05:17:52 PM »
Sa iba? PIC16F877A na gamit ko. Ano si mga na try mo?

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: PWM using CCS and Proteus
« Reply #7 on: October 17, 2009, 05:25:27 PM »
ay sorry... dai man palan. naribong ako. CCP capture palan si naiisip ko...

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Re: PWM using CCS and Proteus
« Reply #8 on: October 17, 2009, 05:34:46 PM »
Bro, nakua ko na, dai nag o-on ag timer 2, dapat mag execute ka TMR2ON=1; tig chop chop ko ang put@ng in@!

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: PWM using CCS and Proteus
« Reply #9 on: October 17, 2009, 05:42:33 PM »
hahaha pareho kita... uyan man.

Code: [Select]
#include <16F648A.h>

#FUSES NOWDT,INTRC_IO,NOPUT,NOPROTECT,NOBROWNOUT,MCLR,NOLVP,NOCPD


void main()
{
   setup_oscillator(OSC_4MHZ);
 
   setup_timer_2(T2_DIV_BY_4,249,1);
   set_pwm1_duty(512);
   setup_ccp1(CCP_PWM);
  
   set_timer2(0);       //add this after setting everything for PWM.
                        //this is PR2
  
   while(TRUE);

}
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Re: PWM using CCS and Proteus
« Reply #10 on: October 17, 2009, 05:59:35 PM »
nalingawan yan ilaag sa documenttation ah.

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6028
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: PWM using CCS and Proteus
« Reply #11 on: October 17, 2009, 06:09:24 PM »
^iyo ngani... dai ko pa man yan nababasa...

ok na yan. at least aram ta na.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: PWM using CCS and Proteus
« Reply #11 on: October 17, 2009, 06:09:24 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com