Show Posts
Pages: 1 2 [3] 4 5 ... 166
31  Using Arduino / Project Guidance / Re: RF detector falling off for some reason on: March 28, 2014, 05:12:48 pm
May be link was corrupted, here I attached a schematics:

32  Products / Arduino Due / Re: Continuous SPI for multiple bytes on: March 28, 2014, 05:02:34 pm
I'm not sure about 10th of MHz, but to go faster you better use DMA + SPI channel, w/o a library.  Look inside spi.c file for start.
33  Using Arduino / LEDs and Multiplexing / Re: Using BJT's with a 595 shift register not outputting expected current. on: March 28, 2014, 10:32:36 am
to OP: find UDN2981 /2982 - high side switch,
34  Using Arduino / Project Guidance / Re: RF detector falling off for some reason on: March 28, 2014, 10:26:08 am
Make a call,  send a SMS/MMS, or navigate a browser.
http://www.linear.com/search/search.php?q=AN87&col=doc-an&start=&sort=&order=&ci=0
This doc has nice RF detector on page 110.
35  Using Arduino / LEDs and Multiplexing / Re: Using BJT's with a 595 shift register not outputting expected current. on: March 28, 2014, 10:14:06 am
PNP is not enough to make a high side switch, there 'd be +12 V at emmiter, and base at max +5, it's not going to off.
Why there is 595, do you need more pins? If you replace 595 with ULN2803 and 8 PNP , than you 'd be o'k
36  Using Arduino / LEDs and Multiplexing / Re: Using BJT's with a 595 shift register not outputting expected current. on: March 28, 2014, 07:39:36 am
Swap LED and R1
37  Using Arduino / Programming Questions / Re: default on time of a pin on: March 28, 2014, 07:36:43 am
Approximately time of execution digitalWrite, or 4.7 usec
38  Using Arduino / Project Guidance / Re: Coding a pulse signal on: March 28, 2014, 07:35:24 am
Search for MrTimer or TimerOne library.
39  Using Arduino / Programming Questions / Re: Generating 77.5 kHz on: March 27, 2014, 05:12:08 pm
You are welcome.  The point is, use serial all the time, nice debugging feature we only have on arduino.
I can't find the sketch, that bugged me with signed/unsigned problem in the past.  Probably, it was on earlier IDE, 0.22 or 1.0
But I recollect another issue I had with Leonardo board, here is the ~2 years old discussion:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=125907&highlight=
 The problem is inability to set ADTS bit on AtMega32u4. The was no any mistakes in syntaxis, bit just stubbornly refused to set. Serial print help me to find, that one of the header file in the avr library has an error. Reported long time ago:
https://savannah.nongnu.org/bugs/?30569
 
And know what?  I just checked my IDE 1.0.5 and bug still there!
 
Code:
#define ADCSRB _SFR_MEM8(0x7B)
#define ADTS0 0
#define ADTS1 1
#define ADTS2 2
#define ADTS3 4 <<<-
#define MUX5 5
#define ACME 6
#define ADHSM 7
 
40  Products / Arduino Due / Re: Arduino Due DAC0 problem (not working) on: March 27, 2014, 04:30:54 pm
 10 hours test pass. Probably,  writing 0x3 (DACC_ACR_IBCTLCH0(0x03)) instead of 0x2  has no difference.  
I checked what is arduino IDE using inside analogWrite - it's 0x2.
41  Using Arduino / Programming Questions / Re: Outputing 80 kHz from Arduino UNO on: March 27, 2014, 12:41:52 pm
Are you trying to write 400 to Timer2 register? 8-bits register?
Code:
  OCR2A = B10010000; // 400, so timer2 counts from 0 to 400 (400 cycles at 16 MHz)
Change preselector, to run at slower speed.
42  Using Arduino / Programming Questions / Re: Generating 77.5 kHz on: March 27, 2014, 09:22:06 am
 I find a problem in original code. Here what were written in the registers:
Quote
   TCCR2A  = 1
   TCCR2B  = 1
   OCR2A  = CE
   OCR2A DEC  = 206
   OCR2B  = 67
   OCR2B DEC = 103
   TIMSK2  = 2

Here correct values:
Quote
   TCCR2A  = 23
   TCCR2B  = 9
   OCR2A  = CE
   OCR2A DEC  = 206
   OCR2B  = 67
   OCR2B DEC = 103
   TIMSK2  = 2
This time the problem was not related to subtraction from unsigned,  just wrong syntaxis . Correct version - working like a charm:
Code:
// 16000000 / 77500 = 206 + 70/155 = 206 + 14/31
const uint8_t ticks_per_period = 206;
// fractional ticks
const uint8_t nominator = 14;
const uint8_t denominator = 31;

const uint8_t pwm_full_carrier      = ticks_per_period / 2;  // ~50  %   duty cycle
const uint8_t pwm_modulated_carrier = ticks_per_period / 8;  // ~12.5% duty cycle


ISR(TIMER2_COMPA_vect) {
    static uint8_t accumulated_fractional_ticks;

    accumulated_fractional_ticks += nominator;
    if (accumulated_fractional_ticks < denominator) {
        OCR2A = ticks_per_period - 1;
    } else {
        OCR2A = ticks_per_period;
        accumulated_fractional_ticks -= denominator;
    }
}

void setup_timer_0() {
    // disable timer 0 interrupts
    TIMSK0 = 0;
}

