HPWM with Pic16F886 not working


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default HPWM with Pic16F886 not working

    Hi,
    I am trying to make a HPWM on pin RC2 ( CCP1 on a Pic 16F886 chip.
    I am not getting anything out.
    I used the same code but formatted for 16F88 and it worked, so I dont know why I am not getting anything out.
    Any ideas ?
    thanks

    Ken


    Code:
    OSCCON = %01110000 '8 Mhz
    DEFINE OSC 8
    ANSELH = 0
    ADCON1 = 7
     
    '///////////////////////////
    '// Interrupt section //
    '///////////////////////////
    
    '////////// ADCin Config //////////////////
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    ADCON0 = %00010001 ' AN4, Configure and turn on A/D Module
    ADCON1 = %00000001 ' Analog input
    
    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////
    
    
    DEFINE LCD_DREG PORTB 	' Set LCD Data port
    DEFINE LCD_DBIT 4 		' Set starting Data bit (0 or 4) if 4-bit bus  RB.4, RB.5, RB.6, RB.7
    DEFINE LCD_RSREG PORTC 	' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 		' Set LCD Register Select bit
    DEFINE LCD_EREG PORTA	' Set LCD Enable port
    DEFINE LCD_EBIT 7 		' Set LCD Enable bit
    DEFINE LCD_BITS 4 		' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD
    DEFINE LCD_LINES 2 		' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000
    
    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////
    
    Digits   Var  PORTA
    VoltageInput var byte
    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////
    
    
    VoltageDiff var byte
    
    VoltageREF con 120 ' to get 12v output
    DutyCycle var byte
    DutyCycle = 127
    Frequency con 30000 
    
    
    '////////////////// HPWM /////////////////////////
    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2
    Pause 20
    
    
    '////////////////////////////////////////////////////
    '////////////////// PROGRAM /////////////////////////
    '////////////////////////////////////////////////////
    
    Mainloop:
    
        Gosub VoltageCheck
    
    				lcdout $FE,1, "V_Input: ", dec VoltageInput, ":"
    				lcdout $FE,$C0, " Adcin: ", dec VoltageInput 
    				Pause 150  
    
                   	
    goto Mainloop
    End
    
         
    '////////////////////////////////////////////////////     
    VoltageCheck:
         ADCON0.2 = 1			'Start Conversion
         
         adcin 4,VoltageInput
         
        If voltageInput < voltageREF then        ' voltageREF is 127 for 12v dc
            VoltageDiff = VoltageREF - VoltageInput     '=127+(127-115)=139
            DutyCycle = voltageREF + ( voltageREF - VoltageDiff)
            DutyCycle = DutyCycle/255 *100
            HPWM 1,DutyCycle,Frequency         'channel, dutycycle, frequency
            pause 20
        ENDIF
        
        If voltageInput = voltageREF then
            HPWM 1,DutyCycle,Frequency          'channel, dutycycle, frequency    
            pause 20
        else
            VoltageDiff =  VoltageInput - VoltageREF      '=127-(182-127)
            DutyCycle = voltageREF - ( VoltageDiff - voltageREF )
            DutyCycle = DutyCycle/255 *100
            HPWM 1,DutyCycle,Frequency 'channel, dutycycle, frequency
            pause 20
        endif
    
    Return

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: HPWM with Pic16F886 not working

    Figures out it works if the frequency is fixed, so I changed it to 127 to test trial...
    I guess the frequency number is off..

Similar Threads

  1. Can someone help me get hpwm working on 18f24k22
    By jimseng in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st March 2012, 14:31
  2. pic16f886
    By NURULHAIZA in forum General
    Replies: 5
    Last Post: - 21st May 2010, 09:09
  3. PIC16F886 Register Settings
    By aherrera in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th July 2009, 18:52
  4. Pic16f886
    By Larry in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th October 2008, 23:40
  5. PIC16F886 programming problems
    By mmargolis in forum General
    Replies: 2
    Last Post: - 3rd August 2007, 02:19

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts