|
|
View previous topic :: View next topic |
Author |
Message |
-Sonic-
Joined: 27 Jul 2015 Posts: 1
|
CWG Module PIC12F1571 |
Posted: Tue Jul 28, 2015 1:11 am |
|
|
I'm working on a new project for a frequency generator and I want to use the CWG Module in the PIC121571 but I need some help.
To test the CWG Module, the only thing I want to do is to produce a complementary waveform on pin RA0 and RA2. The input signal is generated external with a function generator on pin RA1.
Here is my code:
Code: |
set_tris_a(0b00100010);
setup_comparator(NC_NC);
setup_vref(VREF_OFF);
setup_adc_ports(ADC_OFF);
setup_cwg(CWG_ENABLED | CWG_OUTPUT_A | CWG_OUTPUT_B | CWG_CWG1B_A0 | CWG_CWG1A_A2 | CWG_B_INVERTED | CWG_CLOCK_FOSC | CWG_INPUT_PWM1 , CWG_NO_AUTO_SHUTDOWN, 0, 0);
|
I don't know what is wrong, but I don't get any signal on pin A0 and A2, although a rectangular signal of 2kHz is on pin A1.
Any idea? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Jul 28, 2015 1:51 am |
|
|
You shouldn't need the invert. The 'B' output, is fed from the /Q output of the internal flip flop, the 'A' output, from Q. So the module should give inverted outputs without you having to invert either signal.
Then generally, with these setups, CCS often forgets to set the TRIS. So use 'output_drive()' on each of the pins you are using, to ensure that the driver is turned on. Though you set TRIS first, this will be overridden by the setup, since TRIS _must_ be off to configure this peripheral.
The 2KHz you are seeing is the PWM output. You are telling the CWG, to operate from PWM1 _out_. You can't use the output as an input. The only external signal the CWG can use is the comparator. So the compiler is programming PWM1 to feed PWM1_OUT
So:
Code: |
setup_comparator(CP1_A1_FVR);
//Enable the comparator input on A1.
setup_vref(VREF_COMP_DAC_2v048);
//set the reference to 2.048V
setup_adc_ports(ADC_OFF);
setup_cwg(CWG_ENABLED | CWG_OUTPUT_A | CWG_OUTPUT_B | CWG_CWG1B_A0 | CWG_CWG1A_A2 | CWG_CLOCK_FOSC | CWG_INPUT_C1OUT , CWG_NO_AUTO_SHUTDOWN, 0, 0);
//feed this from the comparator output
output_float(PIN_A1); //make sure A1 is an input
output_drive(PIN_A0);
output_drive(PIN_A2); //enable the two CWG outputs.
|
I think that should be close (no guarantees....). |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|