Skip to content

Commit 192e529

Browse files
committed
investigating the delay problem
1 parent ab6a60b commit 192e529

5 files changed

Lines changed: 51 additions & 13 deletions

File tree

-112 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stm8s103.lib

sduino/wiring.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ unsigned long micros()
144144

145145

146146
void delay(unsigned long ms)
147+
#if 1
148+
#warning "using the crappy version of delay()"
149+
{
150+
uint32_t ziel = millis()+ms;
151+
152+
while(millis()<ziel);
153+
}
154+
#else
147155
{
148156
uint32_t start = micros();
149157

@@ -155,7 +163,7 @@ void delay(unsigned long ms)
155163
}
156164
}
157165
}
158-
166+
#endif
159167
/* Delay for the given number of microseconds. Assumes a 1, 8, 12, 16, 20 or 24 MHz clock. */
160168
void delayMicroseconds(unsigned int us)
161169
{

sduino/wiring_analog.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,23 @@ int analogRead(uint8_t pin)
6161
if (pin>=NUM_ANALOG_INPUTS)
6262
pin = digitalPinToAnalogChannelMap[pin-NUM_ANALOG_INPUTS];
6363
if (pin>=NUM_ANALOG_INPUTS) return 0; // illegal pin number
64-
64+
//ADC1_ConversionConfig(ADC1_CONVERSIONMODE_SINGLE, pin, ADC1_ALIGN_RIGHT);
65+
ADC1_ConversionConfig(ADC1_CONVERSIONMODE_CONTINUOUS, pin, ADC1_ALIGN_RIGHT);
66+
ADC1_PrescalerConfig(ADC1_PRESSEL_FCPU_D18);
67+
ADC1_ExternalTriggerConfig(ADC1_EXTTRIG_TIM, DISABLE);
68+
ADC1_SchmittTriggerConfig(pin, DISABLE);
69+
/*
6570
// select channel
6671
ADC1->CSR = pin+2; // arduino channel 0 is Ain2 on STM8S103
67-
bitSet(ADC1->CSR, 3); // right align
68-
72+
bitSet(ADC1->CR2, 3); // right align
73+
*/
6974
// start the conversion
70-
bitSet(ADC1->CR1, 0);
75+
// bitSet(ADC1->CR1, 0);
76+
ADC1->CR1 |= ADC1_CR1_ADON;
7177

7278
// EOC is set when the conversion finishes
73-
while (! ADC1->CSR & ADC1_IT_EOC);
79+
// while (! (ADC1->CSR & ADC1_IT_EOC));
80+
delay(2);
7481

7582
// in right align mode we have to read DRL first
7683
low = ADC1->DRL;

test/adc1/adc1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*/
44

55
#include "Arduino.h"
6-
#include "HardwareSerial.h"
7-
#include "Print.h"
6+
#include "Serial.h"
87

98
#include "stm8s_flash.h"
109

1110
void setup(void)
1211
{
13-
HardwareSerial_begin(115200);
12+
Serial_begin(115200);
13+
Serial_println_s("ADC test");
1414

1515
// configure analog pins for input
1616
pinMode(A0, INPUT);
@@ -27,7 +27,7 @@ void loop (void)
2727

2828
for (i=0; i<5; ++i) {
2929
// use channel numbers for reading the inputs
30-
Print_print_u(analogRead(i));
30+
Serial_print_u(analogRead(i));
3131
printStr("\t");
3232
};
3333
println();

test/timer2/timer2.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
#include "Print.h"
99

1010

11+
uint32_t prev=0;
12+
13+
14+
void mydelay(unsigned long ms)
15+
{
16+
uint32_t start = micros();
17+
18+
while (ms > 0) {
19+
// yield();
20+
while ( ms > 0 && (micros() - start) >= 1000) {
21+
ms--;
22+
start += 1000;
23+
}
24+
}
25+
}
26+
27+
1128
void setup(void)
1229
{
1330
HardwareSerial_begin(115200);
@@ -16,12 +33,18 @@ void setup(void)
1633

1734
void loop (void)
1835
{
19-
uint32_t i;
36+
uint32_t now;
2037

38+
now = millis();
2139
Print_print_s("millis()=");
22-
Print_print_u(millis());
40+
Print_print_u(now);
41+
Print_print_s("\tdelta=");
42+
Print_print_u(now-prev);
43+
Print_print_s("\tmicros()=");
44+
Print_print_u(micros());
2345
Print_print_s("\tTIM4_CNTR=");
2446
Print_println_u(TIM4->CNTR);
2547

26-
delay(1000);
48+
prev = now;
49+
mydelay(1000);
2750
}

0 commit comments

Comments
 (0)