jsolarski 94 Posted July 22, 2011 Share Posted July 22, 2011 Im trying to figure out why this simple test code will not work #include /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT //basic clock settings DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; BCSCTL2 |= DIVS_3; //divide smclk/8 125000Hz //GPIO setup P2DIR |= BIT7; P1DIR |= BIT6; //sd16 settings SD16CTL = SD16REFON + SD16SSEL_1; // 1.2V ref, SMCLK SD16CTL |= SD16XDIV_3; // clk/48 2604hz SD16INCTL0 = SD16INCH_1; // A1+/- P1.2 SD16CCTL0 = SD16IE; // 256OSR, bipolar offset, interrupt enable SD16AE = SD16AE2; // P1.1 A1+, A1- = VSS SD16CCTL0 |= SD16SC; // Set bit to start conversion _BIS_SR(GIE); } /*****************************************************************************/ // SD16 ISR #define THRSHMAX 0xac77 //chosen randomly #define THRSHMIN 0x1bbc //very random indeed __attribute__((interrupt(SD16_VECTOR))) void Sd16_Isr(void){ // 0000 - FFFF -- 8000 = halfway point or 1.2V P1DIR ^= BIT6; if (SD16MEM0 < THRSHMAX ){ P2OUT |= BIT7;} // SD16MEM0 > 1.2V?, clears IFG if (SD16MEM0 > THRSHMIN ){ P2OUT |= BIT7;} else { P2OUT = 0; } } I have tried changing the the threshold to different values, tried different inputs,changed clock dividers but I can not get it to work Input signal is an Audio track, going through a low pass filter then biased to 1.2Vs, the audio is within in the .6V FSR The led at 2.7 should be blinking every time it exceeds the threshold, but i get nothing on P2.7 I know the ISR is working since i can see the P1.6 on the scope toggle............ can any one suggest what i am doing wrong? or how i should proceed next? ......btw serial output is not really an option at this time Quote Link to post Share on other sites
RobG 1,892 Posted July 22, 2011 Share Posted July 22, 2011 if (SD16MEM0 < THRSHMAX ){ P2OUT |= BIT7;} // SD16MEM0 > 1.2V?, clears IFG if (SD16MEM0 > THRSHMIN ){ P2OUT |= BIT7;} else { P2OUT = 0; } How about this (ON when outside of threshold): if (SD16MEM0 > THRSHMAX ){ P2OUT |= BIT7;} else if (SD16MEM0 < THRSHMIN ){ P2OUT |= BIT7;} else { P2OUT = 0; } or (ON when within threshold): if ((SD16MEM0 < THRSHMAX ) && (SD16MEM0 > THRSHMIN )) { P2OUT |= BIT7;} else { P2OUT = 0; } Quote Link to post Share on other sites
jsolarski 94 Posted July 22, 2011 Author Share Posted July 22, 2011 Thanks RobG, I will try both of these tonight and see if i get different results. Hopefully this is that last hurdle to finish my BPM counter, so i can finally enter the POTM Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 I tried both, and no luck...... so i did a quick debug and stepped through the whole thing, the weird part is the CPU faults and the only way to get it back to working is to reset it. It stops right after this part ( PC: 0f87e) ( R4: 007fd) ( R8: 0ffff) (R12: 0ffff) ( SP: 00280) ( R5: 05a08) ( R9: 0ff77) (R13: 0fbb7) ( SR: 000fb) ( R6: 03dbf) (R10: 0afef) (R14: 07ff9) ( R3: 00000) ( R7: 06f3e) (R11: 019ff) (R15: 00000) 0xf87e: 0f87e: fd 3f JMP 0xf87a 0f880: 30 40 b0 f8 BR #0xf8b0 0f884: 0f 12 PUSH R15 0f886: f2 e0 40 00 22 00 XOR.B #0x0040, &0x0022 0f88c: 1f 42 so I am going back to basics to make sure the ISR is working correctly, and i made a small adjustable voltage divider to test, so i dont have to keep playing the same record over and over and over again lol very frustrating any ideas of whats going on is appreciated edit-- tested with no real code in the ISR, just toggle a pin and still stops at the same place mpsdebug error after it stops fet: FET returned error code 16 (Could not single step device) fet: failed to restart CPU I still dont understand why this is not working compiler flags as well -Os -Wall -g -mmcu=msp430f2013 Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 objdump that gordon had suggested Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 With gordons help -- i need to add either a while(1) loop or use lpm bits or the mendup-at= flag at least it starting to work, now time to tweak some code so it works correctly Quote Link to post Share on other sites
gordon 229 Posted July 25, 2011 Share Posted July 25, 2011 For others' reference, as I told jsolarski, I strongly believe -mendup-at=main should not ever be used. There's room for a nasty surprise if, for example, your setup code runs again when you don't expect it. jsolarski 1 Quote Link to post Share on other sites
RobG 1,892 Posted July 25, 2011 Share Posted July 25, 2011 CCS doesn't have mendup-at, but it does insert an infinite loop after the main, so things like that always work in CCS even without explicit loop (while(1) or for(;.) call #main call #abort ... abort: NOP L1: JMP (L1) Quote Link to post Share on other sites
gordon 229 Posted July 25, 2011 Share Posted July 25, 2011 MSPGCC turns the whole lot off beforehand: [main()'s last instruction] 0000f99c <__stop_progExec__>: .global _endless_loop__ .weak _endless_loop__ .func _endless_loop__ _endless_loop__: bis #0xf0, r2 f99c: 32 d0 f0 00 bis #240, r2 ;#0x00f0 f9a0: fd 3f jmp $-4 ;abs 0xf99c Jsolarski's original question was actually "why do I get Could not single step device". If the MSPGCC Crt was to just loop infinitely, that is to the same effect as "while(1);", his code should have worked just OK. Thankfully, he had a consistent address where the debugger would give up the ghost, then (after having gotten the helpful objdump output) it became painfully apparent that the MSPGCC Crt is erring on quite the safe side when it comes to getting out of main() . Another compiler-related difference to make note of. Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 Ok past the first bit of code, now im testing with no audio on the pin, just 1.123v bias coming from my low pass filter. but still only getting 0xffff as my result.....in theory it should be under 0x8000. tried a different pin with the same result, when nothing is connected the value is 0x87d3 still testing but any thoughts would be helpful Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 maybe someone else can confirm the input range of the sd16 on the f2013, from what i can tell in the data sheet and how what i thought it should be, originally thought +-Vfsr from the Vref, but from what i can tell its +-Vfsr from 0Vs.......the second seems to be correct but i cant find it in the data sheet, and in testing at 0Vs its close to 0x8000 and when its get close to .6Vs --0xffff is the value. Quote Link to post Share on other sites
oPossum 1,083 Posted July 25, 2011 Share Posted July 25, 2011 What is the inverting (-) input connected to? Ground? I assume it would have to be biased above ground to get full +/- range. Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 the negative input is connected to ground and that was my first thought was to bias the input above ground, originally I had a bias of 1.12 volts........but it didnt work, kept getting a value of 0xffff after setting up an adjustable voltage divider 0V - 1.2 i was getting half range from 0v to .6v (8000 to ffff) Quote Link to post Share on other sites
oPossum 1,083 Posted July 25, 2011 Share Posted July 25, 2011 and that was my first thought was to bias the input above ground, originally I had a bias of 1.12 volts. On the inverting (-) or non-inverting (+) input? I think you need a 600 mV bias on inverting (-) input to get 0 to 1.2 volt range on non-inverting (+) input. Quote Link to post Share on other sites
jsolarski 94 Posted July 25, 2011 Author Share Posted July 25, 2011 just the non-inverting input (+). if i wanted -.6v to +.6v, could i leave it the way it is? since my signal is originally ac and i can easily remove the bias 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.