PWM frequency

Arduino on the STM8 (8 bit processor)
Post Reply
.rpv
Posts: 2
Joined: Tue Apr 09, 2019 11:43 pm
OS: WIN
IDE: Arduino
Core: Roger's, STM official, STM8 Sduino

PWM frequency

Post by .rpv » Wed Apr 10, 2019 5:49 am

Hi guys!

I wonder if someone knows how I can change the pwm frequency on one of this little beast, I'm using sduino on arduino, I can't find any example on the documentation and the code that works on the blue pill didn't work on this mcu.

Thanks.

.rpv
Posts: 2
Joined: Tue Apr 09, 2019 11:43 pm
OS: WIN
IDE: Arduino
Core: Roger's, STM official, STM8 Sduino

Re: PWM frequency

Post by .rpv » Fri Apr 12, 2019 8:17 am

I like this little beast :D
just trying adapting a tm1637 library on the stm8:
stm8_01.jpg
stm8_01.jpg (238.16 KiB) Viewed 251 times

Code: Select all

//--------------------------------------------------------------------------------------------.rTM1637;--//
//this.it's.just.a.reduced.version.of.the.library:https://github.com/maxint-rd/TM16xx
byte _rLD[4]={
	PD3,							//.DIO;3
	PD2,							//.CLK;2
	6,							//.segments;
	6,							//.brightness;
};

const int rLD_ch[]={
	0b00111111,//0
	0b00000110,//1
	0b01011011,//2
	0b01001111,//3
	0b01100110,//4
	0b01101101,//5
	0b01111101,//6
	0b00000111,//7
	0b01111111,//8
	0b01101111,//9
	0b01110111,//A
	0b01111100,//b
	0b00111001,//C
	0b01011110,//D
	0b01111001,//E
	0b01110001,//F
};


void rLD_b(byte i){//.brightness();
	i=(i>=1&&i<=7)?i:4;
	_rLD[3]=i&0x7;}
void rLD_bd(void){delayMicroseconds(5);}//.bitdelay;
void rLD_st(void){digitalWrite(_rLD[0],LOW);rLD_bd();}//.start;
void rLD_sp(void){digitalWrite(_rLD[0],LOW);digitalWrite(_rLD[1],LOW);rLD_bd();digitalWrite(_rLD[1],HIGH);digitalWrite(_rLD[0],HIGH);rLD_bd();}//.stop;
void rLD_sx(byte i){//.send;
	for(byte c=0;c<8;c++){
		digitalWrite(_rLD[1],LOW);
		rLD_bd();
		digitalWrite(_rLD[0],i&1?HIGH:LOW);
		rLD_bd();
		i>>=1;
		digitalWrite(_rLD[1],HIGH);
		rLD_bd();}
	rLD_bd();
	digitalWrite(_rLD[1],LOW);
	pinMode(_rLD[0],INPUT);
	rLD_bd();
	digitalWrite(_rLD[1],HIGH);
	rLD_bd();
	byte s=digitalRead(_rLD[0]);
	if(s==0){digitalWrite(_rLD[0],LOW);}
	pinMode(_rLD[0],OUTPUT);}
void rLD_sc(byte i){rLD_st();rLD_sx(i);rLD_sp();}//.sendcommand;
void rLD_cl(void){//.clear;
	rLD_sc(0x40);
	rLD_st();
	rLD_sx(0xC0);
	for(byte i=0;i<_rLD[2];i++){rLD_sx(0x00);}
	rLD_sp();}
void rLD_cx(byte i,byte s){//.sendChar(i:pos;s:char);
	rLD_sc(0x44);
	rLD_st();
	rLD_sx(0xC0|i);
	rLD_sx(s);
	rLD_sp();}


void rLD_c(void){//.create;
	pinMode(_rLD[0],OUTPUT);
	pinMode(_rLD[1],OUTPUT);
	digitalWrite(_rLD[0],HIGH);
	digitalWrite(_rLD[1],HIGH);
	rLD_cl();
	rLD_sc(0x80|8|_rLD[3]);}
//--------------------------------------------------------------------------------------------.rTM1637;--//



void setup(void){

	rLD_c();

}



void loop(void){
	int c;
	for(c=0;c<_rLD[3];c++){
		rLD_cx(c,rLD_ch[c]);
		delay(2000);}
	rLD_cl();
	for(c=_rLD[3]-1;c>=0;c--){
		rLD_cx(c,rLD_ch[c]);
		delay(2000);}
	rLD_cl();
	delay(1000);
}
And arduino ide says:
Sketch uses 2979 bytes (36%) of program storage space. Maximum is 8192 bytes.
Global variables use 74 bytes (7%) of dynamic memory, leaving 950 bytes for local variables. Maximum is 1024 bytes.

Post Reply