Hi guys ,

i am trying the get PWM (CCP4) output to work on PortG.3 of the 18F67k22 series

what i am seeing so far is that the port seems to put out some pulses then stops , so it seems that i have part of the setup correct

i am thinking that i am also effecting other ports with the setting as other activity on portF , and G seem to sometimes have an effect , but i cant seem to isolate exactly what it is so far

the output pulses rates etc dont matter at this point just as long as it outputs all the time for a test of the PWM function on this pin only

what am i missing


cheers

sheldon


http://ww1.microchip.com/downloads/e...Doc/39960d.pdf


Code:
'    -------   Setup port G Variables  ----------     
   ' port G has 6 I/O only , G5 - Always input ( uses CONFIG3H - MCLRE = OFF for I/O use)  
    CM3CON = 0                 ' Disable comparator 3 on PORTG
    
    ANCON2.0 = 0               ' Set PortG:4 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL16 
    ANCON2.1 = 0               ' Set PortG:3 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL17
    ANCON2.2 = 0               ' Set PortG:2 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL18
    ANCON2.3 = 0               ' Set PortG:1 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL19
    
    TRISG = %00100000          ' ports Output , Row_1 output  portG.5 always input ( internal pullup) VPP/MCLR ,CCP4 output
    FLASH_CE     var PORTG.2   ' FLASH CE - active low - uses SPI bus 
    PWM_TEST VAR PORTG.3   ' CCP4 - PWM outout to control the contrast on glcd       
  
  
   PORTG  =  %00100000        ' Clear Outputs , 
   flash_ce = 1               ' set high as active low 
   PWM_TEST = 0          ' active high

Code:
'---------- PWM OUTPUT REGISTER SETUP --------------------- 
    ' setup CCP4 - PORTG.3 for PWM_CONTRAST control
    ' PWM FRQ = 1/PWM period
    ' When TMR2 = PR2 = start of duty cycle(on Time ) , start of period length
    ' when TMR2 = CCPR4L:CCP4CON5:4 = End of duty cycle , START OF OFF TIME  
    ' when TMR2 = PR2 = End of period , start of duty cycle AGAIN 
   
   
    CCPTMRS1 = %00000000   ' select TM1/TM2 for CCP4 use ( TIMER2 used for PWM)                      
    CCP4CON  = %00001100   ' Setup CCP4 single output for PWM , bits 3,2 , bits 5,4 = 9th and 10 bit of duty cycle ,
    CCPR4L   = 100         ' Lower Byte register for DUTY CYCLE OF PWM  - 8 bits of duty cycle 
    ODCON2.1  = 0          ' set CCP4OD pin not enabled FOR OPen drain  
    PR2      = 100         ' set the PWM period = [(PR2+1)x 4xTosc / TM2 prescale value  
    T2CON    = %00000101   ' Timer 2 ON - POSTSCALLER SETTING NOT USED BY PWM , OLY PRESCALE SETTING - PRESCALE: 00 =1 ,01 = 4,1x = 16
                           ' ( bit 7 = x, bit6-3 postscale, bit2=0 timer off ,bit1-0 = prescale )
    TMR2     =  200