Archive: Programing PIC16f873 for PWM

Status
Not open for further replies.

Thread Starter

damochi

Joined Feb 17, 2006
40
address 0 ---> goto INIT ; First instruction executed when RESET is complete
Rich (BB code):
...
address xx --->INIT:
           Initialize registers for port pins
           Initialize and configure A/D Converter
           Initialize and configure PWM
           Initialize register file variables
...
...
address yy ----> MAIN_LOOP:
            Start an A/D conversion
            While(A/D converter is busy) do nothing
            Read 10 bit A/D result
            Copy A/D result into PWM duty cycle register
            For 10 milliseconds -- do nothing
            goto MAIN_LOOP
Right now i have only got the codes for the address xx------> INIT part but the what about the MAIN LOOP?
 

Thread Starter

damochi

Joined Feb 17, 2006
40
i have actually m,odify the code and see what yu think about this

Rich (BB code):
#include <P16f873.inc>
  org 0
;Set the PWM period (976Hz = 1.025ms) by writing to the PR2 register
  

 movlw  0xff      ;255-dec = 0xff-hex
 bsf   STATUS,RP0   ;use bank 1
 movwf  PR2      ;setting the period of PWM
 bcf   STATUS,RP0   ;return to bank 0

;Set the PWM Duty Cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. 

 movlw 0x80      ;10000000-bin = 0x80-hex
 movwf CCPR1L     ;load 0x80 in W to CCPR1L
 bcf  CCP1CON,CCP1X; ;set bit 1 of the duty cycle
 bcf  CCP1CON,CCP1Y; ;set bit 0 of the duty cycle


;Make the CCP1 pin an output by clearing the TRISC<2> bit 
   
 bsf  STATUS,RP0   ;move to bank 1
 movlw 0xfb      ;11111011-bin = 0xfb-hex
 andwf TRISC      ;clear TRISC<2>
 bcf  STATUS,RP0   ;return to bank 0

;Set the TMR2 prescale value and enable TMR2 by writing to T2CON.

 movlw 0x05      ;TMR2 on, prescale = 4
 movwf T2CON      ;load 0x05 into T2CON reg


;Configure the CCP1 module for PWM 
 movf CCP1CON, W
 andlw 0x30      ;mask all but prev. set duty cycle bits
 iorlw 0x0f        ;and enable PWM mode
 movwf CCP1CON

   END
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by damochi@Mar 11 2006, 12:34 PM
On line 21 i have replaced (ANDWF with CLRF) what do yu think about that
[post=14874]Quoted post[/post]​
The CLRF instruction will of course clear all the bits in the TRISC register and make them all outputs. This should be OK since you are not using any other pins on PORT C for any purpose. If you were using other pins on PORT C then you would need another method. My solution along with yours would be
Rich (BB code):
    BSF    STATUS,RP0
    MOVLW  H'FB'
    ANDWF  TRISC,f
    BCF    STATUS,RP0
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by damochi@Mar 11 2006, 04:05 PM
i have actually m,odify the code and see what yu think about this

Rich (BB code):
#include <P16f873.inc>
   org 0
;Set the PWM period (976Hz = 1.025ms) by writing to the PR2 register
    

 movlw   0xff          ;255-dec = 0xff-hex
 bsf     STATUS,RP0    ;use bank 1
 movwf   PR2            ;setting the period of PWM
 bcf     STATUS,RP0    ;return to bank 0

;Set the PWM Duty Cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. 

  movlw  0x80            ;10000000-bin = 0x80-hex
  movwf  CCPR1L          ;load 0x80 in W to CCPR1L
  bcf    CCP1CON,CCP1X;  ;set bit 1 of the duty cycle
  bcf    CCP1CON,CCP1Y;  ;set bit 0 of the duty cycle
;Make the CCP1 pin an output by clearing the TRISC<2> bit 
     
  bsf    STATUS,RP0      ;move to bank 1
  movlw  0xfb            ;11111011-bin = 0xfb-hex
  andwf  TRISC          ;clear TRISC<2>
  bcf    STATUS,RP0      ;return to bank 0

