Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Re: Need to provide voltage to an external device without PWM on: March 11, 2013, 11:33:33 am
hey nice idea  smiley. I'll try it and let you know.
Thanks
2  Using Arduino / Project Guidance / Need to provide voltage to an external device without PWM on: March 11, 2013, 05:17:58 am
Hi everyone,

From one of my project i need my Arduino to provide some current to another device. This device can run in different mode, depending of the voltage it receives. So i need to be able to dynamically change the value of the voltage the Arduino provides from a digital pin. I know i can use PWM pins to resolve this problem, but in my case all my timer are already used for other operations. So i  need to find a way to provide a current which can vary from 0V to 5V, the more accurate possible and in a cheaper way  smiley-twist.
All suggestions are welcome.

Quertyn
3  Using Arduino / Programming Questions / Re: [Solved] Arduino Leonardo - Timer in CTC running slower than expected on: February 07, 2013, 10:42:33 pm
Yes  smiley-grin
4  Using Arduino / Programming Questions / Re: Arduino Leonardo - Error > Timer in CTC running 8 time slower on: February 07, 2013, 10:24:44 pm
I confirm OCR3A = 7.
Before i was usign this code with Arduino Mega on timer2 and it works. I made a mistake in porting, it should be like this for TCCR3A and TCCR3B (WGM32 is on TCCR3B not on TCCR3A) :
Code:
void clk_start(uint32 frequency) {
// Timer/Counter Register
TCNT3  = 0;

// Timer/Counter Control Register A
// Bit 7      6      5      4      3      2      1     0
//     COMnA1 COMnA0 COMnB1 COMnB0 COMnC1 COMnC0 WGMn1 WGMn0
//
// COMnA1:0: Compare Match Output A Mode
//     These bits control the Output Compare pin (OCnA) behavior.
//
//     COMnA1 COMnA0 Description
//          0      0 Normal port operation, OCnA disconnected
//          0      1 Toggle OCnA on Compare Match
//          1      0 Clear OCnA on Compare Match
//          1      1 Set OCnA on Compare Match
//
// WGMn1:0: Waveform Generation Mode
//     Combined with the WGMn2 bit found in the TCCRnB Register, these
//     bits control the counting sequence of the counter, the source
//     for maximum (TOP) counter value, and what type of waveform
//     generation to be used.
//
//     WGMn3 WGMn2 WGMn1 WGMn0 Mode of Operation  TOP Update of OCRx
//         0     1     0     0               CTC OCRA      Immediate
TCCR3A = (1 << COM3A0);

// Output Compare Register A
//
//                   fclk_I/O
//     fOCnx = ---------------------
//              2 * N * (1 + OCRnx)
//
//     The N variable represents the prescale factor
//     (1, 8, 64, 256, or 1024).
OCR3A  = (F_CPU / (frequency * 2)) - 1;
   
// Timer/Counter Control Register B
// Bit 7     6     5 4     3     2    1    0
//     ICNCn ICESn - WGMn3 WGMn2 CSn2 CSn1 CSn0
//
// CSn2:0: Clock Select
//     The three Clock Select bits select the clock source to be used by the
//     Timer/Counter.
//
//     CSn2 CSn1 CSn0  Description
//        0    0    0          OFF
//        0    0    1        clock
//        0    1    0    clock / 8
//        0    1    1   clock / 64
//        1    0    0  clock / 256
//        1    0    1 clock / 1024
TCCR3B = (1 << WGM32) | (1 << CS30);
}

Thanks for your help.
5  Using Arduino / Programming Questions / Re: Arduino Leonardo - Error > Timer in CTC running 8 time slower on: February 07, 2013, 02:57:40 pm
You 're right, bad math at 4pm. smiley-wink
Any idea why such a difference ? I have the feeling that it toggle on overflow of TCNT3.
6  Using Arduino / Programming Questions / [Solved] Arduino Leonardo - Timer in CTC running slower than expected on: February 07, 2013, 02:08:29 pm
Hi everyone,

I'm working on Arduino Leonardo without the Arduino library directly with Atmel Studio 6 + AVR Dragon through JTAG to debug / program.
I'm trying to reuse a digital pin to provide a clock signal to an external device.

Code:
/* Initialize the external clock to provide.
 *     1 - Stop Timer3.
 *     2 - Disable all interrupts related to Timer3.
 *     3 - Set Digital Pin 5 (PC6) as Output.
 *     4 - Put Digital Pin 5 (PC6) to Low.
 */
