16F1828 HPWM and ADC


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: 16F1828 HPWM and ADC

    Thank you very much for your help ,Richard !
    I made the changes, but now CCPR1L = 0

    Code:
    Define  OSC 4
    OSCCON = %01101010   'sets the internal oscillator to 4Mhz
    
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 100 
    
    ADCON0 = %00000000    
    ADCON1 = %00000011     
    FVRCON = %10000010     'voltage reference set  to 2.048V 
    CM1CON0 = 0   ' COMPARATORS OFF
    CM1CON1 = 0
    CM2CON0 = 0   ' COMPARATORS OFF
    CM2CON1 = 0    
    CPSCON0 = 0   'CAPACTIVE SENSE MODULE OFF
    RCSTA.7 = 0   'SERIAL PORT OFF
    'APFCON0 = %10000000
    'APFCON1 = %00001010
    'APFCON1.3 = 1 
    TRISA =  %00000011
    TRISB =  %00000000 
    TRISC =  %00000100 ' PORTC.2 input    
    ANSELA = %00000011
    ANSELB = %00000000
    ANSELC = %00000100 ' ANALOG INPUT AN6
    
    OPTION_REG.7 = 1 ' disable WPU
    WPUA =  %00000000
    WPUB =  %00000000
    WPUC =  %00000000
    porta = 0
    portb = 0
    portc = 0 
    
    inh1    var  portc.4
    inh2    var  portc.0
    
    adval  var byte
    duty1  var byte
    duty2  var byte
    
    duty1 = 0 
              
    t2con=4
    PR2 = 255
    ccp1con=16
    
    pause 200
    '========================PROGRAM=============================
    main:
    adcin 6 , adval 
    pause 10
    
    CCPR1L = adval            ;set pwm
    duty1 = adval
    
    hpwm 2 , duty1, 2000 
    
    high inh1
    high inh2
    
    goto main
    end
    '=============================================================

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,655


    Did you find this post helpful? Yes | No

    Default Re: 16F1828 HPWM and ADC

    ccp1con=16 is incorrect, that is just nothing

    ccp1con=12 ; pwm mode

    I made the changes, but now CCPR1L = 0
    ?

    CCPR1L = adval ;set pwm

    if adval= 0 then yes it would
    Last edited by richard; - 17th November 2015 at 10:13. Reason: wrong info

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,655


    Did you find this post helpful? Yes | No

    Default Re: 16F1828 HPWM and ADC

    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 100

    ADCON0 = %00000000
    ADCON1 = %00000011
    ADCON1 = %00000011 ; this line just destroyed all your defines

    ADCON1 = ADCON1 | %00000011 ; will set bits 0 and 1 without wrecking the others
    Last edited by richard; - 17th November 2015 at 09:52. Reason: wrong line

Similar Threads

  1. ADC values above 4095 for 12 bit ADC
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st February 2015, 22:24
  2. ADC problem on 18F46K22 device using all 28 ADC pins
    By JimAvanti in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd February 2012, 20:22
  3. Replies: 3
    Last Post: - 23rd October 2011, 12:53
  4. Newbie HPWM / ADC question
    By Johan in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th June 2007, 12:52
  5. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05

Members who have read this thread : 0

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