Voltage output from PIC16f628A


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    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.

  2. #2
    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

  3. #3
    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 06: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, 20: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, 16:06
  3. make a low voltage output from a PIC pin
    By emptyset in forum General
    Replies: 1
    Last Post: - 8th February 2008, 20:20
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 04:46
  5. Help with final project
    By OvERKiLL in forum General
    Replies: 4
    Last Post: - 15th December 2006, 21: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