Generator problem

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
ted456
 
Posts: 18
Joined: Sat Jun 18, 2022 6:13 am

Generator problem

Post by ted456 »

Hi
This generator is working ok when I am using ST Link as upload method , when using a serial method buttons are not working and on display is a number 741 = 741 Hz.
Any idea how to fix it ?

Code: Select all

#include <EEPROM.h> 

unsigned long amp = 0;

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306_STM32.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  display.display();
  display.clearDisplay(); 
  display.drawPixel(100, 15, WHITE);

  pinMode(PA8, PWM);
  pinMode(PA9, PWM);
  pinMode(PB8, INPUT_PULLUP);
  pinMode(PB9, INPUT_PULLUP);
  TIMER1_BASE->CCER = (1 << 4) | (1 << 0);
  TIMER1_BASE->CCMR1 = (1 << 13) | (1 << 12) | (1 << 5) | (1 << 4);
  TIMER1_BASE->PSC = 0;
  TIMER1_BASE->CCR1 = 0 ;
  TIMER1_BASE->CR1 = 1;
  EEPROM.read(500, (uint16*)&amp);

}

void loop() {
  if (digitalRead(PB8) == 0) {
    amp++;

    EEPROM.write(500, amp);
  }
  if (digitalRead(PB9) == 0) {
    amp--;

    EEPROM.write(500, amp);
  }

  TIMER1_BASE->ARR = amp * 2;
  TIMER1_BASE->CCR2 = amp ;

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);

  display.setCursor(64, 28);
  display.print(36000000 / amp / 2);
  display.display();

  delay(20);
}

User avatar
sj_remington
 
Posts: 460
Joined: Mon Jul 27, 2020 4:51 pm

Re: Generator problem

Post by sj_remington »

What might the "generator" be?

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Arduino”