the video i posted its a new pulse detector im working on that's the code its running i haven't posted the digram yet but hopefully with direct port manipulation it will work, the way it is just now it is not fast enough to detect the rising wave until it is stretched right out so that tells me the arduino is not fast enough to detect the changes, it might be because im using leds i might order a lcd, or make a timer to switch the leds off once activated, it might be switching the leds to fast
Announcement
Collapse
No announcement yet.
Arduino code learning
Collapse
X
-
haven't played with a "blue pill" myself but i believe there is a pull up resistor you can change to get it to upload sketches via usb. but not sure which sorry... and your right about the direct manipulation its processes alot faster than the digitalWrite() dose but can get a little noisy im told this is more of a problem on the blue pill as the digital and analog power surplys are interconnected...
Comment
-
int Coil = 13; // the number of the Coil pin
// diode erray
int D1 = 2;
int D2 = 3;
int D3 = 4;
int D4 = 5;
int D5 = 6;
int D6 = 7;
int D7 = 8;
int CoilState = LOW;
unsigned long pMicros = 0;
long OnTime = 150; // micro_seconds of on-time
long OffTime = 5000; // micro_seconds of off-time
int analogPin = 0; //Analog pin to read
int Maxval = 0;
int val = 0;
int calibrate = 0;
bool set_calabration = false;
void setup()
{
pinMode(Coil, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
Serial.begin(9600);
}
void loop()
{
/////////////////////////////////////////////////////////////////
// coil switch
unsigned long cMicros = micros();
if((CoilState == HIGH) && (cMicros - pMicros >= OnTime))
{
CoilState = LOW;
pMicros = cMicros;
digitalWrite(Coil, CoilState);
//delayMicroseconds();
val = analogRead(analogPin);
}
else ((CoilState == LOW) && (cMicros - pMicros >= OffTime))
{
CoilState = HIGH;
pMicros = cMicros;
digitalWrite(Coil, CoilState);
//delayMicroseconds(10);
val = analogRead(analogPin);
}
///////////////////////////////////////////////////////////////////
// clabration cycle
if( calibrate < 100 && set_calabration == false )
{
if( val > Maxval)
{
Maxval = val;
}
calibrate+=1;
} else if( set_calabration == false ) set_calabration=true;
///////////////////////////////////////////////////////////////////
// when setting the on/off state use 1023 - val and divide by 7, the val + is to account for coil recovery
if( (val+200) < Maxval )
{
if( val > 100 ) {digitalWrite(D1, HIGH);} else if ( val < 50 ){ digitalWrite(D1, LOW);}
if( val > 200 ) {digitalWrite(D2, HIGH);} else if ( val < 100 ){ digitalWrite(D2, LOW);}
if( val > 300 ) {digitalWrite(D3, HIGH);} else if ( val < 200 ){ digitalWrite(D3, LOW);}
if( val > 400 ) {digitalWrite(D4, HIGH);} else if ( val < 300 ){ digitalWrite(D4, LOW);}
if( val > 500 ) {digitalWrite(D5, HIGH);} else if ( val < 400 ){ digitalWrite(D5, LOW);}
if( val > 600 ) {digitalWrite(D6, HIGH);} else if ( val < 500 ){ digitalWrite(D6, LOW);}
if( val > 800 ) {digitalWrite(D7, HIGH);} else if ( val < 600 ){ digitalWrite(D7, LOW);}
}
}
Comment
-
Originally posted by c_batchelar View Posthaven't played with a "blue pill" myself but i believe there is a pull up resistor you can change to get it to upload sketches via usb. but not sure which sorry... and your right about the direct manipulation its processes alot faster than the digitalWrite() dose but can get a little noisy im told this is more of a problem on the blue pill as the digital and analog power surplys are interconnected...
I tried at least to compile the code with Arduino IDE and later to flash it with Demonstrator GUI. I compiled simple blink code with Arduino IDE without problems at all.
Next i flashed it through uart with Demonstrator GUI and again no problems. But when i switch it ON, it is not blinking...
Comment
-
this is the layout im using
arduino_md.zip
@ivconic not being funny but have you tried using linux im finding windows a pain have to hit upload a few times to get it to flash, i used ubuntu when you load it up use the shell use sudo arduino and no driver or nothing needed, if you use the icon to launch the ide the com ports don't show up
Comment
-
Originally posted by kosacid View Postthis is the layout im using
[ATTACH]38768[/ATTACH]
@ivconic not being funny but have you tried using linux im finding windows a pain have to hit upload a few times to get it to flash, i used ubuntu when you load it up use the shell use sudo arduino and no driver or nothing needed, if you use the icon to launch the ide the com ports don't show up
But i solved this just 15 minutes ago! Hurrrrraaahh!
After 3 days of numerous attempts i solved it! And solution is actually very simple and easy!
NOTHING... and i mean; NOTHING what's written on the Internet on most tagged links is not working at all to me here!
Must be that i had rare "luck" to obtain pretty exotic module, not documented at all and out of any standards (Murphy again...).
And that's why i had so much troubles, because when i read various hints and tips about how is done by somebody else; nothing works the same here.
So i was pretty much confused all the time.
Here is the simplest possible solution;
1) Pull up resistor at PA12 is mistaken obviously, must be 1K5 instead 10K.
2) Use micro USB on the module and connect it to pc.
3) Download this and unzip it to "c:\Program Files (x86)\Arduino\hardware\" ; https://github.com/rogerclarkmelbourne/Arduino_STM32
4) Open Arduino IDE, choose "Board: Maple (Rev 3)"
and that's about all the pain you'll have!
Now... last important thing is; once you click on "upload" and it starts compiling; just as it will start uploading: press button on module once and release it.
IDE will recognize it in a moment and it will flash it successfully in no time!
...
The best part is:
once flashed; code will start running at once. You don't need to replace jumpers at all! Jumper will stay in initial "0" position all the time!
...
So it will work smooth and nice even without enumeration, just as proper Arduino IDE board config is chosen.
So now i can write my own sketches and codes and flash them straight into chip without any painful acrobatics at all!
Sweeeeeet!
Comment
-
What was the problem all the time when i was trying?
All the tagged links on this topic suggests "Generic STM32F103C series" for board configuration.
And i guess it works fine for them, because all those guys probably obtained blue pill from that series.
And my blue pill is obviously some "wild" version, looking exactly the same as their but now working the same.
Why? I can't tell. I examined their photos very carefully and i missed to see any differences.
So today totally desperate i started to try with all the possible board configurations available.
And i got it finally with "Maple (Rev 3)" totally working. Smooth and easy, no troubles at all.
Also previously at those numerous attempts; i was annoyed to death by constant jumping that damn boot mode jumper!
Now is straightforward and easy; just skim press on button in moment of flashing and it is switching it, flash it and return it in working mode.
No need to jump damn jumper anymore.
There is also one more pretty cute move; probably not documented at most tagged links over the net (not sure, i haven't seen it).
To avoid additional acrobatics with separate installation of proper toolchain for STM32; in Arduino IDE just update Arduino Zero board configurations through Board Manager.
Arduino Zero configuration pulls whole the series of complete toolchains including the STM32 too! Sweet!
...
Job is done! STM32 is now under Arduino IDE control.
...
Before this i tried mbed online compiler. Annoying! Online... yiakkk!
...
Haven't tried yet to set up the Eclipse. Intend to.
But from my previous experiences with Eclipse for Android; i know that it is pretty tedious job to reach the point when all is done properly.
But still intend to make it work with Eclipse too.
Arduino IDE is good for simpler tasks and simpler code. Yet it is somewhat limited when it comes to solve more delicate tasks in code.
Comment
-
Originally posted by kosacid View Postthis is the layout im using
[ATTACH]38768[/ATTACH]
@ivconic not being funny but have you tried using linux im finding windows a pain have to hit upload a few times to get it to flash, i used ubuntu when you load it up use the shell use sudo arduino and no driver or nothing needed, if you use the icon to launch the ide the com ports don't show up
Even that it's not the method which will provide you accurate timings... unfortunately.
What you are planning with this? Are you planning further improving... let's say adding a LCD and digital audio output?
Maybe soft buttons and more "jingle&bells"?
Each functionality you add later; will affect your present timings.
Without use of interrupts there is not much that can be done on this subject.
Problem is if you pick a timer for such task; you'll have to trim it and any customizing will affect some of the functions which are dependable on that timer.
I was carefully followed Joop's attempt on "PI ported to Arduino" and he did very basic but neat and precise job there.
Joop realized that you can't do much more of the things you probably wanted; if you stay within Arduino IDE limits.
Unfortunately it is true.
Using his approach i made small step forward by implementing I2C LCD and displaying (by now) only one variable on it.
I can share it here just as an example.
I took Barracuda and just pulled out CD40106 from it. Than attached Arduino on it's place...
Code:#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <LCDBitmap.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); LCDBitmap bitmap(&lcd, 12, 0); #define DIGITAL_OUT PORTB #define TX_PIN_A 5 // 13 #define SAMPLE_PIN_B 4 // 12 #define SAMPLE_PIN_C 3 // 11 unsigned int Sample1Delay = 65295; static int value; static int Mikrosekunde; void setup () { Generator (); InitTimer2 (); InitTimer1 (); TCNT2 = 200; Serial.begin(1200); lcd.begin(16,2); welcome(); } void VoidDelay (unsigned int n) { n += 12; TCNT1 = n; bitSet (TIFR1, TOV1); while (!(TIFR1 & (1<<TOV1))) {;} } void loop () { serial_radno1(); lcd_delay_ispis(); } void InitTimer1 (void) { TCCR1A = 0; TCCR1B = 0; bitClear (TIMSK1, TOIE1); TCNT1 = 0; TCCR1B = 0x01; } void InitTimer2 (void) { TCCR2A = 0; TCCR2B = 0; bitSet (TIMSK2, TOIE2); TCCR2B = 0x05; } void Generator (void) { DDRB = B00111111; } void ReadDelayPot (void) { value = analogRead(A3); Sample1Delay = 65535 - 16 - value; Mikrosekunde = (65535 -Sample1Delay)/16; } ISR (TIMER2_OVF_vect) { TCNT2 = 47; //******************************** MAIN PULSE - TX ****************************** DIGITAL_OUT |= (1<<TX_PIN_A); VoidDelay (63935); DIGITAL_OUT &= ~(1<<TX_PIN_A); //******************************** MAIN DELAY *********************************** VoidDelay (Sample1Delay); //****************************** MAIN DELAY PULSE ******************************* DIGITAL_OUT |= (1<<SAMPLE_PIN_B); VoidDelay (64850); DIGITAL_OUT &= ~(1<<SAMPLE_PIN_B); //******************************** EF DELAY ************************************* VoidDelay (65135); //****************************** EF DELAY PULSE ********************************* DIGITAL_OUT |= (1<<SAMPLE_PIN_C); VoidDelay( 64850); DIGITAL_OUT &= ~(1<<SAMPLE_PIN_C); //******************************** EF+TX DELAY ********************************** VoidDelay( 64850); ReadDelayPot(); } void welcome() { lcd.clear (); lcd.setCursor(2, 0); lcd.print("BARRACUDA"); bitmap.begin(); bitmap.home(); for (byte x=0; x<=4; x++) { bitmap.line(x, BITMAP_H-1, x+BITMAP_H-1, 0, ON, NO_UPDATE); bitmap.line(x, 0, x+BITMAP_H-1, BITMAP_H-1, ON, NO_UPDATE); } bitmap.update(); } void lcd_delay_ispis() { lcd.setCursor(0, 1); lcd.print("D="); lcd.print(Mikrosekunde); lcd.print("uS "); delay(50); } void serial_radno1() { Serial.print("Analogue Value= "); Serial.print(value); Serial.println(); Serial.print("Sample1Delay= "); Serial.print(Sample1Delay); Serial.println(); Serial.print("Mikrosekunde= "); Serial.print(Mikrosekunde); Serial.print("uS"); Serial.println(); }
Comment
-
so with a lcd once it is initialised is there any delays at sending info to it, buttons are easy you can just add a delay() to them just to debounce them but i know what you mean your limited
even with one delay my program fails, at this rate im going to using my raspberry pi lol
Comment
-
Originally posted by ivconic View PostYou can nick a "tic or few" more if you control the whole port instead picking it's pins separately.
Even that it's not the method which will provide you accurate timings... unfortunately.
What you are planning with this? Are you planning further improving... let's say adding a LCD and digital audio output?
Maybe soft buttons and more "jingle&bells"?
Each functionality you add later; will affect your present timings.
Without use of interrupts there is not much that can be done on this subject.
Problem is if you pick a timer for such task; you'll have to trim it and any customizing will affect some of the functions which are dependable on that timer.
I was carefully followed Joop's attempt on "PI ported to Arduino" and he did very basic but neat and precise job there.
Joop realized that you can't do much more of the things you probably wanted; if you stay within Arduino IDE limits.
Unfortunately it is true.
Using his approach i made small step forward by implementing I2C LCD and displaying (by now) only one variable on it.
I can share it here just as an example.
I took Barracuda and just pulled out CD40106 from it. Than attached Arduino on it's place...
[ATTACH]38775[/ATTACH]
Code:#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <LCDBitmap.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); LCDBitmap bitmap(&lcd, 12, 0); #define DIGITAL_OUT PORTB #define TX_PIN_A 5 // 13 #define SAMPLE_PIN_B 4 // 12 #define SAMPLE_PIN_C 3 // 11 unsigned int Sample1Delay = 65295; static int value; static int Mikrosekunde; void setup () { Generator (); InitTimer2 (); InitTimer1 (); TCNT2 = 200; Serial.begin(1200); lcd.begin(16,2); welcome(); } void VoidDelay (unsigned int n) { n += 12; TCNT1 = n; bitSet (TIFR1, TOV1); while (!(TIFR1 & (1<<TOV1))) {;} } void loop () { serial_radno1(); lcd_delay_ispis(); } void InitTimer1 (void) { TCCR1A = 0; TCCR1B = 0; bitClear (TIMSK1, TOIE1); TCNT1 = 0; TCCR1B = 0x01; } void InitTimer2 (void) { TCCR2A = 0; TCCR2B = 0; bitSet (TIMSK2, TOIE2); TCCR2B = 0x05; } void Generator (void) { DDRB = B00111111; } void ReadDelayPot (void) { value = analogRead(A3); Sample1Delay = 65535 - 16 - value; Mikrosekunde = (65535 -Sample1Delay)/16; } ISR (TIMER2_OVF_vect) { TCNT2 = 47; //******************************** MAIN PULSE - TX ****************************** DIGITAL_OUT |= (1<<TX_PIN_A); VoidDelay (63935); DIGITAL_OUT &= ~(1<<TX_PIN_A); //******************************** MAIN DELAY *********************************** VoidDelay (Sample1Delay); //****************************** MAIN DELAY PULSE ******************************* DIGITAL_OUT |= (1<<SAMPLE_PIN_B); VoidDelay (64850); DIGITAL_OUT &= ~(1<<SAMPLE_PIN_B); //******************************** EF DELAY ************************************* VoidDelay (65135); //****************************** EF DELAY PULSE ********************************* DIGITAL_OUT |= (1<<SAMPLE_PIN_C); VoidDelay( 64850); DIGITAL_OUT &= ~(1<<SAMPLE_PIN_C); //******************************** EF+TX DELAY ********************************** VoidDelay( 64850); ReadDelayPot(); } void welcome() { lcd.clear (); lcd.setCursor(2, 0); lcd.print("BARRACUDA"); bitmap.begin(); bitmap.home(); for (byte x=0; x<=4; x++) { bitmap.line(x, BITMAP_H-1, x+BITMAP_H-1, 0, ON, NO_UPDATE); bitmap.line(x, 0, x+BITMAP_H-1, BITMAP_H-1, ON, NO_UPDATE); } bitmap.update(); } void lcd_delay_ispis() { lcd.setCursor(0, 1); lcd.print("D="); lcd.print(Mikrosekunde); lcd.print("uS "); delay(50); } void serial_radno1() { Serial.print("Analogue Value= "); Serial.print(value); Serial.println(); Serial.print("Sample1Delay= "); Serial.print(Sample1Delay); Serial.println(); Serial.print("Mikrosekunde= "); Serial.print(Mikrosekunde); Serial.print("uS"); Serial.println(); }
Ivconic what are the polarities of the waveform pulses that you are applying to the gates of Q3 and Q4 ? is it just battery ground and plus 5 volts
Comment
Comment