Need your help for a newbie


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2013
    Posts
    3

    Lightbulb Need your help for a newbie

    Hello all ;


    i dont know english at all but really need help on this so that i asked a friend to translate it to English and ask for your help


    i want to make an ADC and HPWM application with 18f4520 .i've done many tries but never succeed , i think its something about my config file or basic knowledge about it. Thing is; if value on ADC when i pressed the buttn conneted to Portd.0 is between 50 and 300 , i want to get 10 khz hpwm from CCP1 and CCp2 .. İf its less then 50 and more than 300 there wont be any signal.


    Here is my config file amd codes , i know i m a rookie but every little thing is a start , thanks for your time and upcoming help






    CONFIG_START
    _CONFIG1H_OSC_HS_1H
    _CONFIG2L_PWRT_ON_2L : _BOR_OFF_2L : _VREGEN_OFF_2L
    _CONFIG2H_WDT_OFF_2H
    _CONFIG3H_MCLRE_OFF_3H : _LPT1OSC_OFF_3H : _PBADEN_ON_3H: _CCP2MX_PORTC_3H
    _CONFIG4L_STVREN_OFF_4L : _LVP_OFF_4L :_XINST_OFF_4L : _DEBUG_OFF_4L
    _CONFIG5L_CP0_OFF_5L : _CP1_OFF_5L : _CP2_OFF_5L : _CP3_OFF_5L
    _CONFIG5H_CPB_OFF_5H : _CPD_OFF_5H
    _CONFIG6L_WRT0_OFF_6L : _WRT1_OFF_6L : _WRT2_OFF_6L : _WRT3_OFF_6L
    _CONFIG6H_WRTB_OFF_6H : _WRTC_OFF_6H : _WRTD_OFF_6H
    _CONFIG7L_EBTR0_OFF_7L : _EBTR1_OFF_7L : _EBTR2_OFF_7L : _EBTR3_OFF_7L
    _CONFIG7H_EBTRB_OFF_7H

    CONFIG_END

    DEFINE OSC 10


    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 1 ' LCD TANIMLAMALARI
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50






    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2
    DEFINE CCP2_REG PORTC
    DEFINE CCP2_BIT 1
    CCP1CON=%00001100
    CCP2CON=%00001100
    PR2=249
    DUTY=1000


    DEFINE ADC_BITS 10 'ADC 10 BİT
    DEFINE ADC_CLOCK 0
    DEFINE ADC_SAMPLEUS 50 'ÖRNEKLEME ZAMANI 50 MİKROSANİYE
    ADCON0=%00010111
    ADCON1=11
    ADCON2=%10000111
    ADRESH=0
    ADRESL=0
    INTCON2=%10000000
    INTCON=%10100001
    T0CON=%10000001
    T2CON=%00000100
    T3CON=%00100110





    HPWM 1,0,0
    HPWM 2,0,0


    TRISA=%11111111
    TRISB=%00000000
    TRISC=%00000000
    TRISD=%11111111


    DUTY VAR BYTE
    OKUA VAR WORD
    OKUB VAR WORD
    OKUC VAR WORD
    SAY VAR BYTE


    DON:
    ADCIN 0,OKUA
    OKUA=(OKUA*/500)>>2
    OKUA=OKUA*32
    OKUA=OKUA/10




    IF PORTD.0=0 AND OKUA<=50 OR OKUA>=300 THEN
    HPWM 1,0,0
    HPWM2,0,0


    IF PORTD.0=0 AND OKUA>=50 OR OKUA<=300 THEN
    HPWM 1,DUTY,PR2
    HPWM 2,DUTY,PR2
    GOTO DON

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Need your help for a newbie

    It might help to know what PIC and version of PBP you are using.


    I never did PWM but I see a few things:

    1. That is not a correct CONFIG statement (chech PBP manual).
    2. Move TRIS before HPWM statements.
    3. Add ENDIF to IF statements (check PBP manual).
    4. Missing a space in HPWM2,0,0.

    Do not use political hash strings in thread titles.

    Robert
    Last edited by Demon; - 4th June 2013 at 14:07. Reason: added #4 and 5

  3. #3
    Join Date
    Jun 2013
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Need your help for a newbie

    its version 4.0 with PIc 18f4520

    i also corrected 2,3 and 4 but not sure but not able to find something about CONFIG statements on manual and no idea how should CONFIG statements should be

    btw sorry about hastags , i normally do not put things like that but since its not a political issue , it seem to be no problem but rules are rules , i respect to that ...

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Need your help for a newbie

    Can you show me a link to where you got PBP version 4?

    Robert

  5. #5
    Join Date
    Jun 2013
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Need your help for a newbie

    Sorry version 2.6

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Need your help for a newbie


  7. #7
    gilroy's Avatar
    gilroy Guest


    Did you find this post helpful? Yes | No

    Default Re: Need your help for a newbie

    the digital representation of the tones thru a lowpass filter. Look in the manual for an example. I have used this command for generating tones for our 2 meter repeater and it works just fin

Similar Threads

  1. Newbie HELP :(
    By TheOne in forum mel PIC BASIC
    Replies: 3
    Last Post: - 27th March 2009, 17:15
  2. Newbie needs help
    By chien_fu in forum mel PIC BASIC
    Replies: 9
    Last Post: - 30th June 2008, 13:52
  3. Newbie
    By NF9Ω in forum Off Topic
    Replies: 0
    Last Post: - 24th August 2007, 13:16
  4. newbie
    By david gillian in forum mel PIC BASIC
    Replies: 2
    Last Post: - 12th July 2007, 19:02
  5. newbie
    By kctan in forum General
    Replies: 2
    Last Post: - 22nd November 2005, 15:56

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