PDA

View Full Version : Need your help for a newbie



kkamil
- 4th June 2013, 11:33
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

Demon
- 4th June 2013, 13:57
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

kkamil
- 4th June 2013, 14:24
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 ...

Demon
- 4th June 2013, 14:40
Can you show me a link to where you got PBP version 4?

Robert

kkamil
- 4th June 2013, 15:01
Sorry version 2.6

Demon
- 4th June 2013, 17:04
Ok, then read this:
http://www.picbasic.co.uk/forum/content.php?r=467-PICs-CONFIGS-and-Oscillator-Settings-for-Beginners

Robert

gilroy
- 8th July 2013, 10:54
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