Shop OBEX P1 Docs P2 Docs Learn Events
Sx48 timer — Parallax Forums

Sx48 timer

SpillerSpiller Posts: 52
edited 2007-09-10 18:52 in General Discussion
Hi,

I like to build a PLL circuit by usinng CD4046 programmed from SX48. I use the SX TIMER1· in PWM mode to drive the 4046 input. This is okay, but I have problem with the TIMER2 when I put this timer into the loop of the PLL. I used TIMER2 EXTERNAL command to set RC.3 pin into External Event Clock Source mode. I have connected RC.3 pin to the output of the 4046. I used TIMER2 R1 Value and TIMER2 R2 value for programmig the registers. I have connected RC.2 to the 4046 phase comparator input. I expected pulses there but nothing came out. After the SX user manual the timer external mode works like PWM mode the only differences that the dirving clock is not from the prescaler. I don't understand whay not pulses there. confused.gif· Then I put the TIMER2 into CAPTURE mode I got pulses, it was about 30 Hz which was independent from the external clock. How can I get pulses from the RC.2 in external timer mode?

Regads

Spiller

Comments

  • BeanBean Posts: 8,129
    edited 2007-09-10 11:37
    Spiller,
    It would help alot if you could post your code(simplified as much as possible)·and a schematic.

    Did you make RC.2 an output ?
    Also note that the prescaler doesn't work with external clocks.

    What is the frequency of the Timer2 clock ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The first rule to being successful is "Learn from your mistakes",
    The second rule is "Be willing to make mistakes"
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 9/10/2007 2:01:32 PM GMT
  • SpillerSpiller Posts: 52
    edited 2007-09-10 15:47
    Hi Bean,

    Thanks for the quick answer. I made RC.2 an output. I know that the precaler not works in external clock mode.

    I like to vary Timer2 clock frequecy betveen 20Hz and 20kHz At the this test the frequeny was 1KHz. I'm at the very begining of my desing and have no schematic, but when I get home I will post the code.

    Regards

    Silller
  • SpillerSpiller Posts: 52
    edited 2007-09-10 18:52
    Hi Bean,

    Here is my code:

    '
    ' Device Settings
    '

    DEVICE SX52, OSCXT2
    FREQ 4_000_000
    ID "SX_MFG"


    '
    ' IO Pins
    '
    PLL_IN VAR RB.6 ' Clock for PLL input
    SQR_IN VAR RC.3 ' Square wave input from wave form gen.
    MUL_OUT VAR RC.2 ' Multiplyer output for PLL
    '
    ' Constants
    '


    '
    ' Variables
    '


    '
    INTERRUPT
    '

    ISR_Start:
    ' ISR code here

    ISR_Exit:
    RETURNINT ' {cycles}


    ' =========================================================================
    PROGRAM Start
    ' =========================================================================


    '
    ' Subroutine Declarations
    '


    '
    ' Program Code
    '

    Start:
    ' initialization code here
    TIMER1 CLEAR
    TIMER2 CLEAR
    OUTPUT PLL_IN ' Set PLL_IN output
    INPUT SQR_IN ' Set Square wave input
    OUTPUT MUL_OUT ' Set Multiplyer output
    TIMER2 EXTERNAL ' Set TIMER2 into external mode

    Main:
    ' main code here
    TIMER1 PWM,2000,4000 ' Set 1kHz onto PLL_IN output
    ' Set 500Hz onto MUL_OUT
    TIMER2 R2,1 ' Set loop counter value 1
    TIMER2 R1,1 ' Set loop counter value 1

    END

    It is very interesting, I got pulses on the RC.2 if I wait about 1 minutes. I got the 500Hz square wave on this output but it has a very stange slip after some periods. I checked the input singnal onto the RC.3 pin, it has no any slip. Can it be coding problem? Or my HW is bad?

    I will attach the sreen shot of this 500Hz signal in a new topic.

    Regards

    Spiller
Sign In or Register to comment.