EPWM control


Closed Thread
Results 1 to 12 of 12

Thread: EPWM control

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Off hand I do not see anything wrong with the logic, so check hardware.

    Can you add to your code a quick debug out put---serot to hyperterm the values of Speed and AnalogLow/High or the ADC value of that pin?

    The ADC with out the pot could float to mid range.

    Along with the debug, check the voltages at the ADC pins(sure you have done this,basic trouble shooting).

    Hard code Duty a a give value to check the output(if you have a spare pin --- add some where in the main loop--- if pin? then Duty = ?.

    I know this is not much help but a the moment it is all I can suggest
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jun 2007
    Location
    Merango, IL
    Posts
    13


    Did you find this post helpful? Yes | No

    Thumbs up

    It's ok mackrackit any help is better than none. Here's where I'm at as of now. I have encorperated the rest of the code back into the main now. I've left out the section where I figure out the seeking value and hard coded it. I've also given position a hard coded value as with nothing attached to the pin I will get garbage on the pin. I still have a pot tied to AN5 which does change the DC as I move it up and down. If you look below there are 6 lines in the "timeTomove" sub, if I uncomment the first four only I get no output. If I uncomment out the bottom two I get a couple of pulses on the output (Maybe 2 of 3) but after that the signal drops out. Any ideas? I will continue to work on this, and thank you for the help so far.


    Code:
    '-------------------------------------------------------------------------'
    '	PIC Defines Specific to PIC Basic Pro                                  '
    '-------------------------------------------------------------------------'
       ' 1. Use internal system clock
       @ DEVICE PIC16F684, INTRC_OSC_NOCLKOUT 
       ' 2. Turn watchdog timer on
       @ DEVICE PIC16F684, WDT_OFF
       ' 3. Power on time on
       @ DEVICE PIC16F684, PWRT_ON
       ' 4. Turning off the master clear input
       @ DEVICE PIC16F684, MCLR_OFF
       ' 5. Brown out detect on
       @ DEVICE PIC16F684, BOD_ON
       ' 6. Data EE Read protect is off
       @ DEVICE PIC16F684, CPD_OFF
       ' 7. Code protect is off
       @ DEVICE PIC16F684, PROTECT_OFF
    
    '-------------------------------------------------------------------------'
    '	Hardware Defines Specific to PIC Basic Pro                             '
    '-------------------------------------------------------------------------'
    	define ADC_BITS 10          'Set A/D coverter to use 10 bits
       define ADC_SAMPLEUS 50      'Set A/D sample time as 50us
       DEFINE OSC 8                'Change clock speed to 8Mhz
       
    '-------------------------------------------------------------------------'
    '	Define Program Variables                                               '
    '-------------------------------------------------------------------------'
       R VAR BYTE
       ScaledX VAR BYTE
       ScaledY VAR BYTE
       ShortX VAR BYTE
       ShortY VAR BYTE
       Slope VAR WORD
       
       AnalogLow VAR WORD          'Digital value for an analog low signal
       AnalogHigh VAR WORD         'Digital value for an analog high signal
       CurrentSpeed VAR WORD
       DUTY VAR WORD
       ExtLimit VAR WORD           'Stored value of the extend limit setting
       JoyX VAR WORD
       JoyY VAR WORD
       RetLimit VAR WORD           'Stored value of the retract limit setting
       Position VAR WORD           'Analog value of the internal potentiometer
       Seeking VAR WORD
       Speed VAR WORD
    
    '-------------------------------------------------------------------------'
    '	Define I/O and EEPROM Definitions                                      '
    '-------------------------------------------------------------------------'
       
       data @0,word 768            'Set default extend limit
       data @2,word 256            'Set default retract limit    
    
       AnalogHigh = 768            'Set analog high signal level 
       AnalogLow = 256             'Set analog low signal level
    
    '   READ 1, RetLimit.Highbyte
    '   READ 0, RetLimit.Lowbyte
    '   READ 3, ExtLimit.Highbyte
    '   READ 2, ExtLimit.Lowbyte
    
    '-------------------------------------------------------------------------'
    '	Initialise PIC Hardware                                                '
    '-------------------------------------------------------------------------'
       CMCON0 = 7                  'Turn comparators off
    	ADCON0.7 = 1                'Set A/D Values to be right justified
       ADCON0.0 = 1                'Turn on A/D Converter
       ANSEL = %00110111           'Turn on select analog registers
    	TRISA = %00001111           'Turn on select register inputs
    	TRISC = %00111111           'Turn on select register inputs
        
       PR2 = 249
       CCP1CON = %11001100  
       CCPR1L = 0 
       PIR1.1 = 0
       T2CON.0 = 0
       T2CON.1 = 0
       T2CON.2 = 1
       WHILE (PIR1.1 = 0)
       WEND;
       TRISC = %00000011 
    '-------------------------------------------------------------------------'
    '   Start of Main Program                                                 '
    '-------------------------------------------------------------------------'
    Main:   
       ADCIN 1, JoyX
       JoyX.LowByte = ADRESL
       JoyX.HighByte = ADRESH
      
       ADCIN 0, JoyY
       JoyY.LowByte = ADRESL
       JoyY.HighByte = ADRESH 
    
       ShortX = JoyX / 4
       ShortY = JoyY / 4
       Seeking = 400
       GOTO TimeToMove
    
    TimeToMove:
       ADCIN 2, Position
       Position.LowByte = ADRESL
       Position.HighByte = ADRESH
    
    Position = 300
    
       If (Position < Seeking + 10) OR (Position > Seeking - 10) THEN
    '      DUTY = 0
    '      CCP1CON.4 = DUTY.0
    '      CCP1CON.5 = DUTY.1 
    '      CCPR1L = DUTY >> 2      
       ELSE 
          IF (Position > Seeking + 10) THEN
    '         CCP1CON.7 = 1
             GOSUB GETSpeed
          ENDIF
          IF (Position < Seeking - 10) THEN
    '         CCP1CON.7 = 0
             GOSUB GetSpeed
          ENDIF
       ENDIF
    GOTO Main
    
    GetSpeed:
       ADCIN 5, Speed
       Speed.lowbyte = ADRESL  
       Speed.highbyte = ADRESH    
       IF (Speed > AnalogLow) & (Speed < AnalogHigh) THEN
          DUTY = 617
          CCP1CON.4 = DUTY.0
          CCP1CON.5 = DUTY.1 
          CCPR1L = DUTY >> 2
       ENDIF
       IF (Speed < AnalogLow) THEN
          DUTY = 400
          CCP1CON.4 = DUTY.0
          CCP1CON.5 = DUTY.1 
          CCPR1L = DUTY >> 2
       ENDIF
       IF (Speed > AnalogHigh) THEN
          DUTY = 850
          CCP1CON.4 = DUTY.0
          CCP1CON.5 = DUTY.1 
          CCPR1L = DUTY >> 2
       ENDIF
    RETURN
    
    END

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    After DUTY gets a value in the main part of the program you have DUTY=0 in timeTOmove.

    The code you have working writes to the high and low byte for Speed the goes straight to CCP1CON.4 and CCP1CON.5 with the low and high byte of speed.

    In the one that is not working DUTY has 0 written to it before CCP1CON.4 and CCP1CON.5.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Jun 2007
    Location
    Merango, IL
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    The part of the code I last posted that has 0 being put into DUTY is there to stop the motor from running. The position is between the two required points so I want to stop motion. The other two if statments is is the motor is not in the correct position then it needs to move. To do that you change the CCP1CON.7 pin to either a 1 or 0 for full H-bridge mode, and use the standard duty cycle. It's just a way so I do not have to shut down the PWM and leave it running forever.

    I will be working on this all day today, and try to give an update as I progress. If you have anything at all please let me know, I'm starting to run out of ideas. Thanks again.

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


    Did you find this post helpful? Yes | No

    Default

    mmm, something spring to mind now form your first post, you said it was suppose to produce 8KHz but, in real-world, it produce 4KHz.

    DEFINE OSC 8 don't change the internal OSC speed, it's more a compiler directive to match PAUSE, PAUSEus and all other timed stuff with the real OSC speed.

    POR value for the internal osc is 4 MHZ, to change it to 8 MHZ you want to use

    Code:
    OSCCON = %01110000    ' this set the internal osc to 8MHz
    for now i can't check the whole thing here, but let us know if the above fix something. At very least, you should have the right PWM frequency.

    HTH
    Steve

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

  6. #6
    Join Date
    Jun 2007
    Location
    Merango, IL
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Thank you Mister_e, that did help out. The running frequency is now 8KHz. I ran a small bit of code below.

    Code:
    '-------------------------------------------------------------------------'
    '	PIC Defines Specific to PIC Basic Pro                                  '
    '-------------------------------------------------------------------------'
       ' 1. Use internal system clock
       @ DEVICE PIC16F684, INTRC_OSC_NOCLKOUT 
       ' 2. Turn watchdog timer on
       @ DEVICE PIC16F684, WDT_OFF
       ' 3. Power on time on
       @ DEVICE PIC16F684, PWRT_ON
       ' 4. Turning off the master clear input
       @ DEVICE PIC16F684, MCLR_OFF
       ' 5. Brown out detect on
       @ DEVICE PIC16F684, BOD_ON
       ' 6. Data EE Read protect is off
       @ DEVICE PIC16F684, CPD_OFF
       ' 7. Code protect is off
       @ DEVICE PIC16F684, PROTECT_OFF
    
    '-------------------------------------------------------------------------'
    '	Hardware Defines Specific to PIC Basic Pro                             '
    '-------------------------------------------------------------------------'
    	define ADC_BITS 10          'Set A/D coverter to use 10 bits
       define ADC_SAMPLEUS 50      'Set A/D sample time as 50us
       DEFINE OSC 8                'Change clock speed to 8Mhz
       OSCCON = %01110000          'Change internal osc to 8MHz
    '-------------------------------------------------------------------------'
    '	Define Program Variables                                               '
    '-------------------------------------------------------------------------'
       R VAR BYTE
       ScaledX VAR BYTE
       ScaledY VAR BYTE
       ShortX VAR BYTE
       ShortY VAR BYTE
       Slope VAR WORD
       
       AnalogLow VAR WORD          'Digital value for an analog low signal
       AnalogHigh VAR WORD         'Digital value for an analog high signal
       CurrentSpeed VAR WORD
       DUTY VAR WORD
       ExtLimit VAR WORD           'Stored value of the extend limit setting
       JoyX VAR WORD
       JoyY VAR WORD
       RetLimit VAR WORD           'Stored value of the retract limit setting
       Position VAR WORD           'Analog value of the internal potentiometer
       Seeking VAR WORD
       Speed VAR WORD
    
    '-------------------------------------------------------------------------'
    '	Define I/O and EEPROM Definitions                                      '
    '-------------------------------------------------------------------------'
       data @0,word 768            'Set default extend limit
       data @2,word 256            'Set default retract limit    
    
       AnalogHigh = 768            'Set analog high signal level 
       AnalogLow = 256             'Set analog low signal level
       ExtLimit = 750
       Retlimit = 50
    '-------------------------------------------------------------------------'
    '	Initialise PIC Hardware                                                '
    '-------------------------------------------------------------------------'
       CMCON0 = 7                  'Turn comparators off
    	ADCON0.7 = 1                'Set A/D Values to be right justified
       ADCON0.0 = 1                'Turn on A/D Converter
       ANSEL = %00110111           'Turn on select analog registers
    	TRISA = %00001111           'Turn on select register inputs
    	TRISC = %00111111           'Turn on select register inputs
        
       PR2 = 249
       CCP1CON = %11001100  
       CCPR1L = 0 
       PIR1.1 = 0
       T2CON.0 = 0
       T2CON.1 = 0
       T2CON.2 = 1
       WHILE (PIR1.1 = 0)
       WEND;
       TRISC = %00000011 
    '-------------------------------------------------------------------------'
    '   Start of Main Program                                                 '
    '-------------------------------------------------------------------------'
    Main:   
    
    WHILE(1)
       CCP1CON.7 = 1
       DUTY = 300
       CCP1CON.4 = DUTY.0
       CCP1CON.5 = DUTY.1 
       CCPR1L = DUTY >> 2
       PAUSE 1000
       DUTY = 0
       CCP1CON.4 = DUTY.0
       CCP1CON.5 = DUTY.1 
       CCPR1L = DUTY >> 2
       PAUSE 200
       
       CCP1CON.7 = 0
       DUTY = 300
       CCP1CON.4 = DUTY.0
       CCP1CON.5 = DUTY.1 
       CCPR1L = DUTY >> 2
       PAUSE 1000
       DUTY = 0
       CCP1CON.4 = DUTY.0
       CCP1CON.5 = DUTY.1 
       CCPR1L = DUTY >> 2
       PAUSE 200   
    WEND
    
    END
    This ran a few times on the motor back and forth, and then ruined one of the driver chips on the board shorting my pcb out. This is an update of where I am at the moment. I starting trouble shooting on it now, so hopefully if anyone finds a solution so will I. One of the things that might be hurting me is a electro cap on the 5V rail (I know duh) or a very high uF cap on the +12V rail for the 2 H-bridges running DC brush motors. (Again, I can't believe I forgot these) I'm also attaching the schematic as this might help some see something in the hardware. I really appreciate all of the help so far guys. Thank you

    Anthony
    Attached Images Attached Images   

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


    Did you find this post helpful? Yes | No

    Default

    Seems you forgot the back EMF diode in your H-Bridge driver.

    470 Ohm seems a bit bit high for a gate resistor... if even really needed...

    How many amp you need to drive?

    Did you also tried with a resistive load?

    I'll look the whole thing later, sure i missed something else.

    Fortunately, someone else may beat me to the punch
    Steve

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

Similar Threads

  1. How do I give a radio control car autonomous control
    By Kenjones1935 in forum General
    Replies: 190
    Last Post: - 17th January 2010, 15:40
  2. pt2258+16f877 how can i use for 5.1 volume control ?
    By whyliving in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th January 2008, 17:51
  3. No one-way approach to learning ir remote control frequencies
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd June 2007, 13:26
  4. Allow better control of text in GUI
    By Archangel in forum PBP Wish List
    Replies: 1
    Last Post: - 19th February 2007, 13:25
  5. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 08:18

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