Jump to content

pillum

Members
  • Content Count

    37
  • Joined

  • Last visited

Everything posted by pillum

  1. pillum

    Measuring time in clocks between edges

    Thanks, your code did work somehow oPossum.
  2. Hello, I want to measure the time between the both edges of clock signal. The Purpose of the project is to build a shift light with the MSP430 and the TLC5940 LED driver. The RPM signal to the tachometer comes in a 12V HIGH/LOW signal and the higher the RPM is the higher the frequency of the signal is. Instead of using a frequency counter I measure the time the signal is on HIGH. Capturing the signal with the Open Logic Sniffer gave me a straight and continuous signal. 2 MSP430s are used. One to generate the signal and the other to measure it. MSP430 #1 P1.0 -> MSP430 #2 P2.1 This is the code for generating the clock: void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; P1DIR = BIT0; P1OUT = 0x00; TACTL = TASSEL_2 | MC_1 | ID_0; CCR0 = 8000; CCTL0 = CCIE; _enable_interrupts(); _bis_SR_register(LPM0 | GIE); } #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A (void) { P1OUT ^= BIT0; // Toggle P1.0 } This is the code for measuring it: void main() { /* Clock Setup */ WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Set Clock Frequency to 16Mhz BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; P2SEL = BIT1; P1DIR = 0x00; TA1CTL = TASSEL_2 + MC_2; TA1CCTL1 = CM_3 | SCS | CCIS_0 | CAP | CCIE; _enable_interrupts(); for(; ; } #pragma vector=TIMER1_A1_VECTOR __interrupt void TimerA1(void) { timer = TA1CCR1; TA1CTL |= TACLR; TA1CCTL1 &= ~(COV | CCIFG); } (I even tried to set the check to positive edge and in the ISR set the check to negative edge so its only measuring the HIGH signal time.) Sometimes I get values around CCR0 (8048, 8079, ..) but mostly its trash (0, 33152, 5000, 6915, ...). Whats wrong? Thank you
  3. pillum

    Measuring time in clocks between edges

    yes the clock source should be fast enough, 16Mhz SMCLK TA1CTL = TASSEL_2 + MC_2; TA1CCTL1 = CM_3 | SCS | CCIS_0 | CAP | CCIE;
  4. pillum

    Measuring time in clocks between edges

    weird, with your version I get 48 for every pulse of different length. Also I cannot use Timer1_A0 only Timer1_A1. It never gets to the ISR of it.
  5. pillum

    Measuring time in clocks between edges

    @JWoodrell Is there an advantage of your version to the HW Timer version? @oPossum I get the same value for different frequencies.
  6. pillum

    Measuring time in clocks between edges

    reading TAIV didnt change anything but rising the value to 64 now
  7. pillum

    Measuring time in clocks between edges

    This gives me 16 variables with exactly the value 59, is that right? looks weird to me (edit: after a 2nd run its 54) Also how do I handle overflows if i'm not going to reset the register everytime?
  8. pillum

    Measuring time in clocks between edges

    That would block the cpu for other uses like updating the led driver, wouldn't it?
  9. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    edit: seems like my 1.3 Pin is broken now. simple main.c with only activating it, gives GND on it
  10. Hello, I recently bought a Launchpad with an included MSP430G2553 and I tried to control some LEDs with it via the TLC5940. I've connected it and programmed like in the official Texas Instruments Documents but somehow it doesn't work. The used resistor for IREF has a value of 1.92KOhm to restrict the out current to around 20mA. Here is my code: #include #include #include /* * P1.0 - GSCLK (ACLK) * P1.2 - SIN (UART) * P1.4 - SCLK (UART) * P1.5 - BLANK * * P2.3 - VPRG * P2.4 - DCPRG * P2.5 - XLAT */ /* Defines */ /* Port 1 */ #define GSCLK_POUT P1OUT #define GSCLK_PDIR P1DIR #define GSCLK_PIN BIT0 #define SOUT_POUT P1OUT #define SOUT_PDIR P1DIR #define SOUT_PIN BIT1 #define SIN_POUT P1OUT #define SIN_PDIR P1DIR #define SIN_PIN BIT2 #define SCLK_POUT P1OUT #define SCLK_PDIR P1DIR #define SCLK_PIN BIT4 #define BLANK_POUT P1OUT #define BLANK_PDIR P1DIR #define BLANK_PIN BIT5 /* Port 2 */ #define VPRG_POUT P2OUT #define VPRG_PDIR P2DIR #define VPRG_PIN BIT3 #define DCPRG_POUT P2OUT #define DCPRG_PDIR P2DIR #define DCPRG_PIN BIT4 #define XLAT_POUT P2OUT #define XLAT_PDIR P2DIR #define XLAT_PIN BIT5 #define TLC5940_N 1 /* Macros */ #define SETINPUT(DPIN) (DPIN ## _PDIR &= ~ DPIN ## _PIN) #define SETOUTPUT(DPIN) (DPIN ## _PDIR |= DPIN ## _PIN) #define SETLOW(DPIN) (DPIN ## _POUT &= ~ DPIN ## _PIN) #define SETHIGH(DPIN) (DPIN ## _POUT |= DPIN ## _PIN) #define PULSE(DPIN) \ do { \ SETHIGH(DPIN); \ SETLOW(DPIN); \ } while(0); #define OUTPUTSTATE(DPIN) (DPIN ## _POUT & DPIN ## _PIN) /* Global Data */ uint8_t dcdata[96 * TLC5940_N] = { // MSB LSB 1, 1, 1, 1, 1, 1, // Channel 15 1, 1, 1, 1, 1, 1, // Channel 14 1, 1, 1, 1, 1, 1, // Channel 13 1, 1, 1, 1, 1, 1, // Channel 12 1, 1, 1, 1, 1, 1, // Channel 11 1, 1, 1, 1, 1, 1, // Channel 10 1, 1, 1, 1, 1, 1, // Channel 9 1, 1, 1, 1, 1, 1, // Channel 8 1, 1, 1, 1, 1, 1, // Channel 7 1, 1, 1, 1, 1, 1, // Channel 6 1, 1, 1, 1, 1, 1, // Channel 5 1, 1, 1, 1, 1, 1, // Channel 4 1, 1, 1, 1, 1, 1, // Channel 3 1, 1, 1, 1, 1, 1, // Channel 2 1, 1, 1, 1, 1, 1, // Channel 1 1, 1, 1, 1, 1, 1, // Channel 0 }; uint8_t gsdata[192 * TLC5940_N] = { // MSB LSB 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 15 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 14 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 13 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 12 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 11 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 10 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 9 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 8 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 7 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 6 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 5 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 4 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 3 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 2 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // Channel 0 }; bool firstcycleflag; /* Functions */ void TLC5940_InitPins() { SETOUTPUT(GSCLK); SETOUTPUT(SCLK); SETOUTPUT(DCPRG); SETOUTPUT(VPRG); SETOUTPUT(XLAT); SETOUTPUT(BLANK); SETOUTPUT(SIN); SETINPUT(SOUT); SETLOW(GSCLK); SETLOW(SCLK); SETLOW(DCPRG); SETHIGH(VPRG); SETLOW(XLAT); SETHIGH(BLANK); } void TLC5940_SendDC() { SETHIGH(DCPRG); SETHIGH(VPRG); uint8_t counter = 0; for(; { if(counter > (TLC5940_N*96-1)) { PULSE(XLAT); break; } else { if(dcdata[counter]) SETHIGH(SIN); else SETLOW(SIN); PULSE(SCLK); counter++; } } firstcycleflag = true; } void TLC5940_SendGS() { if(OUTPUTSTATE(VPRG)) { SETLOW(VPRG); firstcycleflag = true; } uint16_t gsclk_counter = 0; uint8_t data_counter = 0; SETLOW(BLANK); for(; { if(gsclk_counter > 4095) { SETHIGH(BLANK); PULSE(XLAT); if(firstcycleflag) PULSE(SCLK); firstcycleflag = false; break; } else { if(!(data_counter > TLC5940_N*192-1)) { if(gsdata[data_counter]) SETHIGH(SIN); else SETLOW(SIN); PULSE(SCLK); data_counter++; } PULSE(GSCLK); gsclk_counter++; } } } void main() { /* Clock Setup */ WDTCTL = WDTPW + WDTHOLD; // Stop WDT TLC5940_InitPins(); TLC5940_SendDC(); TLC5940_SendGS(); __bis_SR_register(GIE); for(; { TLC5940_SendGS(); } } My KiCAD rendered schematics are attached. I hope somebody can help me..I even bought some extra devices (like logic analyzer) to check what could be the source of the problem but didn't find anything so far. Thank you
  11. pillum

    TLC5940 examples

    Is there a reason you are latching in new gs data before you update it in the ISR ? Wouldn't otherwise be more reasonable and faster in terms of latency?
  12. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Hmmm, can I use GND as Low? VPRG can be either GND or VCC but DCPRG can be either L or H..is there any difference? Because I really dont know whats not working again, all the signals and connections are checked and are all right
  13. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    The first cycle flag. According to the Programing Flowchart you need to pulse SCLK the first time you updated GS data.
  14. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Cr*p...happens again. This time everythings soldered so no flaky breadboard connection. Do I need to update DC register before updating GS register? Also, do I need the first cycle flag when not updating it? VPRG and DCPRG are grounded and not controlled by MSP this time since I'm using the DC data from EEPROM. Sniffer tells me, that there is a (clocked) current flowing through OUTn (strangely also on TLCs not connected to the MSP). But the LEDs are pretty dark to off using the same old resistor with value of 1.91kOhm
  15. pillum

    Volt/Amp/Watt meter

    How accurate is it at the fastest mode and how fast is the fastest mode of that chip?
  16. pillum

    TLC5940 board

    I would be interested in a version with three TLC5940 for RGB LEDs if there will be one anytime.
  17. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Ah ok, I get it now. I was just confused by the fact that you're counting 8 leds with ledcounter and sending 3 bytes each. Thanks for explaining
  18. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Now you're confusing me more. I thought this is serial and not random access. I update the grayscale data serially, that means one after another. But you're specify WHICH led to update. Where you got that from? You got any documentation on that? Also you're transmitting 3 bytes per LED (counting last '\0'), I only do 12bits.
  19. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    I should use SCLK pin for GSCLK? I'm not sure I understand what you want to do.. but XLAT isn't? Is pulsing BLANK really so resource intensive that you need an timer interrupt for it? In the flowchart they pulse GSCLK only after data transfer is complete, does this really not need to be synchronized or was this just arbitrary that they made it like this?
  20. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Doesn't the clock signal need to be synchronized then? Because now I'm resetting the PWM counter after 4095 rounds of gsdata upload and not after 4095 cycles. Isn't the MSP430G2553 also able to use the USCI HW to control the TLC5940 via SPI? Also, how do I change the Grayscale data with an USB connection to my PC? Is there already a lib for serial connection like with arduino?
  21. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    That sounds like a very good idea! Thank you :!:
  22. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Lol, well...I removed everything and connected everything from scratch the dunno maybe like 10th time and now it works.. This time I used Launchpad's Vcc for the LEDs, though. Trying with external power source now. Thanks all for your help, especially kylej1050, cde and RobG ! :clap: edit: Tried external power source, works too! Since I changed all wires and reconnected them from scratch, i think there was some fault in the wiring. edit2: strange, it works sometimes and sometimes not.... :eh: . now its not working anymore it blinks sometimes and sometimes its off and then on for a long time edit3: i think the led is broken..used a different led, its not blinking
  23. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    Well, its like that MSP and TLC are on the breadboard. TEST, RST, GND and Vcc of the MSP are connected to the LP. TLC's Vcc and GND are also taken from LP. Breadboards Vcc aka Vled is only for the leds. No, I'm not. Is it worth a try? Is there anything I need to do instead then like resistors on any point?
  24. pillum

    Controlling TLC5940 with MSP430G2553 doesn't work

    It's just an initial test programmed like described in the programming flowchart by TI if you mean decoupling capacitors, then yes as you can see in the schematics. It looks like its a hardware / wiring fault then :/ Have you guys tried it with the MSP430 directly on the Breadboard (not on the launchpad) ?
×