;Set the TMR2 prescale value and enable TMR2 by writing to T2CON.

  movlw  0x05            ;TMR2 on, prescale = 4
  movwf  T2CON          ;load 0x05 into T2CON reg
;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30            ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON

     END
[post=14883]Quoted post[/post]​
I think this should work for the initialization of the PWM. Way to go.
 

Thread Starter

damochi

Joined Feb 17, 2006
40
i was reading about a/d conversion and i came up with this steps

To perform the A/D conversion and output the result to port C follow the following:
1. First we need to configure port A for A/D conversion and port C to be an
output.
To configure port C to be output we have to clear the TRISC (0x87) register.
To configure port A for A/D conversion we need to clear
ADCON<6:5:4:3:2:1:0> bits.
The 10-bit result is read into 2 8-bit registers: ADRESH and ADRESL
Set ADCON<7>: right justified. 6 most significant bits of ADRESH are read
as zeros.
Clear ADCON<7>: left justified. 6 least significant bits of ADRESL are read
as zeros.
Rich (BB code):
bsf STATUS ,RP0;move to bank 1
bcf STATUS ,RP1
movlw 0x00
movwf TRISC;clear TRISC, port C output
clrf ADCON1;left justified, all input A/D
bcf STATUS, RP0;return to bank 0
movlw 0x41;fosc/8 [7-6],A/D on ch0[5-3]
2. Start the A/D conversion by setting ADCON0<2>
Rich (BB code):
bsf ADCON0,GO;start the A/D conversion
3. Wait until the A/D conversion is done. Bit ADCON0<2> is cleared when
conversion is done.
Rich (BB code):
Wait: btfsc ADCON0,GO;wait until conversion is done
goto Wait
4. Write the 8 most significant bits located in ADRESH (since we setup the
registers to be left justified) to port C as an output.
Rich (BB code):
movf ADRESH,W
movwf PORTC;write value to port C
so what do yu think
 

Thread Starter

damochi

Joined Feb 17, 2006
40
so basically i've got a code like this
Rich (BB code):
#include <P16f873.inc>
   org 0
;Set the PWM period (976Hz = 1.025ms) by writing to the PR2 register
    

 movlw   0xff          ;255-dec = 0xff-hex
 bsf     STATUS,RP0    ;use bank 1
 movwf   PR2            ;setting the period of PWM
 bcf     STATUS,RP0    ;return to bank 0

;Set the PWM Duty Cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. 

  movlw  0x80            ;10000000-bin = 0x80-hex
  movwf  CCPR1L          ;load 0x80 in W to CCPR1L
  bcf    CCP1CON,CCP1X;  ;set bit 1 of the duty cycle
  bcf    CCP1CON,CCP1Y;  ;set bit 0 of the duty cycle


;Make the CCP1 pin an output by clearing the TRISC<2> bit 
     
  bsf    STATUS,RP0      ;move to bank 1
  movlw  0xfb            ;11111011-bin = 0xfb-hex
  andwf  TRISC          ;clear TRISC<2>
  bcf    STATUS,RP0      ;return to bank 0

;Set the TMR2 prescale value and enable TMR2 by writing to T2CON.

  movlw  0x05            ;TMR2 on, prescale = 4
  movwf  T2CON          ;load 0x05 into T2CON reg


;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30            ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON

     END

;configure port A for A/D conversion and port C to be an output.

   bsf STATUS ,RP0      ;move to bank 1
   bcf STATUS ,RP1
   movlw 0x00
   movwf TRISC          ;clear TRISC, port C output
   clrf ADCON1          ;left justified, all input A/D
   bcf STATUS, RP0      ;return to bank 0
   movlw 0x41          ;fosc/8 [7-6],A/D on ch0[5-3]

;Start the A/D conversion by setting ADCON0<2>

   bsf ADCON0,GO        ;start the A/D conversion

;Wait until the A/D conversion is done. Bit ADCON0<2> is cleared when conversion is done.
 
   Wait: btfsc ADCON0,GO;wait until conversion is done
 goto Wait

