I just noticed that the PIC16F1827 has a 5-bit D-> A converter on it, which would be handy for a project I am working on. Has anyone implemented it's use with GCB and if so have you got any example code to share with me please.
I have played around with it but not used it in a project or submited a Library.
It is only intended to be used as a voltage referance and would need an OP-AMP to boost it if you need it as an external signal.
What is it that you intend to do with it?
Cheers
chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Chris .. no problem adding an op amp to my PCB design. I need it drive a motor speed controller which requires a 0->10v signal (input impedance of speed control input is around 10kOhms. The main PSU is 24v DC, regulated down to 12v then 5v, so I could use the 12v to power the Opamp to boost the PIC DAC signal to 0->10v . I know it's not a very resolute
D-> A but it keeps the chip count/cost down and seems perfect for my application.
Last edit: ashimotok0 2018-02-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am up for any suggestions of how to implement a DAC onto my project . I do have an MCP4728 I2C chip .. bit of an overkill but not too expensive. Any ideas please.
best wishes .. Ash
Here is the C ? code for the on-chip 5-bit. The guy who posted it was having non-linearity problems but this was due to use a dev board with RA0 fitted with a resistor which needs removing when asigning and using the pin as a DAC output pin.
#include <htc.h> //PIC hardware mapping
//#define _XTAL_FREQ 500000 //Used by the XC8 delay_ms(x) macro
//config bits that are part-specific for the PIC16F1829 CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); CONFIG(WRT_OFF & PLLEN_OFF & STVREN_OFF & LVP_OFF);
void main(void) {
OSCCON = 0b00111000; //500KHz clock speed
TRISAbits.TRISA0 = 1; // RA0 = DAC1 Output 1
// Set the FVR
FVRCONbits.CDAFVR = 0b11; // FVR output voltage for DAC = 4.096V
FVRCONbits.FVREN = 1; // FVR enabled
DACCON0bits.DACPSS=0b10; // use this for DAC Voltage source as the FVR.
DACCON0bits.DACLPS=0; // enable LPS
DACCON0bits.DACOE=1; // enable the DAC output 1 pin (RA0). 1 = DAC voltage level is also an output on the DACOUT pin
DACCON0bits.DACNSS = 0; // DAC negative voltage source is Vss
DACCON0bits.DACEN=1; // turn DAC on
while (1)
{
DACCON1bits.DACR = 0b00011111; // set this to get the maximum voltage output
}
}
Last edit: ashimotok0 2018-02-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'TRISAbits.TRISA0 = 1; // RA0 = DAC1 Output 1
dir PortA.0 out
' // Set the FVR
'FVRCONbits.CDAFVR = 0b11; // FVR output voltage for DAC = 4.096V
CDAFVR0 = 1 'bit 2
CDAFVR1 = 1 'bit3
'FVRCONbits.FVREN = 1; // FVR enabled Bit 7 of FVRCON
FVREN = 1
'DACCON0bits.DACPSS=0b10; // use this for DAC Voltage source as the FVR.
DACPSS0 = 0 'bit 2
DACPSS1 = 1 'bit 3
'DACCON0bits.DACLPS=0; // enable LPS
DACLPS = 0
'DACCON0bits.DACOE=1; // enable the DAC output 1 pin (RA0). 1 = DAC voltage level is also an output on the DACOUT pin
DACOE = 1
'DACCON0bits.DACNSS = 0; // DAC negative voltage source is Vss
DACNSS = 0
'DACCON0bits.DACEN=1; // turn DAC on
DACEN = 1
Do
'DACCON1bits.DACR = 0b00011111; // set this to get the maximum voltage output
'DACR is not a name in the 16F1829 dat file so we have to use DACCON1 as the register name
DACCON1 = 0b00011111; // set this to get the maximum voltage output
loop
Good Luck
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tried it Mike ... initially I couldn't try the code because my PicKit2 v2.60 would not support PIC16F1827 but when I hit flash icon on GCB IDE it programmed and worked fine. I didn't realize you could programme directly from the IDE ... cool !! Many thanks ... Ash
Last edit: ashimotok0 2018-02-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will create a post for the PicKit2.... but, essentially look in your Great Cow BASIC installation. You will find the PicKit2 GUI this has been updated to program your chip, you should also find a within the Great Cow BASIC shell folder an icon to the PicKit2 programmer.
Same applies to the PicKit3.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Glad you got it going Ash but I have to ask why are you trying to use it for your application?
You wanted to control motor speed and the PIC16F1827 has two ECCP (Enhanced Capture Compare PWM) Modules that are specifically designed for High Resolution Motor Speed control.
Having two such controllers will allow you to drive a Half Bridge configuration giving you control over torque and Speed to a resolution several orders of magnitude higher than 16 steps you will get out of a 5 bit D2A Voltage reference.
Internally it is just taps in a resistor divider chain between Vss and Vdd and they are only 5% tolerance if that.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Chris, The analogue ouput is a demand voltage (0-10v ) fed into a Danfoss single-> 3Phase inverter drive, with no requirement on the PCB to locally control the power to a motor. I just need an opamp to boost from around 4v to 10v which is no problem. Hope that explains why I need it. I must say you guys have been immensely helpful over the last two days and the GCB is a wonderul resource. Big thank you to all !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just noticed that the PIC16F1827 has a 5-bit D-> A converter on it, which would be handy for a project I am working on. Has anyone implemented it's use with GCB and if so have you got any example code to share with me please.
Kind regards... Ashley UK.
https://www.dropbox.com/s/601xuo4dzjvlm8a/Pic%20D%20to%20A.JPG?dl=0
Using latest version of GCB IDE (downloaded & installed yesterday)
I have played around with it but not used it in a project or submited a Library.
It is only intended to be used as a voltage referance and would need an OP-AMP to boost it if you need it as an external signal.
What is it that you intend to do with it?
Cheers
chris
Thanks Chris .. no problem adding an op amp to my PCB design. I need it drive a motor speed controller which requires a 0->10v signal (input impedance of speed control input is around 10kOhms. The main PSU is 24v DC, regulated down to 12v then 5v, so I could use the 12v to power the Opamp to boost the PIC DAC signal to 0->10v . I know it's not a very resolute
D-> A but it keeps the chip count/cost down and seems perfect for my application.
Last edit: ashimotok0 2018-02-20
I did find this routine but looks like in C
I am up for any suggestions of how to implement a DAC onto my project . I do have an MCP4728 I2C chip .. bit of an overkill but not too expensive. Any ideas please.
best wishes .. Ash
Here is the C ? code for the on-chip 5-bit. The guy who posted it was having non-linearity problems but this was due to use a dev board with RA0 fitted with a resistor which needs removing when asigning and using the pin as a DAC output pin.
#include <htc.h> //PIC hardware mapping
//#define _XTAL_FREQ 500000 //Used by the XC8 delay_ms(x) macro
//config bits that are part-specific for the PIC16F1829
CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
CONFIG(WRT_OFF & PLLEN_OFF & STVREN_OFF & LVP_OFF);
void main(void) {
Last edit: ashimotok0 2018-02-21
This should be the equivalent in GCB.
Good Luck
Mike
Thanks for the rapid response Mike .. I will give it a try !
Tried it Mike ... initially I couldn't try the code because my PicKit2 v2.60 would not support PIC16F1827 but when I hit flash icon on GCB IDE it programmed and worked fine. I didn't realize you could programme directly from the IDE ... cool !! Many thanks ... Ash
Last edit: ashimotok0 2018-02-21
Well done.
I will create a post for the PicKit2.... but, essentially look in your Great Cow BASIC installation. You will find the PicKit2 GUI this has been updated to program your chip, you should also find a within the Great Cow BASIC shell folder an icon to the PicKit2 programmer.
Same applies to the PicKit3.
Glad you got it going Ash but I have to ask why are you trying to use it for your application?
You wanted to control motor speed and the PIC16F1827 has two ECCP (Enhanced Capture Compare PWM) Modules that are specifically designed for High Resolution Motor Speed control.
Having two such controllers will allow you to drive a Half Bridge configuration giving you control over torque and Speed to a resolution several orders of magnitude higher than 16 steps you will get out of a 5 bit D2A Voltage reference.
Internally it is just taps in a resistor divider chain between Vss and Vdd and they are only 5% tolerance if that.
Cheers
Chris
Hi Chris, The analogue ouput is a demand voltage (0-10v ) fed into a Danfoss single-> 3Phase inverter drive, with no requirement on the PCB to locally control the power to a motor. I just need an opamp to boost from around 4v to 10v which is no problem. Hope that explains why I need it. I must say you guys have been immensely helpful over the last two days and the GCB is a wonderul resource. Big thank you to all !