
Jake
-
Content Count
133 -
Joined
-
Last visited
-
Days Won
4
Reputation Activity
-
Jake got a reaction from abecedarian in New C2000 LaunchPad
I already have two of them here with bldc motor booster packs. Just no time!!
-
Jake got a reaction from spirilis in New C2000 LaunchPad
I already have two of them here with bldc motor booster packs. Just no time!!
-
Jake reacted to tripwire in PWM duty cycle change with digital input ?
There are a couple of independent elements in your project, so I'd suggest tackling each in isolation before putting it all together.
One part is the button handling: detecting the difference between a "quick push" and holding the button down. To keep things simple you could toggle one LED each time there's a quick press, and flash another LED while the button is held down. I expect you'll want to make sure that the "quick push" LED isn't toggled by the start of a long hold, or the other way round. That'll probably involve polling the button's state every so often, toggling the LED when the button is pressed and then released quickly. If the button isn't released quickly that's a long press, and you could flash the other LED on and off for as long as it's held down.
The other part is varying the PWM duty cycle. You can work on this without needing the input code: just pretend the button is always pressed, and make the duty cycle go up and down continuously. For this part you'll have to figure out the timing of how quickly the duty cycle changes, and keep track of whether the ramp is on the way up or down.
Once both are working you can bring them together. The main thing to watch out for there is the two parts interfering with each other. When the button is held down the varying duty cycle code needs to happen inbetween the button checks. If the button check shows that the button is still held the duty cycle variation needs to keep going from where it left off before the check.
-
Jake reacted to RobG in PWM duty cycle change with digital input ?
Setup one timer to output PWM signal.
Setup second timer to start counting when switch interrupt is detected (you could also use WDT, but it's less flexible than Timer.)
When timer interrupts, check the state of the button.
If not pressed anymore, it means short press, toggle PWM output on/off (only when hold flag is false,) stop the timer, set the hold flag.
If still pressed, increase CCRx, start counting again, set the hold flag to true.
Second timer could also be used for de-bouncing, you could adjust CCR1 after first Timer interrupt.
Disable switch's interrupt when pressed, enable when Timer detects switch release.
-
Jake reacted to RobG in PWM duty cycle change with digital input ?
I just noticed your post re 3414 PCBs. I have few if you want, I just didn't have time to test them (they are based on another board I made, so they should be fine.)
-
Jake reacted to RobG in PWM duty cycle change with digital input ?
BTW, here's the code for what you are trying to do.
1 PWM channel, 1 switch, press & release to toggle on/off, press & hold to dim up & down.
To test it, remove one of the LED's shorting blocks and connect it to P2.2.
#include "msp430g2553.h" /* * main.c */ typedef unsigned char u_char; #define LED_PIN BIT2 // P2.2 TA1.1 #define SWITCH_PIN BIT3 // P1.3 LaunchPsd's S2 switch #define TOGGLE_DELAY 37500 // time after we test for press & release 250ms @ 1MHz & /8 #define FIRST_DELAY 37500 // time after we start dimming (after press & release test) 250ms #define STEP_DELAY 1500 // dimmer step interval 10ms u_char hold = 0; // when 1, it means we are holding the button u_char direction = 1; // dimmer direction, 1 is up int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // 1MHz clock DCOCTL = CALDCO_1MHZ; // setup PWM output P2DIR |= LED_PIN; P2SEL |= LED_PIN; P2OUT &= ~LED_PIN; // input pin P1OUT |= SWITCH_PIN; // pull up P1REN |= SWITCH_PIN; // enable resistors P1IES |= SWITCH_PIN; // trigger hi -> low P1IFG &= ~SWITCH_PIN; // clear flags P1IE |= SWITCH_PIN; // enable interrupts // timer TA0, used to monitor the switch TA0CCR0 = 0; // full cycle TA0CTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode // timer TA1, PWM timer TA1CCR0 = 255; // full cycle TA1CCTL1 = OUTMOD_7; // CCR1 set/reset TA1CCR1 = 0; // CCR1 default 0 TA1CTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode _bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupt while (1) ; } // Timer A0 interrupt service routine #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A0(void) { if (hold) { if (P1IN & SWITCH_PIN) { // switch is up, end of press & hold TA0CCTL0 &= ~CCIE; // disable timer TA0CCR0 = 0; P1IFG = 0; // enable switch interrupt P1IE |= SWITCH_PIN; } else { // still holding TA0CCR0 = STEP_DELAY; if (P2DIR & LED_PIN) { // PWNM output is on, we can update PWM if (direction) { // change PWM according to direction TA1CCR1++; if (TA1CCR1 == TA1CCR0) { // all the way up, change direction direction = 0; } } else { TA1CCR1--; if (TA1CCR1 == 0) { // all the way down, change direction direction = 1; } } } } } else { if (P1IN & SWITCH_PIN) { // switch is up, press & hold, toggle output P2DIR ^= LED_PIN; // toggle output on/off TA0CCTL0 &= ~CCIE; // stop timer TA0CCR0 = 0; P1IFG = 0; // enable switch interrupt P1IE |= SWITCH_PIN; } else { TA0CCR0 = FIRST_DELAY; // looks like press & hold hold = 1; } } } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IE = 0; // disable switch interrupt TA0CCR0 = TOGGLE_DELAY; // set time & enable timer TA0CCTL0 = CCIE; hold = 0; } -
Jake reacted to tripwire in Where is a good place to start for C tutorials? And challenges with button push led program
You need to pass __delay_cycles a number of cycles to wait for, eg "__delay_cycles(40)" will busy wait for 40 cycles. That would give a 40 microsecond delay if MCLK frequency is set to 1MHz. MSP430G2553 will default to approx 1.1MHz on startup, which is good enough for rough timing. If you need more accuracy you can use the DCO calibration constants to set it to 1MHz.
-
Jake got a reaction from LariSan in Analog Discovery
My analog discovery showed up today, it's pretty neat hopefully I'll get to stretch it's legs soon!
-
Jake reacted to cps13 in Unwanted activation of output
Changed a couple of bits on my program. But as dubnet says setting P1.0 to low I think did the trick Thanks!!
#include <msp430.h> /* * main.c */ volatile long int i; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1SEL = 0x00; // setting all P1 pins to GPIO P1DIR |= 0x01; // Set P1.0 to output direction P1IN =0x00; // Set P1.0 to LOW P1OUT =0x00; // Set P1.4 to LOW for (; // infinite loop { if ((0x10 & P1IN)) // check if P1.4 is high { P1OUT |= 0x01; // set P1.0 high i=1100000; do(i--); while (i !=0); P1OUT &= ~0x01; // set P1.0 to low } } } -
Jake reacted to abecedarian in Where is a good place to start for C tutorials? And challenges with button push led program
Another thing- you have one too many left curly braces following the "for" statement.
-
Jake reacted to tripwire in Where is a good place to start for C tutorials? And challenges with button push led program
I'm afraid you've fallen into one of the traps set by the designers of C there. They got the precedence of the bitwise operators wrong, so that line will be evaluated as:
if (P1IN & (BTN==0)) Instead of what you'd expect it to do:
if ((P1IN & BTN)==0) You need to include the parentheses around P1IN & BTN to get the correct result.
That doesn't explain why CCS can't find the out file, though. Take a look in the C:\Users\Jake\Google Drive\CCS\Turn lights on\Debug\ folder to see if it's there or not. If it is there maybe CCS is having trouble with spaces in the file path.
If there's no out file that suggests CCS hit some errors during the build and failed to write it. Try right clicking on your project in the "Project Explorer" view and select "Clean Project". Then build it again and see if there are any errors in the "Console" view. If you can't see what's wrong copy all the console output into a text file and attach it here.
-
Jake reacted to weirdnerd10 in Basic Control Register Control for LED Blink Issue
Hello everyone,
I am new to MSP430G2553 and a beginner at programming. But I am trying to do something simple to start off which is to do the blink example, but without using digitalWrite and instead using P1DIR/P1OUT/etc.
Goal: Take the MSP430G2 Launchpad Development Board and blink P1.6 only.
Issue: I noticed that the following code doesn't work and that I need to initialize P1.7 along with P1.6 for it to work:
void setup() { // initialize pin 1.6 as output P1DIR = 01000000; } // the loop routine runs over and over again to blink the LED: void loop() { P1OUT = 01000000; delay(1000); // wait for a second P1OUT = 00000000; delay(1000); // wait for a second } -----------------------The code below works fine (initializing P1.7 as well)------------------------------------ void setup() { P1DIR = 11000000; } // the loop routine runs over and over again to blink the LED: void loop() { P1OUT = 11000000; delay(1000); // wait for a second P1OUT = 00000000; delay(1000); // wait for a second }
-
Jake reacted to roadrunner84 in Where is a good place to start for C tutorials? And challenges with button push led program
Yeah, to set a pin to input with the pullup enabled you should clear its DIR bit, set its REN bit and set its OUT bit:
#define BTN BIT3 P1DIR &= ~BTN; // set pin to input P1REN |= BTN; // set pin to enable internal resistor P1OUT |= BTN; // set internal resistor to pull-up -
Jake got a reaction from spirilis in Look what showed up today!! C2000 F28069M
IMG_20150128_173925519_HDR by JF TX, on Flickr
Its here !! now once I get past my trailer LED project I will be getting to this!
End goal is a mechanical cow for training horses.... similar to this http://www.cowtrac.com/index.html
Hopefully I will be able to get full remote control via android phone or make a remote that has a 300+ ft reliable control range.
It will either have control, or run loaded programs. I have my BLDC motor already and the motor driver boosterpack, and the bluetooth module.
-
Jake got a reaction from KatiePier in Steve Gibson promotes the TI Launchpad
I came from the Arduino side and coming here is like starting over again. But I do like that this is C programming so learning C helps me with everything. (I'm an industrial powerplant electrician.) And I'm working on my electrical engineering degree. I prefer the systems I can modify to suite my needs instead of relying on others for it, or having to accept the way the system works.
-
Jake got a reaction from cubeberg in Steve Gibson promotes the TI Launchpad
I came from the Arduino side and coming here is like starting over again. But I do like that this is C programming so learning C helps me with everything. (I'm an industrial powerplant electrician.) And I'm working on my electrical engineering degree. I prefer the systems I can modify to suite my needs instead of relying on others for it, or having to accept the way the system works.
-
Jake got a reaction from spirilis in Steve Gibson promotes the TI Launchpad
I came from the Arduino side and coming here is like starting over again. But I do like that this is C programming so learning C helps me with everything. (I'm an industrial powerplant electrician.) And I'm working on my electrical engineering degree. I prefer the systems I can modify to suite my needs instead of relying on others for it, or having to accept the way the system works.
-
Jake reacted to tripwire in Where is a good place to start for C tutorials? And challenges with button push led program
This line in your working energia code does three things:
It sets the pin to input mode, but also enables an internal resistor that pulls the pin up to VCC. In the plain C version you only have the pin set to input (which is the default), but the pullup resistor is not enabled. If you're using the P1.3 button on the MSP430G2 launchpad, for example, you'll need to set P1REN bit 3 to enable the internal resistor, and also set P1OUT bit 3 to make the internal resistor a pullup (rather than pulldown). With that done, P1IN bit 3 will be 1 when the button is not pressed, and 0 when the button is pressed. Your last C example also had a bug in the "if" condition. if(P1IN = 0b00001000) assigns the value 0b00001000 to P1IN, then checks if its value is nonzero. I think you probably wanted to use the equality operator instead, like this: if(P1IN == 0b00001000). I'd expect CCS to produce a warning about that, since using the assignment operator instead of the equality operator is a common C programming bug. Finally, you need to be careful how you test P1IN; if(P1IN == 0b00001000) doesn't just require bit 3 to be 1, it also requires all the other bits to be zero (which they might not be). It's best to just check the bit(s) you're interested in: if((P1IN & 0b00001000) == 0b00001000) is only true if bit 3 of P1IN is set, no matter what the other bits are set to. -
Jake got a reaction from RobG in Analog Discovery
My analog discovery showed up today, it's pretty neat hopefully I'll get to stretch it's legs soon!
-
Jake reacted to RobG in LaunchPad, DC Motor, PWM
Here's my little demo of how to use SN754410 with LaunchPad.
Timer's CCR1 is used to control duty cycle via P1.2
P1.0 and P1.1 to control direction (setting both to the same level, 0 or 1, will cause dynamic breaking.)
Vcc1 of SN754410 is connected to LP's Vcc, Vcc2 is connected to a separate power supply (6V in my case.)
Between outputs and Vcc/Vss I put some Schottky's just in case.
EDIT: SN754410 logic side (Vcc1) requires 5V, it may not work correctly when powered from LP's Vcc.
Next week I will add more examples with bigger motor and some MOSFETs.
#include // DEMO counter unsigned int demoCounter = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1OUT |= BIT1; // Direction control - left P1OUT &= ~BIT0; // Direction control - right // Both 0 or 1 - dynamic break P1DIR |= BIT0 + BIT1 + BIT2; // Bit 2 is connected to enable and will be used for PWM P1SEL |= BIT2; // P1.2 TA1 option select CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 1000; // ~8ms CCTL1 = OUTMOD_3; // CCR1 set/reset CCR1 = 950; // CCR1 duty cycle, slow in the beginning TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { // DEMO movement demoCounter++; if(demoCounter == 800) CCR1 = 900; if(demoCounter == 1600) CCR1 = 500; if(demoCounter == 2000) CCR1 = 250; if(demoCounter == 2400) CCR1 = 0; if(demoCounter == 2800) CCR1 = 900; if(demoCounter == 3200) { P1OUT |= BIT0; // switch direction P1OUT &= ~BIT1; } if(demoCounter == 3600) CCR1 = 0; if(demoCounter == 4000) CCR1 = 900; if(demoCounter == 4400) { P1OUT |= BIT1; // switch direction P1OUT &= ~BIT0; } if(demoCounter == 4800) { P1OUT |= BIT0; // switch direction P1OUT &= ~BIT1; } if(demoCounter == 5200) { CCR1 = 500; P1OUT |= BIT1; // switch direction P1OUT &= ~BIT0; demoCounter = 0; } // END DEMO movement }