Triggering 5 TTL clocks simultaneously


Closed Thread
Results 1 to 40 of 84

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    yes for sure Here: goto here can be skip. just for testing purpose on a single task.

    once you start the PWM it will run as long as you have power on the PIC.. DEUH!!!

    For the HPWM statement... i always set register myself. Never tested this one. By the book it's suppose to work... or i'm missing something like a DEFINE something stuff.
    Steve

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

  2. #2
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Alright, I'll try that tomorrow and let you know how it goes. thanks again.

  3. #3
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, I tried it and I am getting the same problem. CCP1 does not appear to be oscillating at all. Also, do I have to set PORTA.2 to receive an external interrupt?? I thought if I just test and see if it has a 5V source on it, that would suffice, but maybe not. I just plopped your code example in there to see if it would compile, and it did, but does not appear to generate the desired function.

    ' Connect analog input to (RA0)
    ' Connect clocks to PORTB
    ' PORTB.0 is the Reset Clock
    ' PORTB.1 is the Vphase1 clock
    ' PORTB.2 is the Vphase2 clock
    ' PORTB.3 is the Hphase1 clock
    ' PORTB.4 is the Hphase2 clock
    ' The reset will be connected to a HWPM clock pin #17, USE FEEDBACK WIRE!!
    ' Connect pin 2 from the DB9 connector to PORTC.6
    ' Have a +5V source ready to touch PORTA.2 to trigger clocking process

    include "modedefs.bas"

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    DEFINE OSC 20 ' Sets clock speed to 20Mhz
    Define ADC_CLOCK 4 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    ' PIC18F2320 example, may need to change
    TRISC.2=0 ' CCP1 AS OUTPUT
    Tmr2dutyvar VAR WORD
    Tmr2dutyvar=86 ' ((1/3600)/4)/20Mhz / 16(prescaller)
    PR2=$57 ' load frequency period (PWM freq=3.6 KHZ)
    'set Duty cycle
    CCP1CON.5=Tmr2dutyvar.1
    CCP1CON.4=Tmr2dutyvar.0
    CCPR1L =(tmr2dutyvar>>2)

    T2CON=%00000110 ' start timer 2
    ' set prescaler = 16

    CCP1CON = %00001100 ' pwm mode for CCP1

    INTCON2 = %0100000 ' External Interrupt on Rising Edge
    INTCON.7 = 0 ' Disables global interrupts
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001101 ' Set PORTA analog, except for pin 2
    TRISB = %00000001 ' Set PORTB to all output, except for bit 0
    Pause 500 ' Wait .5 second
    Pause 500 ' Wait .5 second

    horizpulse var byte
    vertpulse var byte
    adval var byte ' Create adval to store result

    horizpulse = 1 ' Initialize counters, initial states
    vertpulse = 1
    PORTB.1 = 0
    PORTB.2 = 0
    PORTB.3 = 1
    PORTB.4 = 0

    buttonloop:
    IF PORTA.2 = 1 then
    GOTO vertloop
    else
    GOTO buttonloop ' Waits for 5V that signals shutter is closed
    ENDIF
    vertloop:
    horizpulse = 1
    PORTB.1 = 1
    PAUSEUS 139
    PORTB.1 = 0
    PORTB.2 = 1
    PAUSEUS 139
    PORTB.1 = 1
    PORTB.2 = 0
    PAUSEUS 139
    PORTB.1 = 0
    PAUSEUS 270
    vertpulse = vertpulse + 1
    IF vertpulse < 512 THEN
    GOTO horizloop
    ELSE
    GOTO buttonloop
    ENDIF
    horizloop:
    INTCON.1 = 0 ' Resets interrupt flag to 0
    Resetcheck: ' Loops back to make sure
    ' the PORTB.3 goes low and
    IF INTCON.1 = 0 THEN ' PORTB.4 goes high as close
    GOTO Resetcheck ' to the external trigger's
    ' rising edge as possible
    ENDIF
    PORTB.3 = 0
    PORTB.4 = 1
    PAUSEUS 139
    PORTB.4 = 0
    PORTB.3 = 1
    PAUSEUS 15
    ADCIN 0, adval ' A/D 8 bit value from PORTA.0 into adval
    SEROUT2 PORTC.6,16416,[BIN8 adval,13,10] ' Output 8 bit word serially to PC from C.6
    PAUSEUS 87
    horizpulse = horizpulse + 1
    IF horizpulse < 784 THEN
    GOTO horizloop
    ELSE
    PAUSEUS 270
    GOTO vertloop
    ENDIF
    END

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


    Did you find this post helpful? Yes | No

    Default

    mm, unfortunately i don't have any of those 4520 here to test... weird.
    1. Did you set config fuse to HS oscillator in your programmer?!?
    2. is your MCLR is tie to VCC via 1K-10K resistor ?!?
    3. is your supply line 5volts and clean... have you place 0.1 uF close to the PIC?!?
    4. Is a stupid blink light on this pin work?!?
    Last edited by mister_e; - 2nd March 2005 at 17:04.
    Steve

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

  5. #5
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Yes, I have HS configured in the EPIC programmer.

    My master clear is tied to +5V through a 1k resistor.

    My supply line is 5V.

    And I was doing a lot more than the blinking program on this PIC before I tried doing the HPWM.

  6. #6
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    It wouldn't have anything to do with my DEFINE ADC_CLOCK line, would it?

  7. #7
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    When you're having problems like this, it's sometimes much easier to simplify
    everything & start with a single peice of code that gets a peripheral you're
    having problems with working first.

    Then move on to testing your other routines step-by-step, inserting tested
    & known working code with new code until you hit the problem again. Then
    you at least have some idea of what may be causing the problem.

    Try something like this without any other code to test your CCP module.
    Disconnect all external circuits just in case it's an external circuit connection
    that causing problems.

    Code:
    DEFINE HPWM1_TIMER 2
    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2   ' RC2
    DEFINE HPWM2_TIMER 2
    DEFINE CCP2_REG PORTC
    DEFINE CCP2_BIT 1   ' RC1
    
    TRISC.1 = 0
    TRISC.2 = 0 ' HPWM automatically does this for you, but just in case
    CCP1CON = %00001100  ' PWM mode
    CCP2CON = %00001100  ' PWM mode
    
    HPWM 1,127,3600    ' RC2/CCP1 3.6kHz @ ~50% duty
    HPWM 2,127,3600    ' RC1/CCP2 3.6kHz @ ~50% duty
    Does it work?

    If it does, then you have verified your CCP module & PBP code to control
    it. If it doesn't work then you may have a hardware or config problem.

    Your PBP device header file (18F4520.INC) has "deafult" config fuse settings
    in it something like the following;
    Code:
            INCLUDE "P18F4520.INC"   ; MPASM  Header
            __CONFIG    _CONFIG1H, _OSC_XT_1H
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
            __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    If you think maybe your programmer isn't setting HS when selected manually,
    then edit your inc file changing XT in the first line to HS. Save it, close it,
    and re-compile. Then check to see if it's really set to HS when you open the
    .HEX file with your programmer before programming your 4520.

    Once you get hardware PWM working, then move on to insert other code
    modules one-by-one, and re-test.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 20:52
  2. How do I set GPIO 0-2 and 5 simultaneously?
    By cstack in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th August 2009, 10:32
  3. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 03:30
  4. Replies: 11
    Last Post: - 13th July 2005, 20:26

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