void clk_init(void) {
// Timer/Counter Control Register B
// Bit 7     6     5 4     3     2    1    0
//     ICNCn ICESn - WGMn3 WGMn2 CSn2 CSn1 CSn0
TCCR3B = 0;

// Timer/Counter Interrupt Flag Register
// Bit 7 6 5    4 3     2     1     0
//     - - ICFn - OCFnC OCFnB OCFnA TOVn
TIFR3 &= ~((1 << ICF3) | (1 << OCF3C) | (1 << OCF3B) | (1 << OCF3A) | (1 << TOV3));

// Timer/Counter Interrupt Mask Register
// Bit 7 6 5     4 3 2     1     0
//     - - ICIEn - OCIEnC OCIEnB OCIEnA TOIEn
TIMSK3 &= ~((1 << ICIE3) | (1 << OCIE3C) | (1 << OCIE3B) | (1 << OCIE3A) | (1 << TOIE3));

// Port C Data Direction Register
// Bit 7    6    5    4    3    2    1    0
//     DDC7 DDC6 DDC5 DDC4 DDC3 DDC2 DDC1 DDC0
DDRC |= (1 << DDC6);

// Port C Data Register
// Bit 7      6      5      4      3      2      1      0
//     PORTC7 PORTC6 PORTC5 PORTC4 PORTC3 PORTC2 PORTC1 PORTC0
//PORTC &= ~(1 << 6);
PORTC |= (1 << 6);
}

/* Configure and start the external clock to provide.
 *     @frequency: clock speed in Hz.
 */
void clk_start(uint32 frequency) {
// Timer/Counter Register
TCNT3  = 0;

// Timer/Counter Control Register A
// Bit 7      6      5      4      3      2      1     0
//     COMnA1 COMnA0 COMnB1 COMnB0 COMnC1 COMnC0 WGMn1 WGMn0
//
// COMnA1:0: Compare Match Output A Mode
//     These bits control the Output Compare pin (OCnA) behavior.
//
//     COMnA1 COMnA0 Description
//          0      0 Normal port operation, OCnA disconnected
//          0      1 Toggle OCnA on Compare Match
//          1      0 Clear OCnA on Compare Match
//          1      1 Set OCnA on Compare Match
//
// WGMn1:0: Waveform Generation Mode
//     Combined with the WGMn2 bit found in the TCCRnB Register, these
//     bits control the counting sequence of the counter, the source
//     for maximum (TOP) counter value, and what type of waveform
//     generation to be used.
//
//     WGMn3 WGMn2 WGMn1 WGMn0 Mode of Operation  TOP Update of OCRx
//         0     1     0     0               CTC OCRA      Immediate
TCCR3A = (1 << COM3A0) | (1 << WGM32) ;

// Output Compare Register A
//
//                   fclk_I/O
//     fOCnx = ---------------------
//              2 * N * (1 + OCRnx)
//
//     The N variable represents the prescale factor
//     (1, 8, 64, 256, or 1024).
OCR3A  = (F_CPU / (frequency * 2)) - 1;
   
// Timer/Counter Control Register B
// Bit 7     6     5 4     3     2    1    0
//     ICNCn ICESn - WGMn3 WGMn2 CSn2 CSn1 CSn0
//
// CSn2:0: Clock Select
//     The three Clock Select bits select the clock source to be used by the
//     Timer/Counter.
//
//     CSn2 CSn1 CSn0  Description
//        0    0    0          OFF
//        0    0    1        clock
//        0    1    0    clock / 8
//        0    1    1   clock / 64
//        1    0    0  clock / 256
//        1    0    1 clock / 1024
TCCR3B = (1 << CS30);
}

The problem is  when i do:

Code:
clk_init();
clk_start(1000000);

I noticed, with my analyzer logic, it provides a clock with a frequency of 122Hz instead of 1MHz.
I dont understand why i got such a difference. Any idea ? Could it be linked with the fuses ?

My current fuses:
Extended: 0xFB
High: 0x10
Low: 0xFF

Thanks.
7  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 16, 2013, 10:49:55 am
Quote
I was not so wrong  smiley-twist, took this in HardwareSerial.cpp:
Yes, and how many Arduinos does that apply to?
I don't know. But I think it's better to be aware of the under layer limitation even if it's seems large.
8  Using Arduino / Project Guidance / Re: USART Half Duplex on a single-wire and external clock on: January 16, 2013, 10:35:18 am
I realize that, and indeed have an example of doing just that here:

http://www.gammon.com.au/forum/?id=10892&reply=3#reply3

However the fact remains that this is really using SPI and not async serial in this case. The original post asked:

Quote
... how can I compute the correct baud rate ...

... which suggests s/he is trying to use async serial to solve a problem with something that has a clock signal.

Sound interresting, before this week end I'll try to do something with SPI. And let you know.
9  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 16, 2013, 10:25:31 am
Quote
keep in mind, for later use, the size of the buffer used by Serial library to store the received bytes, 16bytes if I remember well.
You don't smiley-wink (unless you've got very restricted RAM, like on a Tiny)

I was not so wrong  smiley-twist, took this in HardwareSerial.cpp:

Code:
// Define constants and variables for buffering incoming serial data.  We're
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
#if (RAMEND < 1000)
  #define SERIAL_BUFFER_SIZE 16
#else
  #define SERIAL_BUFFER_SIZE 64
#endif

In your case it's working because you are in the case where buffer size is 64.
10  Using Arduino / Project Guidance / Re: USART Half Duplex on a single-wire and external clock on: January 16, 2013, 10:08:39 am
Hi guys,

