adcin and HPWM


Closed Thread
Results 1 to 25 of 25

Thread: adcin and HPWM

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Once is enough !

    Hi, Ken

    Just change the dutycycle IF there's a change in ADC result ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Just change the dutycycle IF there's a change in ADC result ...
    Isn't that what I said earlier?

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    oK I will try this when I get home tonight.

    I did some change in my program, mostly in the Pin Configuration section.
    If this do not work, I will remove all the ADC stuff and just try the HPWM


    INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
    @ DEVICE pic16F88, HS_OSC , CCPMX_ON
    DEFINE OSC 20 'use external 20mhz crystal
    PAUSE 100 ' start-up delay

    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////

    DEFINE CCP1_REG PORTB 'Define output port of pulses out
    DEFINE CCP1_BIT 3 'Define output port of pulses out

    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

    CMCON = 7 ' Disable analog comparator
    ANSEL = %00000010 ' set AN1 (RA1) as analog, others to digital
    ADCON1 = %00000000 ' Left justified results in 8 bits
    ADCON0 = %10000001 ' Configure and turn on A/D Module

    TRISB = %00000000 ' Set PORTB to all output
    TRISA = %11111111 ' Set PORTA to all input

    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////

    DutyCycle var byte 'Create adval to store result

    '//////////////////////////
    '// Program starts here //
    '//////////////////////////

    Mainloop:
    ADCON0.2 = 1 'Start Conversion

    ADCIN 1, DutyCycle 'analog pin 1 (RA1) get the 8 bit result
    pause 50

    HPWM 1,DutyCycle,10800
    pause 100

    GOTO Mainloop
    end

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Maybe try this instead:
    Code:
    INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
    @ DEVICE pic16F88, HS_OSC , CCPMX_ON
    DEFINE OSC 20 'use external 20mhz crystal
    PAUSE 100 ' start-up delay
    
    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////
    
    DEFINE CCP1_REG PORTB 'Define output port of pulses out
    DEFINE CCP1_BIT 3 'Define output port of pulses out
    
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 100 ' Set sampling time in uSec
    
    CMCON = 7 ' Disable analog comparator
    ANSEL = %00000010 ' set AN1 (RA1) as analog, others to digital
    ADCON1 = %00000000 ' Left justified results in 8 bits
    ADCON0 = %10000001 ' Configure and turn on A/D Module
    
    TRISB = %00000000 ' Set PORTB to all output
    TRISA = %11111111 ' Set PORTA to all input
    
    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////
    
    DutyCycle var byte 'Create adval to store result
    LastDutyCycle var byte 'hold last time around
    
    '//////////////////////////
    '// Program starts here //
    '//////////////////////////
    
    Mainloop:
    ADCON0.2 = 1 'Start Conversion
    
    ADCIN 1, DutyCycle 'analog pin 1 (RA1) get the 8 bit result
    pause 50
    
    If dutycycle <> lastdutycycle then
         lastdutycycle = dutycycle
         HPWM 1,DutyCycle,10800
    Endif
    
    GOTO Mainloop
    end

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    I'm guessing that whenever this is executed:
    Code:
    HPWM 1,DutyCycle,10800
    PBP is stopping, setting up and restarting the HPWM.

    If you do this in the loop,
    Code:
    CCPR1L = DutyCycle
    then your problem should go away. I don't know if PBP allows you to do this. If not, you will have to set up the hardware manually.
    Code:
    PR2 = 462  '10,800Hz frequency
    CCPR1L = 0  'Initial duty cycle
    CCP1CON = %1100  'PWM mode
    T2CON.2 = 1  'Start TIMER2

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I tried the following program, very simple, still not getting anything out..
    using internal osc, trying to cut down on the hardware...



    'Test HPWM command
    '
    INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
    @ DEVICE pic16F88, CCPMX_ON, INTRC_OSC_NOCLKOUT

    OSCCON = %110 ' Set OSC TO 4MHZ 'select the clock


    'DEFINE OSC 20 'use external 20mhz crystal
    PAUSE 100 ' start-up delay

    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////

    DEFINE CCP1_REG PORTB 'Define output port of pulses out
    DEFINE CCP1_BIT 3 'Define output port of pulses out

    CMCON = 7 ' Disable analog comparator

    TRISB = %00000000 ' Set PORTB to all output
    TRISA = %11111111 ' Set PORTA to all input

    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////

    '//////////////////////////
    '// Program starts here //
    '//////////////////////////
    HPWM 1,126,3000
    PAUSE 200 ' delay

    Mainloop:

    GOTO Mainloop
    end

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I tried the following program, very simple, still not getting anything out..
    using internal osc, trying to cut down on the hardware...
    Which pin on the PIC are you looking at? And how are you looking at it?

  8. #8
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I am looking at B.3 through my scope.
    I am using the same hardware as my digital thermometer now, which was using B.3 to get the temperature and have a LCDout. (and that circuit is working fine, but no a/d or HPWM)
    So I removed that wire on B.3 (of course) , placed the new chip in place and I am not seeing anything to the scope

    k

Similar Threads

  1. ADCIN > HPWM but with min/max limits - i failed maths
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th November 2009, 02:02
  2. 16F684 adcin and hpwm
    By astouffer in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st November 2008, 17:29
  3. Portc.3 latching?
    By Bronurstomp in forum mel PIC BASIC
    Replies: 4
    Last Post: - 10th November 2008, 17:47
  4. PIC16F819 HPWM CCP1 clariffication
    By earltyso in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th March 2008, 18:43
  5. Newbie HPWM / ADC question
    By Johan in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th June 2007, 12:52

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