Voltage output from PIC16f628A


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    hi Ben,

    Since our PICs are serial processors, at least for now, and must execute the instructions serially, that is to say one line or instruction at a time, you will never get Serin and Serout commands working at the same time.

    If you use hardware USART, then it will be working in the background, so that you can receive something at the same time you send it.


    -----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As i said before... look for # modifier... it convert your ASCII string to a DECIMAL value.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    bennamanna's Avatar
    bennamanna Guest


    Did you find this post helpful? Yes | No

    Smile

    Hi sayzer,

    Thanks for your reply. I did not think that my code was trying to use ser in and out at the same time? Could you indicate where I am doing this? Thanks mate.

    mister_e,

    Thanks once again. I'm sorry if I'm making you repeat your self. As stated before I am a beginner. I had however already played with # in my code. I tested it with and without. With out # all i get is jargon.

    Thanks,

    Ben

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    T2CON = %00010101 ' Turn on Timer2, Prescale=4
    '
    '
    '
    duty = 100 ' Set duty cycle to 20%
    1. your prescaler is not set to 1:16 as said in the calc. Now, it's set to 1:4. Have a look in datasheet section 8.0 register 8-1 T2CON. you'll discover you need to use T2CON=%00000110

    2. duty=100 set a duty cycle of 16%... still as per the calc. 20% Duty=125

    Code:
    SerIn SI,T9600,,duty
    i think it's invalid.

    you should try
    Code:
    SerIn SI,T9600,#duty
    In Microcode Studio serial communicator, you have access to the settings. Right to 'send' button there's a little arrow.. click on it, go to line terminator, then check 'No terminator'
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    bennamanna's Avatar
    bennamanna Guest


    Did you find this post helpful? Yes | No

    Smile

    Gday,

    I changed the items you found to be in correct. It still will not output what I send via RS232. It comes up with other numbers. I will repost the code I have ended up with below.

    INCLUDE "modedefs.bas" ' Include serial modes
    SI VAR PORTB.1 ' Serial Input pin
    B0 VAR BYTE
    Define OSC 10

    Define LCD_DREG PORTA ' RA0..3
    Define LCD_DBIT 0
    Define LCD_RSREG PORTA ' RA6
    Define LCD_RSBIT 6
    Define LCD_EREG PORTA ' RA4
    Define LCD_EBIT 4
    Define LCD_BITS 4
    TRISA = 0
    TRISB = 0
    CMCON = 7

    Pause 1000 ' Wait for LCD to startup

    duty VAR word ' Duty cycle value (CCPR3L:CCP3CON<5:4>)

    TRISB.3 = 0 ' Set PORTB.5 (CCP3) to output
    CCP1CON = %00001100 ' Set CCP3 to PWM
    T2CON = %00000110 ' Turn on Timer2, Prescale=6

    PR2 = 155 ' Set PR2 to get 1KHz out
    duty = 125 ' Set duty cycle to 20%

    loop:
    SerIn SI,T9600,,# duty

    if duty > 625 then
    LCDOut $FE,1 ' Clear LCD screen
    LCDOut "Duty to great" ' Display line 1
    goto loop
    endif

    CCP1CON.4 = duty.0 ' Store duty to registers as
    CCP1CON.5 = duty.1 ' a 10-bit word
    CCPR1L = duty >> 2

    'duty = duty + 5 ' Increase duty cycle
    LCDOut $FE,1 ' Clear LCD screen
    LCDOut # duty ' Display line 1

    GoTo loop ' Do it forever



    Any other ideas?

    Thanks,

    Ben

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Try this one. I don't use LCD but echo the results to the PC.
    Code:
    @     __CONFIG  _HS_OSC & _MCLRE_ON  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_ON  
    DEFINE OSC 10
    
    CMCON = 7
    PORTA = 0
    PORTB = 0
    TRISA = 0
    TRISB = %00000010
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 64  ' 9600 Baud @ 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    Duty    VAR WORD      ' Duty cycle value (CCPR1L:CCP1CON<5:4>)
    
    CCP1CON = %00001100   ' PWM mode
    T2CON = %00000110     ' Turn on Timer2, Prescale=1:16
    
    PR2 = 155             ' Set PR2 to get 1KHz out
    duty = 125            ' Set duty cycle to 20%
    GOSUB ChangeDuty
    
    Loop:
        HSerIn [DEC Duty]
        IF Duty > 625 THEN
           HSEROUT ["Duty too high... MAX = 625",13,10]
           ELSE
               GOSUB ChangeDuty
               HSEROUT ["Duty=",DEC Duty,13,10]
           ENDIF
        GOTO Loop
        
    ChangeDuty:
        CCP1CON.4 = Duty.0 ' Store duty to registers as
        CCP1CON.5 = Duty.1 ' a 10-bit word
        CCPR1L = Duty >> 2
        RETURN
    and read the FAQ about the fuse config... i think it's your main problem.

    So far, it's working here.
    Last edited by mister_e; - 13th November 2006 at 05:27.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 19:10
  2. What's the voltage on output pin when it's HIGH?
    By TonyA in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 23rd April 2008, 15:06
  3. make a low voltage output from a PIC pin
    By emptyset in forum General
    Replies: 1
    Last Post: - 8th February 2008, 19:20
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  5. Help with final project
    By OvERKiLL in forum General
    Replies: 4
    Last Post: - 15th December 2006, 20:35

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