RobG 1,892 Posted October 9, 2011 Author Share Posted October 9, 2011 I wanted to see how X-10 signals and switching heavy loads will affect my light controller's zero-crossing detector, so I programmed my LauchPad to count pulses and display result once every second. In normal, interference free conditions, I expect to see steady 120, but due to internal clock's tolerance, I the count is alternating between 122 and 123. In my first test, I am using X-10 transmitter plugged to the same outlet as light controller. Once or twice I can see a hiccup where 123 is longer than expected (this could be clock's tolerance because this hiccup is cyclic,) but nothing major like 124+. In my second test, I am turning on and off 1200W Miele upright, lights in the room blink, but light controller is not affected. Quote Link to post Share on other sites
bluehash 1,581 Posted October 9, 2011 Share Posted October 9, 2011 It's actually looking quite good. Also, moving to Booster Pack sub-forum. Quote Link to post Share on other sites
bluehash 1,581 Posted October 10, 2012 Share Posted October 10, 2012 Added to Store: Quote Link to post Share on other sites
gwdeveloper 275 Posted March 9, 2013 Share Posted March 9, 2013 Hey RobG, I pulled this boosterpack out of my drawer to use as a readout on my tablesaw project. Sorting through the code, I'm a bit confused. It won't display numbers higher than 4096. Send it 4097, and it just rolls over to show 0001. So basically, it shows (My_Number - 4096) instead of the proper value. My knowledge of Assembly is limited but growing. Is there something in the ASM that would prevent numbers higher than 4096? Can you point me in the right direction to fix it up? Quote Link to post Share on other sites
RobG 1,892 Posted March 9, 2013 Author Share Posted March 9, 2013 It's possible that you are using 12 bit version of the binToBCD. You can find more functions here. Quote Link to post Share on other sites
gwdeveloper 275 Posted March 9, 2013 Share Posted March 9, 2013 Perfect. Quote Link to post Share on other sites
RobG 1,892 Posted March 9, 2013 Author Share Posted March 9, 2013 Well, don't thank yet I just realized that all my binTo... functions are 12 bit, they were all created to be used with 10 bit ADC. I will create 16 bit later on, but for now, you can use something like this: void bin16ToUnpackedBCD(unsigned int n, unsigned char * digits) { unsigned char charIndex = 0; while (charIndex < 3) { digits[charIndex] = 0; charIndex++; } while (n > 0) { digits[charIndex] = n % 10; n /= 10; charIndex--; } } gwdeveloper 1 Quote Link to post Share on other sites
gwdeveloper 275 Posted March 9, 2013 Share Posted March 9, 2013 Ha. I'm only just now sitting down to test this so good timing! For what I'm doing, C will work fine as the project is not clock critical ATM. Quote Link to post Share on other sites
gwdeveloper 275 Posted March 10, 2013 Share Posted March 10, 2013 Ok, well finally got to actually test this and the above bin16ToUnpackedBCD function does not work either. It limits the display to < 1000. Send 999 and it shows 0999 as expected. Send 1000 or greater to it and it displays digit 0 and 3 only. so it looks like 1x0x. I'll run through it a bit more and see what I can come up with; I know you're busy. Using the MSP430 Assembly manual, I'm commenting your ASM code so I can better see what it is doing. Quote Link to post Share on other sites
RobG 1,892 Posted March 11, 2013 Author Share Posted March 11, 2013 Ok, will take another look, I tested that function before I posted it so it could be something else. Which code are you using? Quote Link to post Share on other sites
roadrunner84 466 Posted March 11, 2013 Share Posted March 11, 2013 void bin16ToUnpackedBCD(unsigned int n, unsigned char * digits) { unsigned char charIndex = 0; while (charIndex <= 3) { digits[charIndex] = 0; charIndex++; } while (n > 0) { charIndex--; digits[charIndex] = n % 10; n /= 10; } } You don't initialize digits[3] with 0, I changed it so it does. In this case, I'd prefer to use just plain lines, not loops; it's only 4 lines and probably not more code anyway void bin16ToUnpackedBCD(unsigned int n, unsigned char * digits) { digits[3] = n % 10; n /= 10; digits[2] = n % 10; n /= 10; digits[1] = n % 10; n /= 10; digits[0] = n % 10; } Now I'm looking at it, when your uin16 exceeds 9999 you'll try to write to charIndex -1 (that's minus 1), the second loop should be charIndex oriented instead of n oriented. void bin16ToUnpackedBCD(unsigned int n, unsigned char * digits) { int charIndex; for(charIndex = 3; charIndex >= 0; --charIndex) { if (n != 0) // this if-block will save you unneccesary division operations, but adds a litle code to your codespace { // calculate digit digits[charIndex] = n % 10; n /= 10; } else { // n == 0; just put a zero in this digit digits[charIndex] = 0; } } } gwdeveloper 1 Quote Link to post Share on other sites
gwdeveloper 275 Posted March 11, 2013 Share Posted March 11, 2013 (edited) Ok, it's definitely on my end. I created a new project with your original code. Replacing the binaryToUnpackedBCD with bin16ToUnpackedBCD and it works great! Sorry for any trouble. Fail on my part for sure. I'll sort out my code. In my attempt to add a bit of abstraction, I screwed something up somewhere. Thanks for the help! EDIT: @roadrunner84, I'll test your function out after dropping the kiddo off at camp this morning. EDIT: @RobG, do you have any more of these PCBs? The store has been out for some time. Edited March 11, 2013 by gwdeveloper Quote Link to post Share on other sites
RobG 1,892 Posted March 11, 2013 Author Share Posted March 11, 2013 Good catch rr84, I was setting those individually before I changed to loop, missed that one. Re int >9999, before you use bin16ToUnpackedBCD, you should verify that then number is in the range and if it's out of range, display error or something like that. You can also change the function to convert to 6 chars, but then you will not be able to display #5 and #6 on a 4 digit display. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.