Sorry for the late reply.
Just to resume, I have one Arduino Mega2560 which is linked to a smart card connector. This smart card connector just redirects the contacts of a smart cart to 8 pins. In my case I'm focusing on the IO part. The way to communicate with a smart card is defined in the ISO 7816-3 http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-3.aspx. Typically, the Arduino provided an external clock to the smart card to indicate the speed to use to transmit the data. Another wire is used for IO. So far I have one driver on Arduino which handle the communication but it's all in software, meaning managing the external clock + exchanging the bits are done in software, which brings some limitation, I cannot go faster than with a clock at 1MHz.

My idea is to handle my IO in hardware. I know some chip provides an UART hardware ISO 7816-3 compliant but I prefer to try first to solve this without adding any hardware part. My first idea is to reuse one of the hardware USART and trick it to be able to use it with a smartcard. But one problem is the speed, for USART it's related at one point at the internal clock. At first, I don't know why, I was block by SPI, but it seems a better solution and at least a more evident one regarding your comments. One think, it's dumb but i rather to be sure, in my environment the ground used by SPI should be link to the ground of the smartcard right?

To answer your previous comments, having my own library isn't a problem. I'm doing my project without the Arduino library, like this i have more registers / options to play with. First I was asking how to compute the baud rate because I wanted to trick my Arduino and send data like if my internal clock was at 1MHz. For Riva: The ISO 7816-3 specifies (at least at begining) that every bit duration is 372 clock pulses for a clock at 1MHz, meaning the OP needs the data bit to hold then change only every 372 clock pulses.

I think If I want to use SPI I'll need some pull up resistors as well in order to have a SPI over a single IO wire + clock + ground. What do you think ?

Thanks for your help.
11  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 16, 2013, 09:08:21 am
Code:
  while(Serial.available() == 0){
    delay(10);
  }
Can you describe the exact purpose for the delay()? Does it matter whether the while loop iterates 10 times in 100 milliseconds, or 10,000,000?

If you know (or think/hope) that the response is going to be 6 bytes, wait for 6,

Then, of course, you still need to read all 6 of them.

You're right the delay doesn't really matter, I put it just to understand the need to wait.
About the wait of 6 bytes, keep in mind, for later use, the size of the buffer used by Serial library to store the received bytes, 16bytes if I remember well. Typicaly don't expect to be able to do a
Code:
while(Serial.available() < 32);
12  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 15, 2013, 05:54:19 am
Hi,

First thing in your code, in correctRespond function you should poll until the fingerprint reader sent back a response, just in case correctRespond is called too early, before the fingerprint reader had enough time to respond. You can do something like this:
 
Code:
void correctRespond() {
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("Cor");
  
  while(Serial.available() == 0){
    delay(10);
  }

  // read the most recent byte
  respond = Serial.read();

  
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // print the correct respond code of the reader (0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7)
  lcd.print("Cor=");
  lcd.print(respond, HEX);
  
  delay(1000);
}
13  Using Arduino / Project Guidance / Re: USART Half Duplex on a single-wire and external clock on: January 14, 2013, 02:07:05 am
No it's not really SPI. The IO needed is following ISO7816 (used by smartcard), two lines one for the clock one for io.
There is  also a ground as well and vcc connected from the arduino to the module.
14  Using Arduino / Project Guidance / Re: USART Half Duplex on a single-wire and external clock on: January 14, 2013, 01:22:44 am
Hi Rob,

I'm agree the clock as nothing to do with the serial. The idea is to reuse the USART hardware for my IO to have less to manager on software side and be faster. But my other module requires that external clock to know the speed of the IO.
My question is more about how to compute the baudrate on the arduino side to be able to transmit 1bit on a time of 372 clock pulse with a clock at 1MHz but for a clock at 16MHz. Does it mean in case of 16MHz, 1 bit will take 372/16 clock pulse ?

Aurelien
15  Using Arduino / Project Guidance / USART Half Duplex on a single-wire and external clock on: January 13, 2013, 10:00:27 pm
Hi everyone,

I'm working on a project with an Arduino Mega2560, and another module. To communicate with this module I have two wires, one used by Arduino to provided an external clock to the module, this clock indicates the speed of the IO, and the second wire used as IO half duplex. So far I already made a driver to communicate with that module, but my IO is driven in software which brings some limitation about the speed. To improve this I'd like to reuse the serial USART1 as IO channel and keep the external clock as well (mandatory by the other module). For the moment I'm thinking about the feasibility and I think there is 2 key parts.

1) The electronic part: RX and TX will share the same wire so i need to put some pull up resistors in place if i'm not wrong. Is it doable ?
2) The software part: I found that the speed of the USART is computed based on the internal clock of the chip, so in my case 16MHz. But the external clock I want to provide is 1MHz. My question is how can I compute the correct baud rate on Arduino side, if i want to have a clock at 1MHz and a speed at 372 clock pulses for 1 bit transmitted.

Any help is welcome  smiley

PS: for this project, I'm not using the Arduino library, I'm playing directly with the registers.
Pages: [1] 2