Jump to content
43oh

oliveiracarlos

Members
  • Content Count

    22
  • Joined

  • Last visited

Reputation Activity

  1. Like
    oliveiracarlos reacted to RobG in MSP430 Analog read - potentiometer value floating   
    1. What value is your pot?
    2. What are the default ADC settings for analogRead? (I am not familiar with Energia.)
     
    Few things you can try: lower pot's value, extend sample time, and use Vref from MSP430 to power your pot.
     
    In the example below, I am using 50k pot (el cheapo,) Vcc to power my pot, and S&H time = 16x ADC10CLKs.
    Very stable, no changes whatsoever.
     

     
    #include <msp430g2553.h> unsigned char txData[6] = {0,0,0,0,'\r','\n'}; void binaryToASCII(unsigned int n, unsigned char * digits); void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; P1SEL = BIT2; // P1.2 is TXD P1SEL2 = BIT2; UCA0CTL1 |= UCSSEL_2; UCA0BR0 = 104; UCA0BR1 = 0; UCA0MCTL = UCBRS_1; UCA0CTL1 &= ~UCSWRST; ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_0; // P1.0 analog input ADC10AE0 |= BIT0; CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 6400; // sample every 50ms TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { binaryToASCII(ADC10MEM >> 3, txData); char c = 0; while(c < 6) { while (!(IFG2 & UCA0TXIFG)) ; UCA0TXBUF = txData[c]; c++; } } // Timer A0 interrupt service routine #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A (void) { ADC10CTL0 |= ENC + ADC10SC; } void binaryToASCII(unsigned int n, unsigned char * digits) { __asm(" clr R14"); __asm(" rla R12"); __asm(" rla R12"); __asm(" rla R12"); __asm(" rla R12"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" mov.b R14, 3(R13)"); __asm(" swpb R14"); __asm(" mov.b R14, 1(R13)"); __asm(" rra R14"); __asm(" rra R14"); __asm(" rra R14"); __asm(" rra R14"); __asm(" mov.b R14, 0(R13)"); __asm(" swpb R14"); __asm(" mov.b R14, 2(R13)"); __asm(" and #0x0F0F, 0(R13)"); __asm(" and #0x0F0F, 2(R13)"); __asm(" add.b #0x30, 3(R13)"); __asm(" tst.b 0(R13)"); __asm(" jnz l1"); __asm(" mov.b #0x20, 0(R13)"); __asm(" tst.b 1(R13)"); __asm(" jnz l2"); __asm(" mov.b #0x20, 1(R13)"); __asm(" tst.b 2(R13)"); __asm(" jnz l3"); __asm(" mov.b #0x20, 2(R13)"); __asm(" jmp l4"); __asm("l1:"); __asm(" add.b #0x30, 0(R13)"); __asm("l2:"); __asm(" add.b #0x30, 1(R13)"); __asm("l3:"); __asm(" add.b #0x30, 2(R13)"); __asm("l4:"); return; }
  2. Like
    oliveiracarlos reacted to RobG in MSP430 Analog read - potentiometer value floating   
    unsigned int sensor4Valor; void setup() { Serial.begin(9600); } void loop() { sensor4Valor = analogRead(A7) >> 3; Serial.print("Pot 1 value = "); Serial.print(sensor4Valor); Serial.println(" | "); delay(1); } or
     
    unsigned int sensor4Valor = 0; unsigned int adc = 0; unsigned int adcMin = 0; unsigned int adcMax = 0; void setup() { Serial.begin(9600); } void loop() { adc = analogRead(A7); if( adc > adcHigh || adc < adcLow) { adcHigh = adc + 2; adcLow = adc - 2; sensor4Valor = adc >> 3; // divide 10 bit to get 7bit, MIDI uses 0-127 } Serial.print("Pot 1 value = "); Serial.print(sensor4Valor); Serial.println(" | "); delay(1); }  
  3. Like
    oliveiracarlos reacted to skaven in Setting up PWM on launchpad   
    With some more tinkering I was able to get PWM working as expected, and I was able to output PWM to arbitrary pins (though I settled on P1.6 since it's got an LED hooked up already).
     
    I wrote this simple little program to ensure I understood how to incorporate interrupts (from a pin, not a timer) along with a PWM output...maybe this will be useful to somebody. This code runs on a MSP430G2231, but I suspect it'll run on any of the 430's...
     

    //****************************************************************************** // Description: Toggle P1.0 using interrupt routine. Timer_A is configured // for up mode with CCR0 defining period, TA0 also output on P1.6. P1.6 // will pulse up (brighter) by default. Toggle P1.3 (S2) and the direction will // change, making P1.6 pulse down (dimmer) as well as toggling P1.0 (indicating // direction). // ACLK = n/a, SMCLK = MCLK = TACLK = default DCO // // MSP430G2xx1 // ----------------- // /|\| XIN|- // | | | // --|RST XOUT|- // | | // S2 -->|P1.3 P1.0|--> LED1 // | | // | P1.6/TAO|--> LED2/PWM out //****************************************************************************** #include unsigned int pwm_duty=1; int dir = 1; void main(void) { unsigned int x; WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1OUT &= 0x0; // Drop all outputs to zero by default P1DIR |= ~BIT3; // P1.3 input, all others output P1IE |= BIT3; // P1.3 interrupt enable P1IFG &= ~BIT3; // Clear the P1.3 interrupt P1SEL |= BIT6; // P1.6 option select (enables timer output) CCR0 = 1000-1; // PWM period CCTL1 = OUTMOD_7; // Timer_A output reset/set mode CCR1 = pwm_duty; // PWM duty cycle TACTL = TASSEL_2 + MC_1; // use SMCLK, up mode _BIS_SR(GIE); // Enable interrupts while(1) { // Increment or decrement the PWM duty pwm_duty = pwm_duty + dir; if(pwm_duty > 998) { pwm_duty = 1; } if(pwm_duty < 1) { pwm_duty = 999; } // Set the duty cycle CCR1 = pwm_duty; // Pause to give a nice pulse speed for(x=0; x<100; x++); } } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { dir *= -1; // change pulse direction P1OUT ^= BIT0; // toggle P1.0 P1IFG &= ~BIT3; // clear interrupt }
  4. Like
    oliveiracarlos got a reaction from GeekDoc in Int To Hexa ?   
    Thanks all replys.
     
    Roadrunner thx for the tip, I have no experience shifting to get results. I really appreciated your help.
     
    But cuberge was right, I dont need to convert, just use the 0..127 potentiometer value !
     
    I will let the code here if someone wanna use. This code calcs the checksum used to send messages to Rolands keyboards. Now its workings right. With my [poor] english comments. Hope to help somebody.
     
     
    #include <math.h> int sensor1 = 0; long int sensor1Value = 0; void setup() {   Serial.begin(31250); //Starts serial use - 31250 to midi messages } void loop() {   sensor1Value = f1024t8(analogRead(A3)); //Get the potentiometer value using 1.3 pin   SendSysex(0x1F, 0x00, 0x20, 0x49, sensor1Value); //this message is: tfv.cufoff   delay(1); } //Converting the 0..1024 value from analog read to 0..127 (used to send midi messages). //But some messages uses anothes values like 0..63, I still dont know what I gonna do. //And I gonna change the function to use roadrunner84 tip long int f1024t8(long int f1024){  ldiv_t res;  res = ldiv(f1024, 8);  return res.quot; } //Sending the midi exclusive message algorithm void SendSysex(long int addr1, long int addr2, long int addr3, long int addr4, long int data){  //sum parameters values  long int addrMaisData = 0;  addrMaisData = addr1 + addr2 + addr3 + addr4 + data;   //div the sum parameterse values by 128 and hold the remainder  long int restoDiv = 0;  ldiv_t   restoTemp;  restoTemp = ldiv(addrMaisData, 128);  restoDiv  = restoTemp.rem;    //128 - remainder = checksum value  long int checksum = 0;  checksum = 128 - restoDiv;    long int zero = 0x00; //I dont know why but this var was needed to use as parameter, if I use 0x00 as parameter I get and Energia error message. //Send the message, writing to serial  Serial.write(0xF0); //msg start  Serial.write(0x41); //Roland id  Serial.write(0x10); //Device id  Serial.write(zero); //Model Id (this case = Juno di)  Serial.write(zero); //Model Id (this case = Juno di) Serial.write(0x3A); //Model Id (this case = Juno di) Serial.write(0x12); //Command Id    Serial.write(addr1); //Address  Serial.write(addr2); //Address  Serial.write(addr3); //Address  Serial.write(addr4); //Address  Serial.write(data); //Data  Serial.write(checksum); //Checksum    Serial.write(0xF7); //msg end } //for more info try the Roland Midi Implementation Document
  5. Like
    oliveiracarlos got a reaction from cubeberg in Int To Hexa ?   
    Thanks all replys.
     
    Roadrunner thx for the tip, I have no experience shifting to get results. I really appreciated your help.
     
    But cuberge was right, I dont need to convert, just use the 0..127 potentiometer value !
     
    I will let the code here if someone wanna use. This code calcs the checksum used to send messages to Rolands keyboards. Now its workings right. With my [poor] english comments. Hope to help somebody.
     
     
    #include <math.h> int sensor1 = 0; long int sensor1Value = 0; void setup() {   Serial.begin(31250); //Starts serial use - 31250 to midi messages } void loop() {   sensor1Value = f1024t8(analogRead(A3)); //Get the potentiometer value using 1.3 pin   SendSysex(0x1F, 0x00, 0x20, 0x49, sensor1Value); //this message is: tfv.cufoff   delay(1); } //Converting the 0..1024 value from analog read to 0..127 (used to send midi messages). //But some messages uses anothes values like 0..63, I still dont know what I gonna do. //And I gonna change the function to use roadrunner84 tip long int f1024t8(long int f1024){  ldiv_t res;  res = ldiv(f1024, 8);  return res.quot; } //Sending the midi exclusive message algorithm void SendSysex(long int addr1, long int addr2, long int addr3, long int addr4, long int data){  //sum parameters values  long int addrMaisData = 0;  addrMaisData = addr1 + addr2 + addr3 + addr4 + data;   //div the sum parameterse values by 128 and hold the remainder  long int restoDiv = 0;  ldiv_t   restoTemp;  restoTemp = ldiv(addrMaisData, 128);  restoDiv  = restoTemp.rem;    //128 - remainder = checksum value  long int checksum = 0;  checksum = 128 - restoDiv;    long int zero = 0x00; //I dont know why but this var was needed to use as parameter, if I use 0x00 as parameter I get and Energia error message. //Send the message, writing to serial  Serial.write(0xF0); //msg start  Serial.write(0x41); //Roland id  Serial.write(0x10); //Device id  Serial.write(zero); //Model Id (this case = Juno di)  Serial.write(zero); //Model Id (this case = Juno di) Serial.write(0x3A); //Model Id (this case = Juno di) Serial.write(0x12); //Command Id    Serial.write(addr1); //Address  Serial.write(addr2); //Address  Serial.write(addr3); //Address  Serial.write(addr4); //Address  Serial.write(data); //Data  Serial.write(checksum); //Checksum    Serial.write(0xF7); //msg end } //for more info try the Roland Midi Implementation Document
  6. Like
    oliveiracarlos reacted to oPossum in Int To Hexa ?   
    void uint32hex(uint32_t x, char *s)
    {
    unsigned n = 8;
    s += n;
    *s-- = 0;
    do {
    *s-- = "0123456789ABCDEF"[x & 15];
    x >>= 4;
    } while(--n);
    }

×
×
  • Create New...