;Write the 8 most significant bits located in ADRESH (since i've setup the registers to be left justified) to port C as an output.
   movf ADRESH,W
   movwf PORTC        ;write value to port C
     end
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by damochi@Mar 11 2006, 05:12 PM
so basically i've got a code like this
Rich (BB code):
#include <P16f873.inc>
   org 0
;Set the PWM period (976Hz = 1.025ms) by writing to the PR2 register
    

 movlw   0xff          ;255-dec = 0xff-hex
 bsf     STATUS,RP0    ;use bank 1
 movwf   PR2            ;setting the period of PWM
 bcf     STATUS,RP0    ;return to bank 0

;Set the PWM Duty Cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. 

  movlw  0x80            ;10000000-bin = 0x80-hex
  movwf  CCPR1L          ;load 0x80 in W to CCPR1L
  bcf    CCP1CON,CCP1X;  ;set bit 1 of the duty cycle
  bcf    CCP1CON,CCP1Y;  ;set bit 0 of the duty cycle
;Make the CCP1 pin an output by clearing the TRISC<2> bit 
     
  bsf    STATUS,RP0      ;move to bank 1
  movlw  0xfb            ;11111011-bin = 0xfb-hex
  andwf  TRISC          ;clear TRISC<2>
  bcf    STATUS,RP0      ;return to bank 0

;Set the TMR2 prescale value and enable TMR2 by writing to T2CON.

  movlw  0x05            ;TMR2 on, prescale = 4
  movwf  T2CON          ;load 0x05 into T2CON reg
;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30            ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON

     END

;configure port A for A/D conversion and port C to be an output.

   bsf STATUS ,RP0      ;move to bank 1
   bcf STATUS ,RP1
   movlw 0x00
   movwf TRISC          ;clear TRISC, port C output
   clrf ADCON1          ;left justified, all input A/D
   bcf STATUS, RP0      ;return to bank 0
   movlw 0x41          ;fosc/8 [7-6],A/D on ch0[5-3]

;Start the A/D conversion by setting ADCON0<2>

   bsf ADCON0,GO        ;start the A/D conversion

;Wait until the A/D conversion is done. Bit ADCON0<2> is cleared when conversion is done.
 
   Wait: btfsc ADCON0,GO;wait until conversion is done
 goto Wait

;Write the 8 most significant bits located in ADRESH (since i've setup the registers to be left justified) to port C as an output.
   movf ADRESH,W
   movwf PORTC        ;write value to port C
     end
[post=14887]Quoted post[/post]​
I'm sorry -- I thought we were done -- my mistake.

Superficially, there cannot be two "END" statements in one program. You need only one "END" statement at the actual end of your text file.

I do not understand why you are writing the A/D result high to Port C. What you are supposed to do is write the 10bit result into the duty cycle registers,
CCPR1L and CCP1CON<5:4>. Look ant the initialization code where we set the duty cycle registers to H'80':b'00' to initialize a 50% duty cycle.

After you do this you need a goto instruction to go back to the point where you read the A/D converter again. If you look at the flow chart of the algorithm you need to wait for a while before you do this so the change in the PWM has a chance to take effect. I'd suggest 10-20 milliseconds at a minimum.
 

Thread Starter

damochi

Joined Feb 17, 2006
40
thanks for the explaination and i have made some modifications and i still don't understand what yu mean by waiting do mean like creating a delay like this?
Rich (BB code):
      ;PROCEDURE ShortDelay()
ShortDelay	CLRF  ShortDel;  ShortDel=0
      ;  DO
ShortDelDo	DECFSZ	ShortDel,F;    ShortDel=ShortDel-1
  GOTO  ShortDelDo;  UNTIL ShortDel=0
  RETURN  ;END PROCEDURE
anyway this is what i've got at the moment
Rich (BB code):
#include <P16f873.inc>
 __CONFIG _RC_OSC & _CP_OFF & _WDT_OFF & _PWRTE_ON &_LVP_OFF
  
   org 0
;set A/D Conversion

  bsf     STATUS,RP0        ;move to bank 1
  bcf     STATUS,RP1
  clrf    ADCON1            ;left justified, all input A/D
  bcf      STATUS, RP0        ;return to bank 0
  movlw    0x41              ;fosc/8 [7-6],A/D on ch0[5-3]

;Set the PWM period (976Hz = 1.025ms) by writing to the PR2 register
    

 movlw   0xff          ;255-dec = 0xff-hex
 bsf     STATUS,RP0    ;use bank 1
 movwf   PR2            ;setting the period of PWM
 bcf     STATUS,RP0    ;return to bank 0

;Set the PWM Duty Cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. 

  movlw  0x80            ;10000000-bin = 0x80-hex
  movwf  CCPR1L          ;load 0x80 in W to CCPR1L
  bcf    CCP1CON,CCP1X;  ;set bit 1 of the duty cycle
  bcf    CCP1CON,CCP1Y;  ;set bit 0 of the duty cycle


;Make the CCP1 pin an output by clearing the TRISC<2> bit 
     
  bsf    STATUS,RP0      ;move to bank 1
  movlw  0xfb            ;11111011-bin = 0xfb-hex
  andwf  TRISC          ;clear TRISC<2>
  bcf    STATUS,RP0      ;return to bank 0

;Set the TMR2 prescale value and enable TMR2 by writing to T2CON.

  movlw  0x05            ;TMR2 on, prescale = 4
  movwf  T2CON          ;load 0x05 into T2CON reg


;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30              ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON


;Start the A/D conversion by setting ADCON0<2>

start: bsf ADCON0,GO        ;start the A/D conversion
Wait: btfsc ADCON0,GO      ;wait until conversion is done
 goto Wait

;Write the 8 most significant bits located in ADRESH (since we setup the registers to be left justified) to Value
  movf ADRESH,W
  movwf CCPR1L      ;write value into PWM
  bcf CCP1CON,CCP1X
  bcf CCP1CON,CCP2Y

;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30              ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON
  goto start
     END
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by damochi@Mar 14 2006, 07:47 PM
thanks for the explaination and i have made some modifications and i still don't understand what yu mean by waiting do mean like creating a delay like this?
Rich (BB code):
      ;PROCEDURE ShortDelay()
ShortDelay	CLRF  ShortDel;  ShortDel=0
      ;  DO
ShortDelDo	DECFSZ	ShortDel,F;    ShortDel=ShortDel-1
  GOTO  ShortDelDo;  UNTIL ShortDel=0
  RETURN  ;END PROCEDURE
anyway this is what i've got at the moment
Rich (BB code):
#include <P16f873.inc>
 __CONFIG _RC_OSC & _CP_OFF & _WDT_OFF & _PWRTE_ON &_LVP_OFF
  
   org 0
;set A/D Conversion

  bsf     STATUS,RP0        ;move to bank 1
  bcf     STATUS,RP1
  clrf    ADCON1            ;left justified, all input A/D
  bcf      STATUS, RP0        ;return to bank 0
  movlw    0x41              ;fosc/8 [7-6],A/D on ch0[5-3]

;Set the PWM period (976Hz = 1.025ms) by writing to the PR2 register
    

 movlw   0xff          ;255-dec = 0xff-hex
 bsf     STATUS,RP0    ;use bank 1
 movwf   PR2            ;setting the period of PWM
 bcf     STATUS,RP0    ;return to bank 0

;Set the PWM Duty Cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. 

  movlw  0x80            ;10000000-bin = 0x80-hex
  movwf  CCPR1L          ;load 0x80 in W to CCPR1L
  bcf    CCP1CON,CCP1X;  ;set bit 1 of the duty cycle
  bcf    CCP1CON,CCP1Y;  ;set bit 0 of the duty cycle
;Make the CCP1 pin an output by clearing the TRISC<2> bit 
     
  bsf    STATUS,RP0      ;move to bank 1
  movlw  0xfb            ;11111011-bin = 0xfb-hex
  andwf  TRISC          ;clear TRISC<2>
  bcf    STATUS,RP0      ;return to bank 0

;Set the TMR2 prescale value and enable TMR2 by writing to T2CON.

  movlw  0x05            ;TMR2 on, prescale = 4
  movwf  T2CON          ;load 0x05 into T2CON reg
;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30              ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON
;Start the A/D conversion by setting ADCON0<2>

start: bsf ADCON0,GO        ;start the A/D conversion
Wait: btfsc ADCON0,GO      ;wait until conversion is done
 goto Wait

;Write the 8 most significant bits located in ADRESH (since we setup the registers to be left justified) to Value
  movf ADRESH,W
  movwf CCPR1L      ;write value into PWM
  bcf CCP1CON,CCP1X
  bcf CCP1CON,CCP2Y

;Configure the CCP1 module for PWM 
  movf CCP1CON, W
  andlw 0x30              ;mask all but prev. set duty cycle bits
  iorlw 0x0f              ;and enable PWM mode
  movwf CCP1CON
  goto start
     END
[post=14992]Quoted post[/post]​
You are correct. The purpose of the delay, where you do absolutely nothing is to allow the PWM to be active for a few cycles before you change it again. Remember the "moving coil" is like a low pass filter. It will not respond to high frequency changes. At 976 Hz. each cycle is just over 1 millisecond. So in processor terms you need a long delay on the order of 10 to 20 milliseconds. Rather than counting instructions you should familiarize yourself with the operation of Timer 0 and Timer 1 and their respective prescalers and postsaclers.

Good Luck
 

Mazaag

Joined Oct 23, 2004
255
Originally posted by Papabravo@Mar 14 2006, 08:16 PM
You are correct. The purpose of the delay, where you do absolutely nothing is to allow the PWM to be active for a few cycles before you change it again. Remember the "moving coil" is like a low pass filter. It will not respond to high frequency changes. At 976 Hz. each cycle is just over 1 millisecond. So in processor terms you need a long delay on the order of 10 to 20 milliseconds. Rather than counting instructions you should familiarize yourself with the operation of Timer 0 and Timer 1 and their respective prescalers and postsaclers.

Good Luck
[post=14996]Quoted post[/post]​
Hey guys,
I have been following your discussion and have learnt ALOT. However, I have a few questions.

Firstly , Syntax.

btfsc ADCON0,GO

what does the GO mean ?
and what does btfsc do ?

Secondly, how does writing the value obtained from the A/D to CCPR1L control the duty cycle? I mean , does it compare it to the Vref value and assign a percentage automatically ? or is there some code which I am not seeing that takes in this digital value, and assign it as a percentage ?

Thanks
 

Mazaag

Joined Oct 23, 2004
255
Originally posted by Mazaag@Mar 14 2006, 10:30 PM
Hey guys,
I have been following your discussion and have learnt ALOT. However, I have a few questions.

Firstly , Syntax.

btfsc ADCON0,GO

what does the GO mean ?
and what does btfsc do ?

Secondly, how does writing the value obtained from the A/D to CCPR1L control the duty cycle? I mean , does it compare it to the Vref value and assign a percentage automatically ? or is there some code which I am not seeing that takes in this digital value, and assign it as a percentage ?

Thanks
[post=15005]Quoted post[/post]​
Another quick one.

bsf STATUS,RP0 ;move to bank 1
movlw 0xfb ;11111011-bin = 0xfb-hex
andwf TRISC ;clear TRISC<2>
bcf STATUS,RP0 ;return to bank 0


What is the use of the andwf ? if you need to clear TRISC<2> , why not just move the value of w ( 11111011) to f (TRISC) ?

Thanks
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by Mazaag@Mar 14 2006, 11:30 PM
Hey guys,
I have been following your discussion and have learnt ALOT. However, I have a few questions.

Firstly , Syntax.

btfsc ADCON0,GO

what does the GO mean ?
and what does btfsc do ?

Secondly, how does writing the value obtained from the A/D to CCPR1L control the duty cycle? I mean , does it compare it to the Vref value and assign a percentage automatically ? or is there some code which I am not seeing that takes in this digital value, and assign it as a percentage ?

Thanks
[post=15005]Quoted post[/post]​
btfsc is the instruction "bit test file, skip if clear"
This instruction will test a single bit in one of the registers in the register file.
The address of the register is given by ADCON0 which for the PIC16F873 is at address H'1F'. The bit in question is the GO/DONE* bit which is bit 2 of the ADCON0 register. When the bit is clear it means the A/D conversion is finished and the result can be read from the result register.

The value read from the A/D result register can be viewed as the fraction of Vref present at the analog input. As such it has the same relation to Vref as duty cycle does to the period represented by the period register PR2.

He really should also take the two least significant bits of the A/D result and write them to bits 5 and 4 of CCP1CON instead of setting them to zero as we did in the initialization. Then we have 10 bit A/D result is equal to 10 bit duty cycle.
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by Mazaag@Mar 14 2006, 11:41 PM
Another quick one.

bsf STATUS,RP0 ;move to bank 1
movlw 0xfb ;11111011-bin = 0xfb-hex
andwf TRISC ;clear TRISC<2>
bcf STATUS,RP0 ;return to bank 0
What is the use of the andwf ? if you need to clear TRISC<2> , why not just move the value of w ( 11111011) to f (TRISC) ?

Thanks
[post=15006]Quoted post[/post]​
An excellent question. We use the ANDWF to preserve the other bits in the TRISC register. Imagine that each bit of Port C is initialized and used by a different software module or that one of the bits can be both an input and an output. Using this sequence we can change only the bit we want to change and leave the remainder undisturbed.

If there is to be a one time initialization of the TRISC register then moving an 8 bit constant from W to the TRISC register works just fine.

The actual instruction should be written
Rich (BB code):
ANDWF  TRISC,f
The trailing f tells the assembler to code the instruction in such a way that the result of anding W with TRISC is supposed tobe written back to TRISC. The other possibility is to write the result back to W which wouldn't be much use in this instance.
 

Mazaag

Joined Oct 23, 2004
255
Rich (BB code):
#include <P16f873.inc>
__CONFIG _RC_OSC & _CP_OFF & _WDT_OFF & _PWRTE_ON &_LVP_OFF
 
 org 0

Is that all the code that is required before the actual program ?
Usually when I start a project in MPLAB , a whole lot of other stuff appears as part of the template. Can I get rid of all that clutter and just leave those lines of code?
I know what th #include does, but I am not sure about the other two lines.

Thanks
 

Thread Starter

damochi

Joined Feb 17, 2006
40
Originally posted by Mazaag@Mar 16 2006, 04:25 PM
Rich (BB code):
#include <P16f873.inc>
__CONFIG _RC_OSC & _CP_OFF & _WDT_OFF & _PWRTE_ON &_LVP_OFF
 
  org 0
Is that all the code that is required before the actual program ?
Usually when I start a project in MPLAB , a whole lot of other stuff appears as part of the template. Can I get rid of all that clutter and just leave those lines of code?
I know what th #include does, but I am not sure about the other two lines.

Thanks
[post=15054]Quoted post[/post]​
i have included the second line because it configures the PIC automatically instead of me doing it manually when i want to actaully program the PIC and also the purpose of Org 0 is to put the following instruction in memory location 0 which is where the pic will start executing from on start
hope that helps
 

Papabravo

Joined Feb 24, 2006
18,777
Originally posted by damochi@Mar 16 2006, 01:40 PM
i have included the second line because it configures the PIC automatically instead of me doing it manually when i want to actaully program the PIC and also the purpose of Org 0 is to put the following instruction in memory location 0 which is where the pic will start executing from on start
hope that helps
[post=15055]Quoted post[/post]​
In a thread on the PIC16F877 and MPLAB I made a recent discovery that because several different functions are multiplexed onto each pin it is necessary to examine closely with the MPLAB simulator that the port pins are correctly configured.

I don't know if this is affecting your PWM output but it is worth a close look at the datasheet where the I/O ports are described.
 
Status
Not open for further replies.
Top