I have a code that generates a PWM. Can someone tell me how to add code to the existing to generate a PWM and give it a delay to certain amount and get that out through one of the ports?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I have a code that generates a PWM. Can someone tell me how to add code to the existing to generate a PWM and give it a delay to certain amount and get that out through one of the ports?
A delay to what? Yashaswy, please describe in detail the waveform(s) you expect from your program! The hardware PWM only might not do the job for that since it's felixibility is limited. You will have to work with the interrupts of the timer.
It sounds like you want to do something like in this thread:
Maybe you review this question. If you want to do something similar, then you can build your code around the given example there.
Dennis
Yashaswy,
sorry, but we will not find a solution for you if you do not clearly specify what you are expecting.
Yashaswy Akella said:I want the EXACT output
What does that mean? I asked multiple times now to get an idea of what you want. I know that you want two (PWM) pulses with a delay, but that is all so far. I posted a link to a similar example program, but you did not say anything regarding my suggestion, so still no one knows your plans. If you want help with your program you will have to povide some more information and you will have to invest some of your own energy and time. Maybe you have a short look at this article:
Especially 3) and 4)
Dennis
Yashaswy Akella said:... we will be using Timer A 0 and Timer A 1 for I/O ports P1.2, P1.3 respectively...
P1.2 cannot be used as PWM output for TA0. Only P1.6/P2.3, P1.0, or P1.1 can be used.
P1.3 is okay for PWM output of TA1. So is P1.2
Yashaswy Akella said:... I've flashed this code...
You couldn't have flashed any code. You have framed the code ;)
Yashaswy Akella said:... but only the output from P1.2 is coming...
That is because the code is incorrect for your purpose. You started the entire thread talking about the code. It turns out to be the wrong code.
Yashaswy Akella said:#pragma vector = TIMER0_A1_VECTOR // Compare interrupt for 25% elapsed duty cycle
__interrupt void TIMER0_A1_ISR( void )
{
TA1CTL = TASSEL_2 | ID_0 | MC_1 | TACLR; // 2nd PWM: SMCLK, divider 1, up-mode, clear
TA0CCTL2 = 0x00; // Clear compare interrupt - executed only once
}
Your interrupt will not be executed because you did not enable the global interrupts.
Yashaswy Akella said:So how to get the output out of the switch?
Output of the switch?
The pin the switch is connected to should be configured as an input. Of course you can use it as an output, but then you should not press the switch because...
Yashaswy Akella said:I mean which port to connect as there is nothing behind the switch
..."behind the switch" is GND - you would short the pin.
Yashaswy Akella wrote the following post at Sun, Nov 8 2015 10:25 PM:
Yashaswy Akella said:// Configure Timer0_A
TA0CCR0 = 16000-1;
TA0CCR0 = 20;
TA0CCR1 = 12000-1;
TA0CCTL1 = OUTMOD_7;
TA0CCTL2 = CCIE;
TA0CTL = TASSEL_2 | ID_0 | MC_1 | TACLR;
I changed only this part in the entire code as per your suggestion but there is not output from P1.6
Sun, Nov 8 2015 10:33 PM, old_cow_yellow:
P1.0 is accessible at the right-hand end of R6 next to LED2.
Sun, Nov 8 2015 10:46 PM Yashaswy Akella:
The P1.0 is not a port right. It's a switch in my controller.
Sun, Nov 8 2015 11:27 PM Dennis Eichmann:
No, P1.1 is the switch. As OCY said: "...right-hand end of R6 next to LED2" - P1.0 is connected to the LED.
Sun, Nov 8 2015 11:34 PM Yashaswy Akella:
So how to get the output out of the switch?
I mean which port to connect as there
P1.0 is not a switch
Honestly I still don't know what you are planning to do - maybe it is just me, but I don't get it. I read the complete thread again and still cannot figure out what your program shall do in the end.
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1DIR = BIT6 BIT0;
P1SEL0 = BIT6 BIT0;
P1DIR = BIT2;
P1SEL0= BIT2;
PM5CTL0 &= ~LOCKLPM5;
CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 = DCOFSEL_6; // Set DCO = 8MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;// Set ACLK=VLO SMCLK=DCO
CSCTL3 = DIVA__8 | DIVS__8 | DIVM__8; // Set all dividers
CSCTL0_H = 0; // Lock CS registers
// Configure Timer0_A
TA0CCR0 = 16000-1;
TA0CCR1 = 20;
TA0CCR2 = 12000-1;
TA0CCTL1 = OUTMOD_7;
TA0CCTL2 = CCIE;
TA0CTL = TASSEL_2 | ID_0 | MC_1 | TACLR;
TA1CCR0 = 16000-1;
TA1CCR1 = 20;
TA1CCTL1 = OUTMOD_7;
TA1CTL = TASSEL__SMCLK | MC__UP | TACLR;
__bis_SR_register(GIE); // Enter LPM0
__no_operation(); // For debugger
while (1);
}
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR( void )
{
TA1CTL = TASSEL_2 | ID_0 | MC_1 | TACLR;
TA0CCTL2 = 0x00;
}
Dennis,
The code I need will create Two pulses with Time period 16ms each with one being ahead of another by 12ms(which is delay) in an MSP430FR5969 controller.
Regards,
Yashaswy
The source code had some mistakes that I did not see. They are corrected as follows:
#include <msp430.h> int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Cofigure GPIO P1DIR = BIT2 | BIT0; P1SEL0 = BIT2 | BIT0; PM5CTL0 &= ~LOCKLPM5; CSCTL0_H = CSKEY >> 8; // Unlock CS registers CSCTL1 = DCOFSEL_6; // Set DCO = 8MHz CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;// Set ACLK=VLO SMCLK=DCO CSCTL3 = DIVA__8 | DIVS__8 | DIVM__8; // Set all dividers CSCTL0_H = 0; // Lock CS registers // Configure Timer0_A TA0CCR0 = 16000-1; TA0CCR1 = 20; TA0CCR2 = 12000-1; TA0CCTL1 = OUTMOD_7; TA0CCTL2 = CCIE; TA0CTL = TASSEL_2 | ID_0 | MC_1 | TACLR; TA1CCR0 = 16000-1; TA1CCR1 = 20; TA1CCTL1 = OUTMOD_7; __bis_SR_register(GIE); // Enter LPM0 __no_operation(); // For debugger while (1); } #pragma vector = TIMER0_A1_VECTOR __interrupt void TIMER0_A1_ISR( void ) { TA1CTL = TASSEL_2 | ID_0 | MC_1 | TACLR; TA0CCTL2 = 0x00; }
**Attention** This is a public forum