arduino controled oscilator

Hi guys,

Recently I got this code from a friend which is unfortunately unavailable right now.

When button is pressed two halfbridges are supposed to change directions with increasing frequency of direction change until button is pressed again and than that frequency remains same. Potentiometar is there to regulate that incriese of frequency. For some reason one output is always on other one gets one when I press the button.

This is mentioned double halfbridge board: http://www.ebay.de/itm/272620735999?_trksid=p2060353.m2749.l2649&var=571741857121&ssPageName=STRK%3AMEBIDX%3AIT

It is working, I checked button and potentiometer too,

Please help

options.h (418 Bytes)

oscillator_ctrl.ino (1.6 KB)

One thing I notice is passing large values to delayMicroseconds - this doesn't work, stick to a few thousand
at most for the argument to delayMicroseconds.

Also lack of long constants being declared long (ie 100000L rather than 100000). If you don't declare
at least one of the arguments to an operator as long, then it is assumed int (which is 16 bit on the Uno).

Hi Mark,
Honestly, I d not have a clue what you talk about, this code is much above my uderstanding of coding

replace 100000 by 100000L, replace 50000 by 50000L, replace delayMicroseconds by my_delay_micros
and add its declaration:

void my_delay_micros (unsigned long delay)
{
  delay (delay / 1000) ;
  delayMicroseconds (delay % 1000) ;
}

OK,
I have tried,
But what ever I do can not compile cause compiler gives me trouble with line delay (delay / 1000) ;

What am I doing wrong?

#include “options.h”

float ratio = CHANGE_FREQUENCY_MAX_SEC / 1023.0;

void setup() {
pinMode(PIN_PWM_COIL_1, OUTPUT);
pinMode(PIN_PWM_COIL_2, OUTPUT);
pinMode(PIN_DIR_MOTOR, OUTPUT);
pinMode(PIN_START_STOP, INPUT_PULLUP);

digitalWrite(PIN_DIR_MOTOR, HIGH);
digitalWrite(PIN_PWM_COIL_1, HIGH);
digitalWrite(PIN_PWM_COIL_2, LOW);
}

void loop() {
float voltage = 0;
long steps;
long pwm_half_period;
unsigned long change_freq_time = 0;
unsigned long value_steps = 0;
unsigned int stop_freq = 0;

if (digitalRead(PIN_START_STOP)) {
return;
}
void my_delay_micros (unsigned long delay)

delay (delay / 1000) ;
delayMicroseconds (delay % 1000) ;
}
steps = (FREQUENCY_STOP_HZ - FREQUENCY_START_HZ) / FREQUENCY_STEP_HZ;

if (FREQUENCY_STOP_HZ < FREQUENCY_START_HZ ) {
return;
}

// If max number is reached we do nothing error in seetings
if (steps > FREQUENCY_MAX_CHANGES) {
return;
}

value_steps = analogRead(PIN_POTENTIONMETER_IN) * ratio + CHANGE_FREQUENCY_MIN_SEC;
value_steps *= 1000000L;

pwm_half_period = 500000L / FREQUENCY_START_HZ ;

change_freq_time = 0;

while(!digitalRead(PIN_START_STOP)) {

digitalWrite(PIN_PWM_COIL_1, LOW);
digitalWrite(PIN_PWM_COIL_2, HIGH);
my_delay_micros(pwm_half_period);

digitalWrite(PIN_PWM_COIL_1, HIGH);
digitalWrite(PIN_PWM_COIL_2, LOW);
my_delay_micros(pwm_half_period);

change_freq_time++;

if(value_steps == change_freq_time) {
change_freq_time = 0;
pwm_half_period += 500000L / FREQUENCY_STEP_HZ;
stop_freq = 1000000L / FREQUENCY_STOP_HZ;

if(FREQUENCY_STOP_HZ == (2 * pwm_half_period)) {
break;
}
}
}
}

Oh sorry, a name clash, call the argument del or something instead.

same thing again
can you please write some example?