Hello
This is my first post. I am rather a beginner in the microcontroller world, also have little experience with C++, having only used VisualBasic up to VS2019, as well as assembler (many years ago).
I am currently trying to control a TCD1304DG. Using the delay commands worked quite well, because you can specify the timing quite well. However, the timing will hardly be sufficient to drive an ADC as well.
But on my oscilloscope I could observe the reactions of the chip.
Now I am trying to use this clock:
#define CPU_RESET_CYCLECOUNTER do { ARM_DEMCR |= ARM_DEMCR_TRCENA; \
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; \
ARM_DWT_CYCCNT = 0; } while(0)
In principle this works very well for the slower signals. Only for the clock the tempo is again not enough.
I used the Teensy 4.1 because I had read that it can work with much higher clock rates. To generate the clock for my chip I used
a modulo function. But maybe it's possible to lead a chip-internal clock to the outside, which I can synchronize with the other signals?
I don't want to use a ready-made library for my chip, because I can't learn anything with it.
What would you suggest?
On the screenshot you can see that the pulse width of the yellow signal (chip-clock) varies a lot. If I had a higher clock rate of the processor it should be possible to stabilize it, and besides to operate an ADC.
This is my first post. I am rather a beginner in the microcontroller world, also have little experience with C++, having only used VisualBasic up to VS2019, as well as assembler (many years ago).
I am currently trying to control a TCD1304DG. Using the delay commands worked quite well, because you can specify the timing quite well. However, the timing will hardly be sufficient to drive an ADC as well.
But on my oscilloscope I could observe the reactions of the chip.
Now I am trying to use this clock:
#define CPU_RESET_CYCLECOUNTER do { ARM_DEMCR |= ARM_DEMCR_TRCENA; \
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; \
ARM_DWT_CYCCNT = 0; } while(0)
In principle this works very well for the slower signals. Only for the clock the tempo is again not enough.
I used the Teensy 4.1 because I had read that it can work with much higher clock rates. To generate the clock for my chip I used
a modulo function. But maybe it's possible to lead a chip-internal clock to the outside, which I can synchronize with the other signals?
I don't want to use a ready-made library for my chip, because I can't learn anything with it.
What would you suggest?
Code:
#define CPU_RESET_CYCLECOUNTER do { ARM_DEMCR |= ARM_DEMCR_TRCENA; \
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; \
ARM_DWT_CYCCNT = 0; } while(0)
volatile int cycles;
int fMPin = 3;
int SH = 5;
int ICG = 7;
int duty = 50;
int freq = 40;
int fak = freq +1;
float dutys = (freq/(100/duty));
void setup()
{
pinMode(fMPin, OUTPUT);
pinMode(SH, OUTPUT);
pinMode(ICG, OUTPUT);
digitalWriteFast(ICG, HIGH);
digitalWriteFast(SH, LOW);
ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
noInterrupts();
}
void yield () {}
FASTRUN
void loop(){
// ICG
if((ARM_DWT_CYCCNT >= 100) && (ARM_DWT_CYCCNT <= 2400) ){
digitalWriteFast(ICG,LOW);
}
else {
digitalWriteFast(ICG,HIGH);
}
// SH
if((ARM_DWT_CYCCNT >= 200) && (ARM_DWT_CYCCNT <= 1400) ){
digitalWriteFast(SH,HIGH);
}
else {
digitalWriteFast(SH,LOW);
}
// fMPin
if( float((ARM_DWT_CYCCNT * fak) % freq) < dutys ){
digitalWriteFast(fMPin,HIGH);
}
else {
digitalWriteFast(fMPin,LOW);
}
if (ARM_DWT_CYCCNT>=1200000){
CPU_RESET_CYCLECOUNTER;
digitalWriteFast(fMPin,LOW);
}
}
On the screenshot you can see that the pulse width of the yellow signal (chip-clock) varies a lot. If I had a higher clock rate of the processor it should be possible to stabilize it, and besides to operate an ADC.