I have a question here. If I want to use portd for pin2-7 and portB for pin8-9 (LSB), I want to output that for same time. It’s because I used protd for output(pin0-7) at the beginning. Now, pin0 and pin1 are needed to be communication. So, I have this problem. Hope someone to help me. thxx
You cannot do that in a single instruction at once. But the instructions needed are short, so it doesn’t take very much time. Each port will have to be set individually. But you can limit which pins of each port are changed by using bitmasks:
Valen:
You cannot do that in a single instruction at once. But the instructions needed are short, so it doesn’t take very much time. Each port will have to be set individually. But you can limit which pins of each port are changed by using bitmasks:
Thanks. But, I am not really understand because this is my first time to use arduino.
In my program, I need to produce sine waveform.
My program shows here partly:
void setup(){
DDRD=B11111111;
Timer1.initialize(10);
Timer1.attachInterrupt(timer)
}
void loop(){}
void timer()
{
PORTD=sin[acc>>8]
acc=acc+wordd
}
How can I do?
Show the full program. I don’t know what acc, wordd or what sin is. Probably a lookup table, but I can’t suggest anything if I don’t know how it is defined.
degerous:
Thanks. But, I am not really understand because this is my first time to use arduino.
In my program, I need to produce sine waveform.
No problem. Wait with your sine waveform code first. Play around with the code given in those links. Try yourself in a small program what those commands do. Assign a number to a variable. Print that value for reference. Apply a bitmask to that variable using bitwise-AND and print the resulting number. Write both numbers received out in binary form (hint: Windows Calculator in Programmer mode) and compare what happened to it.
Make sure you read the lower part of the first link. It contains the information about how to set specific bits of a port. I understand that english is not your primary language. And that it may be hard. But it is the solution to your problem.
Valen:
Show the full program. I don’t know what acc, wordd or what sin is. Probably a lookup table, but I can’t suggest anything if I don’t know how it is defined.
DDS sig. gen 1k sinwave. Thanks
#include <TimerOne.h>
unsigned int acc=0;
unsigned int wordd=655;
int sine[256]={127, 130, 133, 136, 139, 143, 146, 149, 152, 155,
158, 161, 164, 167, 170, 173, 176, 179, 181, 184,
187, 190, 193, 195, 198, 200, 203, 205, 208, 210,
213, 215, 217, 219, 221, 223, 225, 227, 229, 231,
233, 235, 236, 238, 239, 241, 242, 243, 245, 246,
247, 248, 249, 250, 250, 251, 252, 252, 253, 253,
253, 254, 254, 254, 254, 254, 254, 254, 253, 253,
252, 252, 251, 251, 250, 249, 248, 247, 246, 245,
244, 243, 241, 240, 239, 237, 235, 234, 232, 230,
228, 226, 224, 222, 220, 218, 216, 214, 211, 209,
207, 204, 202, 199, 197, 194, 191, 188, 186, 183,
180, 177, 174, 171, 168, 166, 163, 160, 156, 153,
150, 147, 144, 141, 138, 135, 132, 129, 125, 122,
119, 116, 113, 110, 107, 104, 101, 98, 95, 92,
89, 86, 83, 80, 77, 74, 71, 68, 66, 63,
60, 58, 55, 52, 50, 47, 45, 43, 40, 38,
36, 34, 32, 30, 28, 26, 24, 22, 20, 19,
17, 15, 14, 13, 11, 10, 9, 8, 7, 6,
5, 4, 3, 3, 2, 2, 1, 1, 0, 0,
0, 0, 0, 0, 0, 1, 1, 1, 2, 2,
3, 4, 4, 5, 6, 7, 8, 9, 11, 12,
13, 15, 16, 18, 19, 21, 23, 25, 27, 29,
31, 33, 35, 37, 39, 41, 44, 46, 49, 51,
54, 56, 59, 61, 64, 67, 70, 72, 75, 78,
81, 84, 87, 90, 93, 96, 99, 102, 105, 108,
111, 114, 118, 121, 124, 127
};
int result;
void setup() {
DDRD=B11111111;
Timer1.initialize(10);
Timer1.attachInterrupt(timer);
}
void loop(){}
void timer()
{
PORTD=sine[acc>>8];
acc=acc+wordd;
}