How do I count PWM pulses. Then switch on another pin after x pulses on (or near to) the rising edge.
Essentially what I am looking for is an internal register that is "following" the PWM pulses.
The chip is a 16F1788.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The timer2 to PR2 interrupt flag (PIR1.1) seemed promising, but for some reason is going at a different frequency (I don't know how this is possible).
I've got the PWM at 400 kHz (period 2.5 us) and the interrupt flag is going at a rate of 500 kHz (2.0 us)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just my poor coding being interpreted by the assembler in an unexpected way. PIR1.1 may well be producing an interrupt but it clears too fast to capture.
Maybe the easiest way is to feed the PWM back into an input pin (not an elegant solution).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't think how except connecting to an input pin. Using software pwm in help it says- The PWM is only operational for the number of cycles stated in the calling method. So why try counting pwm?..out of interest.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no internal register that is holding the number of PWM pulses. The simplest method to count PWM pulses would be to connect the PWM out signal to either the T0CK1 or T1CK1 Pin and set up either Timer0 or Timer1 as a counter (External Clock Source)
I would use a 200R to 1k series resister to connect the PWM OUT pin to the tmer CK input pin.
Last edit: William Roth 2017-08-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This has turned out more difficult than anticipated. The device I am sending the pulses specifies a minimum frequency of 400 kHz. This did not seem to be a problem at first after all I can go up to 32 MHz on the 16F1788, but when I finally did the maths 400 kHz rate only allows 20 instructions between pulses which is a bit tight when incrementing a counter testing the number of increments and maybe doing something else. I thought at one stage of using the clockout instead of the PWM, but then I would be limited to the chip clock divided by a power of 2.
If anyone wants to make suggestions the device is an optical array Toshiba TCD1103. At the moment I am just trying to get the necessay pulses working, but I will have to think about an external ADC and maybe a FIFO at some stage.
It may be an idea to move up to a 64MHz chip.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think I am getting the timing, but only just mainly by writing ASM code (well maybe).
Problem now is the device I am connecting to is pulling the logic level from the 16F1688 way down (is this normal?).Also the datasheet for the doide array (TCD1103) in the "suggested circuit" has logic inverters and I'm wondering if the logic is all inverted.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The low logic was a rogue piece of solder on the PCB. It now works and surprisingly can be slowed down well below what is in the datasheet so I might get away with using the internal ADC.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How do I count PWM pulses. Then switch on another pin after x pulses on (or near to) the rising edge.
Essentially what I am looking for is an internal register that is "following" the PWM pulses.
The chip is a 16F1788.
The timer2 to PR2 interrupt flag (PIR1.1) seemed promising, but for some reason is going at a different frequency (I don't know how this is possible).
I've got the PWM at 400 kHz (period 2.5 us) and the interrupt flag is going at a rate of 500 kHz (2.0 us)
Just my poor coding being interpreted by the assembler in an unexpected way. PIR1.1 may well be producing an interrupt but it clears too fast to capture.
Maybe the easiest way is to feed the PWM back into an input pin (not an elegant solution).
I can't think how except connecting to an input pin. Using software pwm in help it says- The PWM is only operational for the number of cycles stated in the calling method. So why try counting pwm?..out of interest.
There is no internal register that is holding the number of PWM pulses. The simplest method to count PWM pulses would be to connect the PWM out signal to either the T0CK1 or T1CK1 Pin and set up either Timer0 or Timer1 as a counter (External Clock Source)
I would use a 200R to 1k series resister to connect the PWM OUT pin to the tmer CK input pin.
Last edit: William Roth 2017-08-02
This has turned out more difficult than anticipated. The device I am sending the pulses specifies a minimum frequency of 400 kHz. This did not seem to be a problem at first after all I can go up to 32 MHz on the 16F1788, but when I finally did the maths 400 kHz rate only allows 20 instructions between pulses which is a bit tight when incrementing a counter testing the number of increments and maybe doing something else. I thought at one stage of using the clockout instead of the PWM, but then I would be limited to the chip clock divided by a power of 2.
If anyone wants to make suggestions the device is an optical array Toshiba TCD1103. At the moment I am just trying to get the necessay pulses working, but I will have to think about an external ADC and maybe a FIFO at some stage.
It may be an idea to move up to a 64MHz chip.
Investigate CLC and NCO. These are hardware and with very low latency. You could config CLC to count independent of your program activities.
Thanks for that it may be the way to go.
If you want. I can ask Microchip to provide us some insights on how to do this.
I think I am getting the timing, but only just mainly by writing ASM code (well maybe).
Problem now is the device I am connecting to is pulling the logic level from the 16F1688 way down (is this normal?).Also the datasheet for the doide array (TCD1103) in the "suggested circuit" has logic inverters and I'm wondering if the logic is all inverted.
The low logic was a rogue piece of solder on the PCB. It now works and surprisingly can be slowed down well below what is in the datasheet so I might get away with using the internal ADC.