PIC 12f683 AD/PWM Problems:


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    6

    Default PIC 12f683 AD/PWM Problems:

    Hi!
    Iīve got a Problem again. This time I read an 10 bit AD Value an want to put it Out as PWM on Port GP2
    Something is wrong with the AD module.
    Here is my Code:

    'READ 10 BIT AD Value and put out as PWM

    @ device pic12f683, fcmen_off, ieso_off, intrc_osc, wdt_off
    @ device pic12f683, pwrt_on, mclr_off, protect_off

    GPIO = %00000000 ' All outputs low
    CMCON0 = 7 ' Comparators off
    TRISIO = %00000001 ' Set GP0 in and Rest Out 0=Output
    ANSEL = %00000001 'Set PORTGPIO.0 analog rest digital
    'WPU=%00110000 ' Pull-ups on for GPIO.4 & 5 inputs
    'OPTION_REG.7=0 ' Enable internal pull-ups

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    Define CCP1_REG GPIO 'PWM Output on gpio
    Define CCP1_BIT 2 'Bit 2

    adval Var Word ' Create adval to store result
    Pause 100

    loop:
    ADCIN 0, adval ' Read channel AN0 to adval

    HPWM 1,adval,500 ' PWM between 0-1024 , 500Hz on GP2

    Pause 100

    Goto loop ' Do it forever

    End
    ---------------------------------------------------------------------

    If I donīt Use the ADCIN, and would say adval = 100 or something else between 0 an 255, I can see the right PWM with the scope coneccted to GP2
    but if adval gets the Value from ADCIN, the PWM Output sometimes is on or off, It looks like that there some definition is missing. I couldnīt imagine which one this could be.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking Answer in the Question...

    hi, Surfer

    The ADC result is between ???
    The PWM valid input range is between ???

    SCALING forgotten ...

    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 " !!!
    *****************************************

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Surfer... go check in the PICBasic documentation and come back and tell me if the HPWM command allows eight bits or ten bits...

  4. #4


    Did you find this post helpful? Yes | No

    Default

    HPWM and PWM is between 0-255 and a 10 bit read for the a/d results in a 0-1023 reading. Divide a/d result by 4 or reduce resolution to 8 bit.

Similar Threads

  1. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  2. IC2 pic 18f452 program problems
    By MrSafe in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th September 2007, 18:55
  3. problems on power up of PIC
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th June 2006, 14:11
  4. Help, problems first time with 18F452 PIC
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2005, 20:49
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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