void setup_timer_1() {
    // disable timer1 interrupts
    TIMSK1 = 0;

    // do not toggle or change timer IO pins
    TCCR1A = 0;       

    // (16000000 / 256) - 1
    OCR1A = 62500 - 1;
   
    // Mode 4, CTC using OCR1A | set prescaler to 256
    TCCR1B = (1<<WGM12) | (1<<CS12);
}

void setup_timer_2() {
     // disable timer2 interrupts during setup
    TCCR2A = 0;
    TCCR2B = 0;
    TIMSK2 = 0;

    // enable OC2B pin for output (digital pin 3)
    DDRD |= 1<<3;

    // The fast Pulse Width Modulation or fast PWM mode (WGM22:0 = 3 or 7) provides a high fre-
    // quency PWM waveform generation option. The fast PWM differs from the other PWM option by
    // its single-slope operation. The counter counts from BOTTOM to TOP then restarts from BOT-
    // TOM. TOP is defined as 0xFF when WGM2:0 = 3, and OCR2A when MGM2:0 = 7. In non-
    // inverting Compare Output mode, the Output Compare (OC2x) is cleared on the compare match
    // between TCNT2 and OCR2x, and set at BOTTOM. In inverting Compare Output mode, the out-
    // put is set on compare match and cleared at BOTTOM.


    TCCR2A |= (1<< WGM20) | (1<<WGM21) | // Fast PWM
              (1<<COM2B1);               // Clear OC2B on Compare Match

    TCCR2B |= (1<<CS20) | // no Prescaler     
              (1<<WGM22);  // Fast PWM

    OCR2A = ticks_per_period - 1;  // period length

    OCR2B = pwm_full_carrier;  // duty cycle
   
    // enable match interrupts
    TIMSK2 |= (1<<OCIE2A);
}

void setup() {
    setup_timer_0();
    setup_timer_1();
    setup_timer_2();
  Serial.begin(115200); 
}

void modulate(const uint8_t duration) {
}

void loop()
{
  char incomingByte;
  uint8_t reg_t;
 
   if (Serial.available() > 0) {   
    incomingByte = Serial.read();
    // "x" command - DEBUG
    if (incomingByte == 'x') {

      reg_t = TCCR2A;
       Serial.print("\n\tTCCR2A  = ");
       Serial.println(reg_t, HEX);
      reg_t = TCCR2B;
       Serial.print("\n\tTCCR2B  = ");
       Serial.println(reg_t, HEX);
      reg_t = OCR2A;
       Serial.print("\n\tOCR2A  = ");
       Serial.println(reg_t, HEX);
       Serial.print("\n\tOCR2A DEC  = ");
       Serial.println(reg_t, DEC);
      reg_t = OCR2B;
       Serial.print("\n\tOCR2B  = ");
       Serial.println(reg_t, HEX);
       Serial.print("\n\tOCR2B DEC = ");
       Serial.println(reg_t, DEC);
      reg_t = TIMSK2;
       Serial.print("\n\tTIMSK2  = ");
       Serial.println(reg_t, HEX);
    }     
  }
}

Quote
It has always worked perfectly for me. Could you post an example of how it fails?
Yes, I will check my sketches, and post back when I find.
43  Using Arduino / Programming Questions / Re: Generating 77.5 kHz on: March 27, 2014, 08:31:50 am
Quote
Not a good idea in an ISR. Never use methods of the Serial object in interrupt context, you might produce a dead lock.
I haven't say in the ISR.
Quote
Subtraction works perfectly with unsigned variables it's just a bit different from the signed variants.
And you are mister avr-gcc compiler expert? 
44  Using Arduino / Programming Questions / Re: Generating 77.5 kHz on: March 27, 2014, 08:06:58 am
My suggestion,  use serial whenever doubts in configuration, print out all TIMER registers content in HEX and verify bit by bit if all  right.
In my experience, subtraction from unsigned variable never works correctly on arduino (drawback of optimization), in your case you may be surprised getting out from OCR2A/B   not what you expect to see.
45  Products / Arduino Due / Re: Arduino Due DAC0 problem (not working) on: March 26, 2014, 11:09:45 pm
Quote
Arduino, which uses the software reset command of the control register (SWRST) never resets the ACR as per Table 45-3.
I agree on this, table clearly says reset status 0x0 , and obviously it's not.
My understanding, based on table 46-38,
Quote
Sleep Mode
Fast Wake Up
Normal Mode with 1 Output On (IBCTLDACCORE = 01,
IBCTLCHx =10)
Normal Mode with 2 Outputs On (IBCTLDACCORE =01,
IBCTLCHx =10)
that setting ACR to 0x0 you send all unit down to sleep mode. IBCTLHx most likely control reference current level for S/H circuitry, and daccore explains itself. I can't resist  to drive all unit up, to 30F, setting max bias current for core and two S/H. My mini DSO shows no noticeable difference -).
Code:
//  dacc_set_analog_control(DACC, DACC_ACR_IBCTLCH0(0x02) | DACC_ACR_IBCTLCH1(0x02) | DACC_ACR_IBCTLDACCORE(0x01));
  dacc_set_analog_control(DACC, DACC_ACR_IBCTLCH0(0x03) | DACC_ACR_IBCTLCH1(0x03) | DACC_ACR_IBCTLDACCORE(0x03));
Will keep it working all night, mini-stress testing
Pages: 1 2 [3] 4 5 ... 166