Arduino
RLC пишет: Всем приветы.
Помогите организовать шим на ардуино, где можно менять частоту и скважность главного сигнала.
Управление 4-мя кнопками, (больше/меньше частота) и (больше/меньше скважность)
Главный сигнал 0.1 - 3 герца, сигнал заполнения 50 герц.
Вложение не найдено
Ограничение по частоте будет для Теслы не пойдет. Можно попробовать на st32... Но там тоже ограничение и очень помех боятся. Если только для инвертора, но говорю, помех боятся.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Если делать нормальный аппаратный ШИМ с регулировкой скважности от 1/255 до 255, то надо его делать на таймере 0. Максимальная частота при тактовой 8 МГц получится 8000/256 = 31 КГц при 16 Мгц - 62 КГц. Если делать более "точный" ШИМ на таймере1, то частота будет ещё меньше
Я конечно скачаю код и посмотрю что там и как, но что-то мне с трудом верится. Так бы лабораторные генераторы на нем бы делали, а вот и нет их.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
RLC пишет: Мне не нужны никакие килогерцы-мегагерцы. Сигнал 0-3 герца с 50 герцевым заполнением.
Это потянет что угодно, даже ламповый калькулятор , неясен алгоритм.
Шим без заполнения с регулировкой частоты сделать - раз плюнуть.
А с заполнением засада. Для меня...
Два таймера, один частоту считает, другой заполнение. В инете должно это быть
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Или вот это
Если не подходит то вот
/*
Copyright release under LGPL (GNU General Public License), as well as a non-commercial use.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
For legal advice on subjects of Copyright, Trademarks and Patents please consult
legal counsel at myattorneyusa.com
*/
#include <stdio.h>
#include <PWM.h>
#include <LiquidCrystal.h>
#define buttonPin A0
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// some variables to use in our program
// Frequency
long toFrequency = 1000; //Start Fq
long currentFrequency; //Current Fq
long maxFrequency = 2000000; //Max Fq
long minFrequency = 1; //Min Fq
int fstep = 10;
// Duty Cycle
int toDC = 520; //Start DC
int DC; //Current DC
int maxDC = 1000; //Max DC
int minDC = 10; //Min DC
// Menu items
int incrementNumber = 1;
int maxprogramnumber = 7; // dont forget to increase the menu numbers here!!
int programnumber = 1;
// Function PWM Library
int32_t ddspin_44 = toFrequency; //frequency (in Hz)
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define LOCKLED 12 //LED - indicator when the frequency is locked, pin D1 *Changed from D1 to D12 just to be next to the new scan LED pin - firepinto 10/25/14
#define SCANLED 11 //LED - indicator when scanning, pin D0 *Changed from D0 to D11 because of serial uploading issues from the IDE - firepinto 10/25/14
#define PEAKLED 13 //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define PICKUP A1 //pickup coil is connected to pin A1 via voltage divider and a zener diode
int freq = 0; //Variable for Locked frequency
int freqplus = 0; //Low end of freqency fine tune scale - firepinto 10/27/14
int freqminus = 0; //High end of freqency fine tune scale - firepinto 10/27/14
int freqrange = 0; //Variable for FRANGE POT
int scale = 0; //Scale variable in Hz for manual frequency adjust buttons
int adjfreq = freq; //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
void setup()
{
Serial.begin(9600);
InitTimersSafe();
SetPinFrequencySafe(44, toFrequency);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(":DDS");
lcd.setCursor(0, 1);
lcd.print(" Square-Wave ");
delay(3000);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
lcd.clear();
}
void loop()
{
lcd.clear();
lcd.print(" SCANNING... ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(11,1);
lcd.print("Hz");
//start scan scanUP() to oscillate the circuit
for (toFrequency = minFrequency; toFrequency <= maxFrequency; toFrequency = toFrequency + fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP); //then read the voltage
if (volt > 818) //If pick-up coil voltage is greater than 4 volts
{
digitalWrite(PEAKLED, HIGH); //turn on peak LED
}
else
{
digitalWrite(PEAKLED, LOW); //turn off peak LED
}
if (vmax < volt) //if there is a resonant point voltage should have the highest value on this frequency
{
vmax = volt; //store as the best voltage
freq = toFrequency; //remember that frequency
intval = intval++; //times found a nice frequency interval, is showing during scan on the left of the lcd
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
lcd_key = read_LCD_buttons();
//start scanDown to oscillate the circuit
for (toFrequency = maxFrequency; toFrequency >= minFrequency; toFrequency = toFrequency - fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP);
if (volt > 818) // *Added by firepinto 10/26/14
{
digitalWrite(PEAKLED, HIGH);
}
else
{
digitalWrite(PEAKLED, LOW);
}
if (vmax < volt)
{
vmax = volt;
freq = toFrequency;
adjfreq = freq;
intval = intval++ ;
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
if(toDC >= maxDC){(toDC = maxDC);}
if(toDC <= minDC){(toDC = minDC);}
DC=toDC;
pwmWrite(44, toDC / 4);
}
int read_LCD_buttons(){
switch(incrementNumber){
case 0:
lcd.setCursor(0,0);
lcd.print("x 1hz");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("x 10hz");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("x 1khz");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("x 10khz");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("x 100khz");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("x 1Mhz");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("Duty C");
break;
default:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
}
lcd.setCursor(0, 1);
lcd.print("Freq :"); //Print to lcd
lcd.setCursor(8, 1);
lcd.print(currentFrequency);
lcd.setCursor(9, 0);
lcd.print("DC :"); //Print to lcd
lcd.setCursor(12, 0);
lcd.print(toDC);
//Serial.println(incrementNumber); // temporary for debuggin delete me
while((analogRead(buttonPin))>=1000){} // do nothing while no buttons pressed to chill out
delay(5);
if(analogRead(buttonPin)>=100 && analogRead(buttonPin)<=200){ // we have pushed up
upFrequency();
delay(300);
}
if(analogRead(buttonPin)>=200 && analogRead(buttonPin)<=350){ // we have pushed down
downFrequency();
delay(300);
}
if((analogRead(buttonPin))<=50){ //pushed right
incrementNumber++;
if(incrementNumber > 6){incrementNumber = 0;}
delay(300);
}
if(analogRead(buttonPin)>=350 && analogRead(buttonPin)<=550){ //pushed left
incrementNumber--;
if(incrementNumber < 0){incrementNumber = 6;}
delay(300);
}
if(analogRead(buttonPin)>=550 && analogRead(buttonPin)<=750)
{ // we have pushed select
incrementNumber = 7;
delay(800);
}
//if(incrementNumber > 6){incrementNumber = 0;}
//if(incrementNumber < 0){incrementNumber = 6;}
delay(100);
lcd.clear();
}
void upFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency + 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency + 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency + 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency + 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency + 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency + 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency + 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC + 10);
break;
default:
toFrequency = (toFrequency + 10);
break;
}
}
void downFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency - 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency - 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency - 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency - 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency - 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency - 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency - 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC - 10);
break;
default:
toFrequency = (toFrequency - 10);
break;
}
}
Данная Программа ищет резонансную частоту катушки, после чего раскачивает катушку найденной резонансной частотой заполняя ее пачками импульсов. Предусмотренна ручная подстройка скважности, частоты и фазы. В этой проге не хватает модуля автоподстройки для полноценной замены 4046, ну и Arduino 16мГц слабоват.
Возвращаясь к вопроу, это немного больше чем тебе нужно, но все лишнее можно легко удалить. Если бы ты объяснил для чего тебе это нужно, было бы проще. Какая разрешающяя способность необходимой частоты? 1.00 или 0.001 Гц?
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Читаю и думаю ,а что это даёт ,ну будет заряд конденсатора метаться за время паузы ,правильно понял?...ну даладно ,и думаю ,а ведь это я уже видел ,долго вспоминал , но вспомнил и даже нашёл , если не то ,то извини ,за лишний мусорRLC пишет: Всем приветы.
Помогите организовать шим на ардуино, где можно менять частоту и скважность главного сигнала.
Управление 4-мя кнопками, (больше/меньше частота) и (больше/меньше скважность)
Главный сигнал 0.1 - 3 герца, сигнал заполнения 50 герц. Скважность привязана к частоте.
Вложение не найдено
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Для какой ардуины Ваш скеч? Для UNO не компилируется.Abadiya пишет: Посмотри на это
Или вот это
Если не подходит то вотВНИМАНИЕ: Спойлер! [ Нажмите, чтобы развернуть ] [ Нажмите, чтобы скрыть ]
#include <stdio.h>
#include <PWM.h>
#include <LiquidCrystal.h>
#define buttonPin A0
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// some variables to use in our program
// Frequency
long toFrequency = 1000; //Start Fq
long currentFrequency; //Current Fq
long maxFrequency = 2000000; //Max Fq
long minFrequency = 1; //Min Fq
int fstep = 10;
// Duty Cycle
int toDC = 520; //Start DC
int DC; //Current DC
int maxDC = 1000; //Max DC
int minDC = 10; //Min DC
// Menu items
int incrementNumber = 1;
int maxprogramnumber = 7; // dont forget to increase the menu numbers here!!
int programnumber = 1;
// Function PWM Library
int32_t ddspin_44 = toFrequency; //frequency (in Hz)
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define LOCKLED 12 //LED - indicator when the frequency is locked, pin D1 *Changed from D1 to D12 just to be next to the new scan LED pin - firepinto 10/25/14
#define SCANLED 11 //LED - indicator when scanning, pin D0 *Changed from D0 to D11 because of serial uploading issues from the IDE - firepinto 10/25/14
#define PEAKLED 13 //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define PICKUP A8 //pickup coil is connected to pin A8 via voltage divider and a zener diode
int freq = 0; //Variable for Locked frequency
int freqplus = 0; //Low end of freqency fine tune scale - firepinto 10/27/14
int freqminus = 0; //High end of freqency fine tune scale - firepinto 10/27/14
int freqrange = 0; //Variable for FRANGE POT
int scale = 0; //Scale variable in Hz for manual frequency adjust buttons
int adjfreq = freq; //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
void setup()
{
Serial.begin(9600);
InitTimersSafe();
SetPinFrequencySafe(44, toFrequency);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(":DDS");
lcd.setCursor(0, 1);
lcd.print(" Square-Wave ");
delay(3000);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
lcd.clear();
}
void loop()
{
lcd.clear();
lcd.print(" SCANNING... ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(11,1);
lcd.print("Hz");
//start scan scanUP() to oscillate the circuit
for (toFrequency = minFrequency; toFrequency <= maxFrequency; toFrequency = toFrequency + fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP); //then read the voltage
if (volt > 818) //If pick-up coil voltage is greater than 4 volts
{
digitalWrite(PEAKLED, HIGH); //turn on peak LED
}
else
{
digitalWrite(PEAKLED, LOW); //turn off peak LED
}
if (vmax < volt) //if there is a resonant point voltage should have the highest value on this frequency
{
vmax = volt; //store as the best voltage
freq = toFrequency; //remember that frequency
intval = intval++; //times found a nice frequency interval, is showing during scan on the left of the lcd
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
lcd_key = read_LCD_buttons();
//start scanDown to oscillate the circuit
for (toFrequency = maxFrequency; toFrequency >= minFrequency; toFrequency = toFrequency - fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP);
if (volt > 818) // *Added by firepinto 10/26/14
{
digitalWrite(PEAKLED, HIGH);
}
else
{
digitalWrite(PEAKLED, LOW);
}
if (vmax < volt)
{
vmax = volt;
freq = toFrequency;
adjfreq = freq;
intval = intval++ ;
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
if(toDC >= maxDC){(toDC = maxDC);}
if(toDC <= minDC){(toDC = minDC);}
DC=toDC;
pwmWrite(44, toDC / 4);
}
int read_LCD_buttons(){
switch(incrementNumber){
case 0:
lcd.setCursor(0,0);
lcd.print("x 1hz");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("x 10hz");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("x 1khz");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("x 10khz");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("x 100khz");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("x 1Mhz");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("Duty C");
break;
default:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
}
lcd.setCursor(0, 1);
lcd.print("Freq :"); //Print to lcd
lcd.setCursor(8, 1);
lcd.print(currentFrequency);
lcd.setCursor(9, 0);
lcd.print("DC :"); //Print to lcd
lcd.setCursor(12, 0);
lcd.print(toDC);
//Serial.println(incrementNumber); // temporary for debuggin delete me
while((analogRead(buttonPin))>=1000){} // do nothing while no buttons pressed to chill out
delay(5);
if(analogRead(buttonPin)>=100 && analogRead(buttonPin)<=200){ // we have pushed up
upFrequency();
delay(300);
}
if(analogRead(buttonPin)>=200 && analogRead(buttonPin)<=350){ // we have pushed down
downFrequency();
delay(300);
}
if((analogRead(buttonPin))<=50){ //pushed right
incrementNumber++;
if(incrementNumber > 6){incrementNumber = 0;}
delay(300);
}
if(analogRead(buttonPin)>=350 && analogRead(buttonPin)<=550){ //pushed left
incrementNumber--;
if(incrementNumber < 0){incrementNumber = 6;}
delay(300);
}
if(analogRead(buttonPin)>=550 && analogRead(buttonPin)<=750)
{ // we have pushed select
incrementNumber = 7;
delay(800);
}
//if(incrementNumber > 6){incrementNumber = 0;}
//if(incrementNumber < 0){incrementNumber = 6;}
delay(100);
lcd.clear();
}
void upFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency + 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency + 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency + 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency + 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency + 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency + 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency + 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC + 10);
break;
default:
toFrequency = (toFrequency + 10);
break;
}
}
void downFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency - 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency - 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency - 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency - 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency - 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency - 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency - 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC - 10);
break;
default:
toFrequency = (toFrequency - 10);
break;
}
}
Данная Программа ищет резонансную частоту катушки, после чего раскачивает катушку найденной резонансной частотой заполняя ее пачками импульсов. Предусмотренна ручная подстройка скважности, частоты и фазы. В этой проге не хватает модуля автоподстройки для полноценной замены 4046, ну и Arduino 16мГц слабоват.
Возвращаясь к вопроу, это немного больше чем тебе нужно, но все лишнее можно легко удалить. Если бы ты объяснил для чего тебе это нужно, было бы проще. Какая разрешающяя способность необходимой частоты? 1.00 или 0.001 Гц?
D:\UNO_gen_resonance\UNO_gen_resonance.ino:2:17: fatal error: PWM.h: No such file or directory
#include <PWM.h>
^
compilation terminated.
exit status 1
Ошибка компиляции.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Подключите arduino-pwm-frequency-library , должно заработать.Mining пишет:
Для какой ардуины Ваш скеч? Для UNO не компилируется.Abadiya пишет: Посмотри на это
Или вот это
Если не подходит то вотВНИМАНИЕ: Спойлер! [ Нажмите, чтобы развернуть ] [ Нажмите, чтобы скрыть ]
#include <stdio.h>
#include <PWM.h>
#include <LiquidCrystal.h>
#define buttonPin A0
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// some variables to use in our program
// Frequency
long toFrequency = 1000; //Start Fq
long currentFrequency; //Current Fq
long maxFrequency = 2000000; //Max Fq
long minFrequency = 1; //Min Fq
int fstep = 10;
// Duty Cycle
int toDC = 520; //Start DC
int DC; //Current DC
int maxDC = 1000; //Max DC
int minDC = 10; //Min DC
// Menu items
int incrementNumber = 1;
int maxprogramnumber = 7; // dont forget to increase the menu numbers here!!
int programnumber = 1;
// Function PWM Library
int32_t ddspin_44 = toFrequency; //frequency (in Hz)
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define LOCKLED 12 //LED - indicator when the frequency is locked, pin D1 *Changed from D1 to D12 just to be next to the new scan LED pin - firepinto 10/25/14
#define SCANLED 11 //LED - indicator when scanning, pin D0 *Changed from D0 to D11 because of serial uploading issues from the IDE - firepinto 10/25/14
#define PEAKLED 13 //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define PICKUP A8 //pickup coil is connected to pin A8 via voltage divider and a zener diode
int freq = 0; //Variable for Locked frequency
int freqplus = 0; //Low end of freqency fine tune scale - firepinto 10/27/14
int freqminus = 0; //High end of freqency fine tune scale - firepinto 10/27/14
int freqrange = 0; //Variable for FRANGE POT
int scale = 0; //Scale variable in Hz for manual frequency adjust buttons
int adjfreq = freq; //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
void setup()
{
Serial.begin(9600);
InitTimersSafe();
SetPinFrequencySafe(44, toFrequency);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(":DDS");
lcd.setCursor(0, 1);
lcd.print(" Square-Wave ");
delay(3000);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
lcd.clear();
}
void loop()
{
lcd.clear();
lcd.print(" SCANNING... ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(11,1);
lcd.print("Hz");
//start scan scanUP() to oscillate the circuit
for (toFrequency = minFrequency; toFrequency <= maxFrequency; toFrequency = toFrequency + fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP); //then read the voltage
if (volt > 818) //If pick-up coil voltage is greater than 4 volts
{
digitalWrite(PEAKLED, HIGH); //turn on peak LED
}
else
{
digitalWrite(PEAKLED, LOW); //turn off peak LED
}
if (vmax < volt) //if there is a resonant point voltage should have the highest value on this frequency
{
vmax = volt; //store as the best voltage
freq = toFrequency; //remember that frequency
intval = intval++; //times found a nice frequency interval, is showing during scan on the left of the lcd
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
lcd_key = read_LCD_buttons();
//start scanDown to oscillate the circuit
for (toFrequency = maxFrequency; toFrequency >= minFrequency; toFrequency = toFrequency - fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP);
if (volt > 818) // *Added by firepinto 10/26/14
{
digitalWrite(PEAKLED, HIGH);
}
else
{
digitalWrite(PEAKLED, LOW);
}
if (vmax < volt)
{
vmax = volt;
freq = toFrequency;
adjfreq = freq;
intval = intval++ ;
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
if(toDC >= maxDC){(toDC = maxDC);}
if(toDC <= minDC){(toDC = minDC);}
DC=toDC;
pwmWrite(44, toDC / 4);
}
int read_LCD_buttons(){
switch(incrementNumber){
case 0:
lcd.setCursor(0,0);
lcd.print("x 1hz");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("x 10hz");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("x 1khz");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("x 10khz");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("x 100khz");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("x 1Mhz");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("Duty C");
break;
default:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
}
lcd.setCursor(0, 1);
lcd.print("Freq :"); //Print to lcd
lcd.setCursor(8, 1);
lcd.print(currentFrequency);
lcd.setCursor(9, 0);
lcd.print("DC :"); //Print to lcd
lcd.setCursor(12, 0);
lcd.print(toDC);
//Serial.println(incrementNumber); // temporary for debuggin delete me
while((analogRead(buttonPin))>=1000){} // do nothing while no buttons pressed to chill out
delay(5);
if(analogRead(buttonPin)>=100 && analogRead(buttonPin)<=200){ // we have pushed up
upFrequency();
delay(300);
}
if(analogRead(buttonPin)>=200 && analogRead(buttonPin)<=350){ // we have pushed down
downFrequency();
delay(300);
}
if((analogRead(buttonPin))<=50){ //pushed right
incrementNumber++;
if(incrementNumber > 6){incrementNumber = 0;}
delay(300);
}
if(analogRead(buttonPin)>=350 && analogRead(buttonPin)<=550){ //pushed left
incrementNumber--;
if(incrementNumber < 0){incrementNumber = 6;}
delay(300);
}
if(analogRead(buttonPin)>=550 && analogRead(buttonPin)<=750)
{ // we have pushed select
incrementNumber = 7;
delay(800);
}
//if(incrementNumber > 6){incrementNumber = 0;}
//if(incrementNumber < 0){incrementNumber = 6;}
delay(100);
lcd.clear();
}
void upFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency + 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency + 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency + 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency + 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency + 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency + 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency + 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC + 10);
break;
default:
toFrequency = (toFrequency + 10);
break;
}
}
void downFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency - 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency - 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency - 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency - 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency - 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency - 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency - 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC - 10);
break;
default:
toFrequency = (toFrequency - 10);
break;
}
}
Данная Программа ищет резонансную частоту катушки, после чего раскачивает катушку найденной резонансной частотой заполняя ее пачками импульсов. Предусмотренна ручная подстройка скважности, частоты и фазы. В этой проге не хватает модуля автоподстройки для полноценной замены 4046, ну и Arduino 16мГц слабоват.
Возвращаясь к вопроу, это немного больше чем тебе нужно, но все лишнее можно легко удалить. Если бы ты объяснил для чего тебе это нужно, было бы проще. Какая разрешающяя способность необходимой частоты? 1.00 или 0.001 Гц?
D:\UNO_gen_resonance\UNO_gen_resonance.ino:2:17: fatal error: PWM.h: No such file or directory
#include <PWM.h>
^
compilation terminated.
exit status 1
Ошибка компиляции.
/Сократ/
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
У меня, рабoтает практически на любом Arduino - UNO, Mega, Mini и т.д.Mining пишет:
Для какой ардуины Ваш скеч? Для UNO не компилируется.Abadiya пишет: Посмотри на это
Или вот это
Если не подходит то вотВНИМАНИЕ: Спойлер! [ Нажмите, чтобы развернуть ] [ Нажмите, чтобы скрыть ]
#include <stdio.h>
#include <PWM.h>
#include <LiquidCrystal.h>
#define buttonPin A0
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// some variables to use in our program
// Frequency
long toFrequency = 1000; //Start Fq
long currentFrequency; //Current Fq
long maxFrequency = 2000000; //Max Fq
long minFrequency = 1; //Min Fq
int fstep = 10;
// Duty Cycle
int toDC = 520; //Start DC
int DC; //Current DC
int maxDC = 1000; //Max DC
int minDC = 10; //Min DC
// Menu items
int incrementNumber = 1;
int maxprogramnumber = 7; // dont forget to increase the menu numbers here!!
int programnumber = 1;
// Function PWM Library
int32_t ddspin_44 = toFrequency; //frequency (in Hz)
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define LOCKLED 12 //LED - indicator when the frequency is locked, pin D1 *Changed from D1 to D12 just to be next to the new scan LED pin - firepinto 10/25/14
#define SCANLED 11 //LED - indicator when scanning, pin D0 *Changed from D0 to D11 because of serial uploading issues from the IDE - firepinto 10/25/14
#define PEAKLED 13 //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define PICKUP A8 //pickup coil is connected to pin A8 via voltage divider and a zener diode
int freq = 0; //Variable for Locked frequency
int freqplus = 0; //Low end of freqency fine tune scale - firepinto 10/27/14
int freqminus = 0; //High end of freqency fine tune scale - firepinto 10/27/14
int freqrange = 0; //Variable for FRANGE POT
int scale = 0; //Scale variable in Hz for manual frequency adjust buttons
int adjfreq = freq; //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
void setup()
{
Serial.begin(9600);
InitTimersSafe();
SetPinFrequencySafe(44, toFrequency);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(":DDS");
lcd.setCursor(0, 1);
lcd.print(" Square-Wave ");
delay(3000);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
lcd.clear();
}
void loop()
{
lcd.clear();
lcd.print(" SCANNING... ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(11,1);
lcd.print("Hz");
//start scan scanUP() to oscillate the circuit
for (toFrequency = minFrequency; toFrequency <= maxFrequency; toFrequency = toFrequency + fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP); //then read the voltage
if (volt > 818) //If pick-up coil voltage is greater than 4 volts
{
digitalWrite(PEAKLED, HIGH); //turn on peak LED
}
else
{
digitalWrite(PEAKLED, LOW); //turn off peak LED
}
if (vmax < volt) //if there is a resonant point voltage should have the highest value on this frequency
{
vmax = volt; //store as the best voltage
freq = toFrequency; //remember that frequency
intval = intval++; //times found a nice frequency interval, is showing during scan on the left of the lcd
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
lcd_key = read_LCD_buttons();
//start scanDown to oscillate the circuit
for (toFrequency = maxFrequency; toFrequency >= minFrequency; toFrequency = toFrequency - fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP);
if (volt > 818) // *Added by firepinto 10/26/14
{
digitalWrite(PEAKLED, HIGH);
}
else
{
digitalWrite(PEAKLED, LOW);
}
if (vmax < volt)
{
vmax = volt;
freq = toFrequency;
adjfreq = freq;
intval = intval++ ;
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
if(toDC >= maxDC){(toDC = maxDC);}
if(toDC <= minDC){(toDC = minDC);}
DC=toDC;
pwmWrite(44, toDC / 4);
}
int read_LCD_buttons(){
switch(incrementNumber){
case 0:
lcd.setCursor(0,0);
lcd.print("x 1hz");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("x 10hz");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("x 1khz");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("x 10khz");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("x 100khz");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("x 1Mhz");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("Duty C");
break;
default:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
}
lcd.setCursor(0, 1);
lcd.print("Freq :"); //Print to lcd
lcd.setCursor(8, 1);
lcd.print(currentFrequency);
lcd.setCursor(9, 0);
lcd.print("DC :"); //Print to lcd
lcd.setCursor(12, 0);
lcd.print(toDC);
//Serial.println(incrementNumber); // temporary for debuggin delete me
while((analogRead(buttonPin))>=1000){} // do nothing while no buttons pressed to chill out
delay(5);
if(analogRead(buttonPin)>=100 && analogRead(buttonPin)<=200){ // we have pushed up
upFrequency();
delay(300);
}
if(analogRead(buttonPin)>=200 && analogRead(buttonPin)<=350){ // we have pushed down
downFrequency();
delay(300);
}
if((analogRead(buttonPin))<=50){ //pushed right
incrementNumber++;
if(incrementNumber > 6){incrementNumber = 0;}
delay(300);
}
if(analogRead(buttonPin)>=350 && analogRead(buttonPin)<=550){ //pushed left
incrementNumber--;
if(incrementNumber < 0){incrementNumber = 6;}
delay(300);
}
if(analogRead(buttonPin)>=550 && analogRead(buttonPin)<=750)
{ // we have pushed select
incrementNumber = 7;
delay(800);
}
//if(incrementNumber > 6){incrementNumber = 0;}
//if(incrementNumber < 0){incrementNumber = 6;}
delay(100);
lcd.clear();
}
void upFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency + 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency + 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency + 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency + 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency + 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency + 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency + 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC + 10);
break;
default:
toFrequency = (toFrequency + 10);
break;
}
}
void downFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency - 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency - 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency - 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency - 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency - 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency - 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency - 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC - 10);
break;
default:
toFrequency = (toFrequency - 10);
break;
}
}
Данная Программа ищет резонансную частоту катушки, после чего раскачивает катушку найденной резонансной частотой заполняя ее пачками импульсов. Предусмотренна ручная подстройка скважности, частоты и фазы. В этой проге не хватает модуля автоподстройки для полноценной замены 4046, ну и Arduino 16мГц слабоват.
Возвращаясь к вопроу, это немного больше чем тебе нужно, но все лишнее можно легко удалить. Если бы ты объяснил для чего тебе это нужно, было бы проще. Какая разрешающяя способность необходимой частоты? 1.00 или 0.001 Гц?
D:\UNO_gen_resonance\UNO_gen_resonance.ino:2:17: fatal error: PWM.h: No such file or directory
#include <PWM.h>
^
compilation terminated.
exit status 1
Ошибка компиляции.
вот файл, скопируй в libraries и назови PWM.h
/* <PWM.h>
Copyright (c) 2012 Sam Knight
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
For legal advice on subjects of Copyright, Trademarks and Patents please consult
legal counsel at myattorneyusa.com
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
This library is built to support two of the AVR Architecture 'groups' that Arduino uses
a) ATmega48/88/168/328,
b) ATmega640/1280/1281/2560/2561
*/
#ifndef PWM_H_
#define PWM_H_
#include "avr/pgmspace.h"
#include "math.h"
#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#include "utility/ATimerDefs.h"
#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
#include "utility/BTimerDefs.h"
#endif
#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
// 16 bit timers
extern uint32_t GetFrequency_16(const int16_t timerOffset);
extern bool SetFrequency_16(const int16_t timerOffset, uint32_t f);
extern uint16_t GetPrescaler_16(const int16_t timerOffset);
extern void SetPrescaler_16(const int16_t timerOffset, prescaler psc);
extern void SetTop_16(const int16_t timerOffset, uint16_t top);
extern uint16_t GetTop_16(const int16_t timerOffset);
extern void Initialize_16(const int16_t timerOffset);
extern float GetResolution_16(const int16_t timerOffset);
// 8 bit timers
extern uint32_t GetFrequency_8(const int16_t timerOffset);
extern bool SetFrequency_8(const int16_t timerOffset, uint32_t f);
extern uint16_t GetPrescaler_8(const int16_t timerOffset);
extern void SetPrescaler_8(const int16_t timerOffset, prescaler psc);
extern void SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
extern void SetTop_8(const int16_t timerOffset, uint8_t top);
extern uint8_t GetTop_8(const int16_t timerOffset);
extern void Initialize_8(const int16_t timerOffset);
extern float GetResolution_8(const int16_t timerOffset);
#endif
#if defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
// 16 bit timers
extern uint32_t GetFrequency_16();
extern bool SetFrequency_16(uint32_t f);
extern uint16_t GetPrescaler_16();
extern void SetPrescaler_16(prescaler psc);
extern void SetTop_16(uint16_t top);
extern uint16_t GetTop_16();
extern void Initialize_16();
extern float GetResolution_16();
// 8 bit timers
extern uint32_t GetFrequency_8(const int16_t timerOffset);
extern bool SetFrequency_8(const int16_t timerOffset, uint32_t f);
extern uint16_t GetPrescaler_8(const int16_t timerOffset);
extern void SetPrescaler_8(const int16_t timerOffset, prescaler psc);
extern void SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
extern void SetTop_8(const int16_t timerOffset, uint8_t top);
extern uint8_t GetTop_8(const int16_t timerOffset);
extern void Initialize_8(const int16_t timerOffset);
extern float GetResolution_8(const int16_t timerOffset);
#endif
//common functions
extern void InitTimers();
extern void InitTimersSafe(); //doesn't init timers responsible for time keeping functions
extern void pwmWrite(uint8_t pin, uint8_t val);
extern void pwmWriteHR(uint8_t pin, uint16_t val); //accepts a 16 bit value and maps it down to the timer for maximum resolution
extern bool SetPinFrequency(int8_t pin, uint32_t frequency);
extern bool SetPinFrequencySafe(int8_t pin, uint32_t frequency); //does not set timers responsible for time keeping functions
extern float GetPinResolution(uint8_t pin); //gets the PWM resolution of a pin in base 2, 0 is returned if the pin is not connected to a timer
#endif /* PWM_H_ */
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Попробовал Ваш sketch, назвал тоже UNO_gen_resonance.ino. При проверке в arduino 1.6.8 споткнулся : exit status 1Abadiya пишет:
У меня, рабoтает практически на любом Arduino - UNO, Mega, Mini и т.д.Mining пишет:
Для какой ардуины Ваш скеч? Для UNO не компилируется.Abadiya пишет: Посмотри на это
Или вот это
Если не подходит то вотВНИМАНИЕ: Спойлер! [ Нажмите, чтобы развернуть ] [ Нажмите, чтобы скрыть ]
#include <stdio.h>
#include <PWM.h>
#include <LiquidCrystal.h>
#define buttonPin A0
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// some variables to use in our program
// Frequency
long toFrequency = 1000; //Start Fq
long currentFrequency; //Current Fq
long maxFrequency = 2000000; //Max Fq
long minFrequency = 1; //Min Fq
int fstep = 10;
// Duty Cycle
int toDC = 520; //Start DC
int DC; //Current DC
int maxDC = 1000; //Max DC
int minDC = 10; //Min DC
// Menu items
int incrementNumber = 1;
int maxprogramnumber = 7; // dont forget to increase the menu numbers here!!
int programnumber = 1;
// Function PWM Library
int32_t ddspin_44 = toFrequency; //frequency (in Hz)
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define LOCKLED 12 //LED - indicator when the frequency is locked, pin D1 *Changed from D1 to D12 just to be next to the new scan LED pin - firepinto 10/25/14
#define SCANLED 11 //LED - indicator when scanning, pin D0 *Changed from D0 to D11 because of serial uploading issues from the IDE - firepinto 10/25/14
#define PEAKLED 13 //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define PICKUP A8 //pickup coil is connected to pin A8 via voltage divider and a zener diode
int freq = 0; //Variable for Locked frequency
int freqplus = 0; //Low end of freqency fine tune scale - firepinto 10/27/14
int freqminus = 0; //High end of freqency fine tune scale - firepinto 10/27/14
int freqrange = 0; //Variable for FRANGE POT
int scale = 0; //Scale variable in Hz for manual frequency adjust buttons
int adjfreq = freq; //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
void setup()
{
Serial.begin(9600);
InitTimersSafe();
SetPinFrequencySafe(44, toFrequency);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(":DDS");
lcd.setCursor(0, 1);
lcd.print(" Square-Wave ");
delay(3000);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
lcd.clear();
}
void loop()
{
lcd.clear();
lcd.print(" SCANNING... ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(11,1);
lcd.print("Hz");
//start scan scanUP() to oscillate the circuit
for (toFrequency = minFrequency; toFrequency <= maxFrequency; toFrequency = toFrequency + fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP); //then read the voltage
if (volt > 818) //If pick-up coil voltage is greater than 4 volts
{
digitalWrite(PEAKLED, HIGH); //turn on peak LED
}
else
{
digitalWrite(PEAKLED, LOW); //turn off peak LED
}
if (vmax < volt) //if there is a resonant point voltage should have the highest value on this frequency
{
vmax = volt; //store as the best voltage
freq = toFrequency; //remember that frequency
intval = intval++; //times found a nice frequency interval, is showing during scan on the left of the lcd
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
lcd_key = read_LCD_buttons();
//start scanDown to oscillate the circuit
for (toFrequency = maxFrequency; toFrequency >= minFrequency; toFrequency = toFrequency - fstep)
{
SetPinFrequencySafe(44, toFrequency); //will send a freq at first
delay(1); //wait for a millisec
Serial.println(toFrequency);
volt = analogRead(PICKUP);
if (volt > 818) // *Added by firepinto 10/26/14
{
digitalWrite(PEAKLED, HIGH);
}
else
{
digitalWrite(PEAKLED, LOW);
}
if (vmax < volt)
{
vmax = volt;
freq = toFrequency;
adjfreq = freq;
intval = intval++ ;
lcd.setCursor(0,1);
lcd.print(intval);
}
lcd.setCursor(5,1);
lcd.print(toFrequency);
}
if(toDC >= maxDC){(toDC = maxDC);}
if(toDC <= minDC){(toDC = minDC);}
DC=toDC;
pwmWrite(44, toDC / 4);
}
int read_LCD_buttons(){
switch(incrementNumber){
case 0:
lcd.setCursor(0,0);
lcd.print("x 1hz");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("x 10hz");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("x 1khz");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("x 10khz");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("x 100khz");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("x 1Mhz");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("Duty C");
break;
default:
lcd.setCursor(0, 0);
lcd.print("x 100hz");
break;
}
lcd.setCursor(0, 1);
lcd.print("Freq :"); //Print to lcd
lcd.setCursor(8, 1);
lcd.print(currentFrequency);
lcd.setCursor(9, 0);
lcd.print("DC :"); //Print to lcd
lcd.setCursor(12, 0);
lcd.print(toDC);
//Serial.println(incrementNumber); // temporary for debuggin delete me
while((analogRead(buttonPin))>=1000){} // do nothing while no buttons pressed to chill out
delay(5);
if(analogRead(buttonPin)>=100 && analogRead(buttonPin)<=200){ // we have pushed up
upFrequency();
delay(300);
}
if(analogRead(buttonPin)>=200 && analogRead(buttonPin)<=350){ // we have pushed down
downFrequency();
delay(300);
}
if((analogRead(buttonPin))<=50){ //pushed right
incrementNumber++;
if(incrementNumber > 6){incrementNumber = 0;}
delay(300);
}
if(analogRead(buttonPin)>=350 && analogRead(buttonPin)<=550){ //pushed left
incrementNumber--;
if(incrementNumber < 0){incrementNumber = 6;}
delay(300);
}
if(analogRead(buttonPin)>=550 && analogRead(buttonPin)<=750)
{ // we have pushed select
incrementNumber = 7;
delay(800);
}
//if(incrementNumber > 6){incrementNumber = 0;}
//if(incrementNumber < 0){incrementNumber = 6;}
delay(100);
lcd.clear();
}
void upFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency + 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency + 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency + 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency + 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency + 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency + 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency + 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC + 10);
break;
default:
toFrequency = (toFrequency + 10);
break;
}
}
void downFrequency()
{
switch(incrementNumber){
case 0:
toFrequency = (toFrequency - 1);
fstep = 1;
break;
case 1:
toFrequency = (toFrequency - 10);
fstep = 10;
break;
case 2:
toFrequency = (toFrequency - 100);
fstep = 100;
break;
case 3:
toFrequency = (toFrequency - 1000);
fstep = 1000;
break;
case 4:
toFrequency = (toFrequency - 10000);
fstep = 10000;
break;
case 5:
toFrequency = (toFrequency - 100000);
fstep = 100000;
break;
case 6:
toFrequency = (toFrequency - 1000000);
fstep = 1000000;
break;
case 7:
toDC = (toDC - 10);
break;
default:
toFrequency = (toFrequency - 10);
break;
}
}
Данная Программа ищет резонансную частоту катушки, после чего раскачивает катушку найденной резонансной частотой заполняя ее пачками импульсов. Предусмотренна ручная подстройка скважности, частоты и фазы. В этой проге не хватает модуля автоподстройки для полноценной замены 4046, ну и Arduino 16мГц слабоват.
Возвращаясь к вопроу, это немного больше чем тебе нужно, но все лишнее можно легко удалить. Если бы ты объяснил для чего тебе это нужно, было бы проще. Какая разрешающяя способность необходимой частоты? 1.00 или 0.001 Гц?
D:\UNO_gen_resonance\UNO_gen_resonance.ino:2:17: fatal error: PWM.h: No such file or directory
#include <PWM.h>
^
compilation terminated.
exit status 1
Ошибка компиляции.
вот файл, скопируй в libraries и назови PWM.h
ВНИМАНИЕ: Спойлер! [ Нажмите, чтобы развернуть ] [ Нажмите, чтобы скрыть ]
/* <PWM.h>
Copyright (c) 2012 Sam Knight
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
For legal advice on subjects of Copyright, Trademarks and Patents please consult
legal counsel at myattorneyusa.com
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
This library is built to support two of the AVR Architecture 'groups' that Arduino uses
a) ATmega48/88/168/328,
b) ATmega640/1280/1281/2560/2561
*/
#ifndef PWM_H_
#define PWM_H_
#include "avr/pgmspace.h"
#include "math.h"
#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#include "utility/ATimerDefs.h"
#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
#include "utility/BTimerDefs.h"
#endif
#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
// 16 bit timers
extern uint32_t GetFrequency_16(const int16_t timerOffset);
extern bool SetFrequency_16(const int16_t timerOffset, uint32_t f);
extern uint16_t GetPrescaler_16(const int16_t timerOffset);
extern void SetPrescaler_16(const int16_t timerOffset, prescaler psc);
extern void SetTop_16(const int16_t timerOffset, uint16_t top);
extern uint16_t GetTop_16(const int16_t timerOffset);
extern void Initialize_16(const int16_t timerOffset);
extern float GetResolution_16(const int16_t timerOffset);
// 8 bit timers
extern uint32_t GetFrequency_8(const int16_t timerOffset);
extern bool SetFrequency_8(const int16_t timerOffset, uint32_t f);
extern uint16_t GetPrescaler_8(const int16_t timerOffset);
extern void SetPrescaler_8(const int16_t timerOffset, prescaler psc);
extern void SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
extern void SetTop_8(const int16_t timerOffset, uint8_t top);
extern uint8_t GetTop_8(const int16_t timerOffset);
extern void Initialize_8(const int16_t timerOffset);
extern float GetResolution_8(const int16_t timerOffset);
#endif
#if defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
// 16 bit timers
extern uint32_t GetFrequency_16();
extern bool SetFrequency_16(uint32_t f);
extern uint16_t GetPrescaler_16();
extern void SetPrescaler_16(prescaler psc);
extern void SetTop_16(uint16_t top);
extern uint16_t GetTop_16();
extern void Initialize_16();
extern float GetResolution_16();
// 8 bit timers
extern uint32_t GetFrequency_8(const int16_t timerOffset);
extern bool SetFrequency_8(const int16_t timerOffset, uint32_t f);
extern uint16_t GetPrescaler_8(const int16_t timerOffset);
extern void SetPrescaler_8(const int16_t timerOffset, prescaler psc);
extern void SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
extern void SetTop_8(const int16_t timerOffset, uint8_t top);
extern uint8_t GetTop_8(const int16_t timerOffset);
extern void Initialize_8(const int16_t timerOffset);
extern float GetResolution_8(const int16_t timerOffset);
#endif
//common functions
extern void InitTimers();
extern void InitTimersSafe(); //doesn't init timers responsible for time keeping functions
extern void pwmWrite(uint8_t pin, uint8_t val);
extern void pwmWriteHR(uint8_t pin, uint16_t val); //accepts a 16 bit value and maps it down to the timer for maximum resolution
extern bool SetPinFrequency(int8_t pin, uint32_t frequency);
extern bool SetPinFrequencySafe(int8_t pin, uint32_t frequency); //does not set timers responsible for time keeping functions
extern float GetPinResolution(uint8_t pin); //gets the PWM resolution of a pin in base 2, 0 is returned if the pin is not connected to a timer
#endif /* PWM_H_ */
'A8' was not declared in this scope.
Не нравится среде строка 49: #define PICKUP A8 //pickup coil is connected to pin A8 via voltage divider and a zener diode
/Сократ/
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.