PDA

View Full Version : Visualize Clockout



JoelMurphy
- 5th December 2008, 01:49
hi-ho,

been bouncing around. i'd like to get the PIC to control a TLC5940 PWM controller for LEDs and whatnot. i have a grip on how the chip works, and how to format the data to its registers, but the 5940 requires a clock signal to time the PWM. [4096 cycles, a little handshake, 4096 more cycles...] i'm thinking 'hey, there's that TMR1 right there. why not, you know...' so i'm just ramping up on getting the CCP and TMR1 to talk to eachother. part of my solution for timing the PWM is to use the INTRC (clockout) configuration. i'm running a 16F88 and have gotten some good results with my test code, and i want to visualize the clockout ont RA6. so, i went ahead and put an LED on it. it gives a little blink when the program starts up, but then nothing. what's going on? am i asking too much of the little OSC2? i even put my multimeter on it, thinking that i would at least see some +V... nuthin.
simple code below. sorry darryl, i'm not using your amazing thing.
as a side note, the software toggle of B.4 goes on and off like you read about. but the mulitplexed B.3 just sits there sorta 'on' even though i'm setting it low in the isr.


16F88, INTRC clockout, disable BOR due to 3V3


OSCCON = %01110110 '8MHz INTERNAL OSCILLATOR
ANSEL = %00000000 'MAKE PortA PINS ALL DIGITAL
TRISB = %00000000

LED VAR PortB.4
LED1 VAR PortB.3

T1CON = %00100001 'ENABLE TIMRE ONE, PRESCALE 1:1, USE INTERNAL CLK
INTCON = %11000000 'ENABLE GLOBAL INT, ENABLE PERIPHERAL INT,
PIE1 = %00000100 'ENABLE CCP1 INT
CCP1CON = %00001000 'COMPARE MODE, SET OUTPUT ON MATCH

CCPR1L = %00000000 'SET CCP REGISTER TO 4069
CCPR1H = %00010000

on interrupt goto ISP


Main:
PAUSE 1
GOTO Main

DISABLE
ISP:
TOGGLE LED
LOW led1
PIR1.2 = 0
TMR1H = 0
TMR1L = 0
RESUME
ENABLE

Bruce
- 5th December 2008, 20:30
Trying to drive an LED with OSC2 out is probably not going to work, as it's not designed to
drive LEDs. It's a low-current clock output. You might get by with applying OSC2 out to the
base of a transistor, but I've never tried it.

And your multi-meter may not be fast enough to keep up with a 2MHz pulse out on OSC2.

An LED turned ON/OFF at 2MHz will most likely appear to be dimly lit all the time. 2MHz is
pretty quick.

Your comment for TIMER1 prescaler is wrong. You actually have the prescaler set to 1:4,
and your comment on the value of CCPR1 is wrong too. It should be 4096 VS 4069.

If you want to see the LEDs blink, you're going to need a lot more time between interrupts.

Try something like this;


@ DEVICE INTRC_OSC_CLKOUT, LVP_OFF, WDT_OFF, MCLR_OFF, BOD_OFF, CCPMX_ON, PWRT_ON

OSCCON = %00010000 ' 125kHz INTERNAL OSCILLATOR
ANSEL = %00000000 ' MAKE PortA PINS ALL DIGITAL
PORTB = 0 ' ALL CLEAR AT POR
TRISB = %00000000

LED VAR PortB.4
LED1 VAR PortB.3

T1CON = %00110001 ' ENABLE TIMER1, PRESCALE 1:8, INTERNAL CLK
PIE1 = %00000100 ' ENABLE CCP1 INT
CCP1CON = %00001011 ' COMPARE MODE, AUTO RESET TIMER1
CCPR1L = %00000000 ' SET CCP REGISTER TO 4096
CCPR1H = %00010000 ' 4096*8*32uS = 1.048 seconds toggle rate
INTCON = %11000000 ' ENABLE GLOBAL INT, ENABLE PERIPHERAL INT.

on interrupt goto ISP

Main:
@ nop
GOTO Main

DISABLE
ISP:
TOGGLE LED
TOGGLE LED1
PIR1.2 = 0
RESUME
ENABLE

JoelMurphy
- 6th December 2008, 13:41
bruce, thanks for the reply,

i may try to put an NPN on OSC2 to see what's up. but i'm more interested in controlling the PWM driver.

i have the PIC connected to the TLC PWM driver, and it's not working. although it looks like there may be a faint glimmer of life on startup. the thing that gets the PWM going is the GSCLK which i'm attempting to drive with my clockout.
the DS for the TLC says that minimum pulse time for GSCLK is 16ns. i'm way in range there...

will try to slow everything down to make sure my timing is matching what the driver needs.
also thinking about using TMR0 interrupt at 1:16 and toggling my output in the ISR.

by the way, the pins on the TLC i'm concerned about are
GSCLK greyscale clock which the chip uses to time the PWM
BLANK which is toggled at the end/beginning of each 4096 clock period

i hope the CCP1 can work, cause it's so cool.
anybody else use this type of LED controller?