help in pic Basic Pro "Break statement"


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    6

    Default help in pic Basic Pro "Break statement"

    in this code i want to increase duty until Feedback is equal to 3, then to break the loop after feedback is equal to 3, then to take this value of duty which made feedback equal to 3 out of loop and to continue to output this constant duty.
    In Pic basic is it possible to use this break statement as in c language, if yes how? If no help me alternative way to solve this problem, thanx in advance

    Code:
                                    *
    '****************************************************************
    clear
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
      ' Duty cycle value (CCPR1L:CCP1CON<5:4>)
    Feedback  var word
    ADCON1=%00000010
    duty VAR WORD  ' Duty cycle value (CCPR1L:CCP1CON<5:4>)
    
       TRISA = %11111111
       TRISB = %11111111
       TRISC = %11111011       ' Set PORTC.2 (CCP1) to output
       CCP1CON = %00001100  ' Set CCP1 to PWM 
       T2CON = %00000101    ' Turn on Timer2, Prescale=4
       
     
    ' Use formula to determine PR2 value for a 1KHz signal, 
    ' 4MHz clock, and prescale=4. (4E6/(4*4*1E3))-1=249
    
       PR2 = 249      ' Set PR2 to get 1KHz out
            
    ' Use formula to determine CCPR1L:CCP1CON<5:4> value for
    ' ends of range 20% to 80%.  (249+1)*4*0.2=200 (20% value)
    ' (249+1)*4*0.8=800 (80% value)
    
       duty = 0      ' Set duty cycle to 0%
    
    mainloop: 
       adcin 0, feedback            
       CCP1CON.4 = duty.0   ' Store duty to registers as
       CCP1CON.5 = duty.1   ' a 10-bit word
       CCPR1L = DUTY >> 2
       duty = duty + 1     ' Increase duty cycle
    
    ' Since the total sweep of duty is 1000 (1000-0) and 
    ' we are adding 1 for each loop, that results in 60
    ' steps min to max. 1 second divided by 1000 = 1mS            
    
       Pause  1
                ' Pause 1/60 of second
    
       IF (feedback => 3) Then
    '       *****break the loop****
           endif
         
       GoTo mainloop        ' Do it forever
        
           CCP1CON.4 = duty.0   ' Store duty to registers as
           CCP1CON.5 = duty.1   ' a 10-bit word
           CCPR1L = DUTY >> 2
          
        End
    Last edited by boscox; - 23rd May 2012 at 08:17.

  2. #2
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: help in pic Basic Pro "Break statement"

    Use either "REPEAT..UNTIL" or "WHILE..WEND"

    BR,
    -Gusse-

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: help in pic Basic Pro "Break statement"

    how about:

    clear
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    ' Duty cycle value (CCPR1L:CCP1CON<5:4>)
    Feedback var word
    ADCON1=%00000010
    duty VAR WORD ' Duty cycle value (CCPR1L:CCP1CON<5:4>)

    TRISA = %11111111
    TRISB = %11111111
    TRISC = %11111011 ' Set PORTC.2 (CCP1) to output
    CCP1CON = %00001100 ' Set CCP1 to PWM
    T2CON = %00000101 ' Turn on Timer2, Prescale=4


    ' Use formula to determine PR2 value for a 1KHz signal,
    ' 4MHz clock, and prescale=4. (4E6/(4*4*1E3))-1=249

    PR2 = 249 ' Set PR2 to get 1KHz out

    ' Use formula to determine CCPR1L:CCP1CON<5:4> value for
    ' ends of range 20% to 80%. (249+1)*4*0.2=200 (20% value)
    ' (249+1)*4*0.8=800 (80% value)

    duty = 0 ' Set duty cycle to 0%

    gosub Adjust:'adjust pwm duty cycle routine

    mainloop:
    GoTo mainloop ' Do it forever

    Adjust:'adjust pwm duty cycle routine
    feedback = 0 'set to 0 for first pass
    while feedback < 3
    adcin 0, feedback
    CCP1CON.4 = duty.0 ' Store duty to registers as
    CCP1CON.5 = duty.1 ' a 10-bit word
    CCPR1L = DUTY >> 2
    duty = duty + 1 ' Increase duty cycle
    ' Since the total sweep of duty is 1000 (1000-0) and
    ' we are adding 1 for each loop, that results in 60
    ' steps min to max. 1 second divided by 1000 = 1mS
    Pause 1 ' Pause 1/60 of second
    CCP1CON.4 = duty.0 ' Store duty to registers as
    CCP1CON.5 = duty.1 ' a 10-bit word
    CCPR1L = DUTY >> 2
    wend
    return

    End
    Last edited by Dave; - 23rd May 2012 at 20:41.
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    Apr 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: help in pic Basic Pro "Break statement"

    thanx in advance -Gusse and Dave for ur suggestion, am taking some time on what you sugggest then i will come to you when i meet any difficulties

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