Posted by Justin on September 29, 2010 – 11:56 pm
A different take on how to create a PWM signal. I decided to go the interrupt route using the WDT+ peripheral. I did this by setting it to the interval timer and putting all my counters and logic within the interrupt. The funny thing is i have read that you shouldn’t put too much code into your interrupt, or something bad will happen.
the resistors on the left, are 100 ohm resistors and the one on the right is a 470 ohm resistor to limit current for the RGB LED. connections on the uC that are used are pins 1.3, 1.4, 1.5 i have not decided which pins are what color, i will decide that on my final build.
The test code will be improved this is just the compile and see if it works.- The best part , the code works lol .
so let me know what you think on creating PWM with the interval timer instead of timer A.
#include <msp430x20x2.h>
#include <signal.h> //add for interrupt
#define UP 0x00
#define DOWN 0x01
volatile int millsecs = 0;
volatile int counter2 = 0;
volatile int led_red = 0;
volatile int led_green = 199;
volatile int led_blue = 199;
volatile int dir = UP;
void main(void)
{
WDTCTL = WDT_MDLY_0_064;
P1DIR |= BIT5 + BIT4 + BIT3;
P1OUT |= BIT5 + BIT4 + BIT3;
IE1 |= WDTIE;
eint();
}//end main
interrupt(WDT_VECTOR) watchdog_timer(void)
{
++millsecs;
if (millsecs == 200) { millsecs= 0; P1OUT |= BIT0 + BIT6; ++counter2; }
if (millsecs == led_red ) { P1OUT ^= BIT3; }
if (millsecs == led_green) { P1OUT ^= BIT4; }
if (millsecs == led_blue ) { P1OUT ^= BIT5; }
if (counter2 == 25 ) { counter2 =0;
switch (dir){
case UP: ++led_red; --led_green; --led_blue;
if (led_red == 199) {dir = DOWN;}
break;
case DOWN: --led_red; ++led_green; ++led_blue;
if (led_red == 0) {dir = UP;}
break;
}//end switch
}//end if
}//end interrupt
To change the Period length – change the 200 value to the period you want, you can also change it by setting the WDT interval to different intervals to change the period.
to change the Duty cycle, change the led_[color] variable to anything between 0 and period length
I am still working on trying to get it to cycle through all colors, and fade better when led_[color] is close to 0
by far this project is not done, the board will be soldered up and pics will be presented. The end result should be code for WDT PWM, which could be used for servos, LEDs, or possibly communication, and i will have my flower pot back!
Posted by Justin on September 21, 2010 – 2:59 am
I keep on buying parts that i may or may not need, but definitely want to have.
so what am i going to do with a 300baud modem or piezoelectric discs, I have no idea but i cant wait to get them
also my Zilog order came in and thats why i also ordered a PLCC-68 socket and its a through hole!!
—————————————————————————
ITEM# DESCRIPTION QTY TOTAL
—————————————————————————
G16133 Amazing Wire Glue 1.00 $3.95
—————————————————————————
G16873A PLCC-68 Socket (Through Hole) / Brand: 1.00 $0.97
—————————————————————————
GP28 IC Socket Assortment 1.00 $2.49
—————————————————————————
G9303 3 Lead Piezo Disk (Pkg of 2) 2.00 $2.00
—————————————————————————
G17892 SALE! LCD Display Assortment 1.00 $0.99
—————————————————————————
A10224 MC14543BCP BCD-to-7 Segment Latch/Decod2.00 $1.38
—————————————————————————
A20538 PBL3717A Bipolar Stepper Motor Driver (4.00 $4.36
—————————————————————————
G14197 SALE! Mini Stepper Motor w/ Driver Sche4.00 $3.56
—————————————————————————
A10025 DM7493AN Decade and Binary Counter (Nat2.00 $0.70
—————————————————————————
A10137 74VHC943N 300 Baud Modem w/5V Supply (N2.00 $3.90
—————————————————————————
A20010 74F164PC Serial-In Parallel-Out Shift R2.00 $1.10
—————————————————————————
SUB TOTAL : $25.40
TAX : $0.00
SHIPPING : $4.95
ORDER TOTAL : $30.35
Posted by Justin on September 16, 2010 – 6:18 am
Z16C3516VSG IC 16MHZ Z8500 CMOS ISCC 68-PLCC 1
Z86E0812SEG1903 IC Z8 2K OTP 12MHZ RC OSC 18SOIC 1
Z8F0423SB005EG IC ENCORE MCU FLASH 4K 8SOIC 2
Z8F0830SJ020EG IC ENCORE XP MCU FLASH 8K 28SOIC 2
cant wait to figure out how to program ….well i can wait
Posted by Justin on September 15, 2010 – 5:15 am
another failed attempt at code, but it is sending me in the right direction
. hopefully the new direction will work, otherwise its going to get posted on my what doesnt work Post
http://justinstech.org/2010/09/msp430-what-doesnt-work/#more-534
Posted by Justin on September 6, 2010 – 12:19 am
This will be an on going post that will be constantly updated on what doesn’t work when coding for the msp430…….yes this will feature my failings lol.
so for the first Failure……
Project: RGB led fade to different colors with a ~4 hour timer
This fail is a test program that i had created to test the software PWM using WDT+ and interrupts.
CCFLAGS = -mendup-at=main
-mendup-at=”function”—when main ends, it usually goes to stop program execution, but you can make it jump back to main when main exits. pretty much sets it up as a never ending loop. great if main is supposed to never exit or return.
Code:
#include<msp430x20x2.h>
#include<signal.h> //interrupt SR
volatile unsigned int timer1 = 0;
void main(void) {
WDTCTL = WDT_MDLY_32;
P1DIR |= BIT0+BIT6;
IE1 |= WDTIE;
if (timer1==126) {
timer1 = 0;
P1OUT ^= BIT6;
}//end if
_BIS_SR(LPM0+GIE);
}//end main
interrupt(WDT_VECTOR) watch_dog_timer(void)
{
++timer1;
P1DIR ^= BIT0;
} //end interrupt
what it was supposed to do is cycle through the program, when the WDT causes an interrupt the timer is supposed to increment
then once the timer reaches 126 it resets and toggles P1.6(green LED on launchpad)
what it did is loop through, never servicing an interrupt, and looped with out doing anything……well almost nothing, timer1 never incremented but the main loop did compare timer1 to 126.
for some reason the interrupt never gets serviced because it goes back to main and clears the WDT timer count, so then it runs it runs so quick that the interrupt that’s sitting there clears when it goes back to main…..
Cause: my theory says my code maybe too short for it to call the interrupt fully.
When i step through it the interrupt flags never get called, and before you know it the whole thing starts over again.
Fix: none as of yet still testing
Read More »