Hey guys, will this work?


Closed Thread
Results 1 to 27 of 27

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmgelba View Post
    Ok, I think I understand all except how did you fill in bits 4 and 5? Why a 0 and 1 in the location you put them in?
    assuming a 10 bits results as follow
    Code:
    'Bit number 9876543210
       MyVar = %1111110011
    In red the MSB, in Blue the LSBs for PWM.

    Shift them all two position to the right you have
    Code:
       MyVar = %0011111100
    Now, where are the LSB now... gone... you need to extract them 2 from the original 10bit value, so Bit0 and BIT1, and transfer them to Bit4 and BIT5 of CCP1CON register
    CCP1CON.4=MyVar.0 ' bit0 to bit4 of CCP1CON
    CCP1CON.5=Myvar.1
    Steve

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

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    YES!! I understand at last!! Thank you so much for your time Steve.

    I have been looking at it all wrong. I can see moving the bits now. I thought each bit value, a 0 or a 1, was the 4 and 5 bit part of the number, so when you removed the lsb's, you shifted everything, and what was in 6 and 7 is now in 4 and 5 and is the new state.

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    Well now, of course, this does absolutly nothing!
    Here's the complete code.

    Code:
    OSCCON = $70
    define osc 8
    
    CSET   VAR WORD 'CURRENT SET
    CSEN   VAR WORD 'CURRENT SENCE  
    DUTY   VAR wORD 'PWM DUTY CYCLE
    
    ADCON0 = %00011001
    ADCON1 = %00001111
    ADCON2 = %10111111
    TRISA = %00000000
    TRISB = %00110011
    Define  ADC_BITS        10     	' Set number of bits in result
    Define  ADC_CLOCK       3     	' Set clock source (5=fosc/16)
    Define  ADC_SAMPLEUS    10    	' Set sampling time in uS
    
    CSET = 0
    CSEN = 0
    
    duty = 20                           ' duty value for 50% duty cycle
    PR2 = 9                             '
    T2CON = %00000100                   ' timer2 on, prescale 1:1
    CCPR1L = duty>>2                    ' MSB of duty cycle value
    CCP1CON.4=Duty.0                    ' set PWM mode and store the 
    CCP1CON.5=Duty.1                    ' 2 LSB of duty
    
    LOOP:
    ADCIN 6, CSET 'READ VALUE OF CURRENT SET POT
    ADCIN 4, CSEN   'READ VALUE OF CURRENT SENCE
    IF CSEN > CSET Then LET DUTY = DUTY - 1
    IF CSEN < CSET THEN LET DUTY = DUTY + 1
    CCPR1L = duty>>2                    ' MSB of duty cycle value
    CCP1CON.4=Duty.0                    ' set PWM mode and store the 
    CCP1CON.5=Duty.1                    ' 2 LSB of duty
    GOTO LOOP

Similar Threads

  1. PortA Doesn't Work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 11
    Last Post: - 8th September 2015, 18:41
  2. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  3. Can't get POT work on P12f675 - Newbie
    By berslan in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th March 2008, 21:22
  4. How to set ICD-2 clone to work with PBP?
    By G-R-C in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th October 2006, 02:50
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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